const express = require('express');
const bodyParser = require('body-parser');
const graphqlHttp = require('express-graphql');
const { buildSchema } = require('graphql');
const app = express();
app.use(bodyParser.json());
app.use(
'/graphql',
graphqlHttp({
schema: buildSchema(`
type RootQuery {
events: [String!]!
}
type RootMutation {
createEvent(name: String): String
}
schema {
query: RootQuery
mutation: RootMutation
}
`),
rootValue: {
events: () => {
return ['Romantic Cooking', 'Sailing', 'All-Night Coding'];
},
createEvent: (args) => {
const eventName = args.name;
return eventName;
}
},
graphiql: true
})
);
app.listen(3000);
I tried using the following tutorial from YouTube.
https://www.youtube.com/watch?v=LXTyzk2uud0&list=PL55RiY5tL51rG1x02Yyj93iypUuHYXcB_&index=3
It didn’t work. Instead I get:
nodemon app crashed – waiting for file changes before starting…
2
Answers
There should be a more detailed error message above "nodemon app crashed". But anyways, there is a top comment in the youtube video that says
graphqlHttp
is not imported properly. It should be:const { graphqlHTTP } = require('express-graphql');