Javascript GraphQLError:语法错误:无法分析意外字符“quot;”&引用;
我是GraphQL的初学者。在设置服务器、连接到mongodb数据库并进行变异时,在运行Javascript GraphQLError:语法错误:无法分析意外字符“quot;”&引用;,javascript,graphql,express-graphql,Javascript,Graphql,Express Graphql,我是GraphQL的初学者。在设置服务器、连接到mongodb数据库并进行变异时,在运行node index.js后,我遇到以下错误 GraphQLError:语法错误:无法分析意外字符“;” 这是我的index.js const { GraphQLServer } = require('graphql-yoga'); const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/todo'); con
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'))
});
如何解决此错误 删除分号并添加结束模板字符串`
const typeDefs = `
type Query {
hello(name: String): String!
}
type Todo{
id: ID!
text: String!
complete: Boolean!
}
type Mutation{
createTodo(text: String!): Todo;
}
; // <= remove
` // <= add
const typeDefs=`
类型查询{
你好(名字:String):String!
}
键入待办事项{
id:id!
文本:字符串!
完成:布尔!
}
类型突变{
createTodo(文本:String!):Todo;
}
; // 删除此行末尾的分号:createTodo(text:String!):Todo