I'm a beginner in GraphQL. While setting the server, connecting to mongodb database and doing a mutation, I'm getting following error after running node index.js
.
GraphQLError: Syntax Error: Cannot parse the unexpected character ";".
Here's my 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'))
});
How to resolve this error!?
Remove semicolon and add closing template string `
const typeDefs = `
type Query {
hello(name: String): String!
}
type Todo{
id: ID!
text: String!
complete: Boolean!
}
type Mutation{
createTodo(text: String!): Todo;
}
; // <= remove
` // <= add