我是 GraphQL 的初学者。在设置服务器、连接到 mongodb 数据库并进行突变时,运行后出现以下错误node index.js
。
GraphQLError:语法错误:无法解析意外字符“;”。
这是我的 index.js....
const { GraphQLServer } = require('graphql-yoga');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/todo');
const Todo = mongoose.model('Todo',{
text: String,
complete: Boolean
});
const typeDefs = `
type Query {
hello(name: String): String!
}
type Todo{
id: ID!
text: String!
complete: Boolean!
}
type Mutation{
createTodo(text: String!): Todo;
}
;
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
Mutation: {
createTodo: async (_, { text }) => {
const todo = new Todo({ text, complete: false });
await todo.save();
return todo;
}
}
};
const server = new GraphQLServer({ typeDefs, resolvers });
mongoose.connection.once('open', function() {
server.start(() => console.log('Server is running on localhost:4000'))
});
如何解决这个错误!?