Hey there, I'm currently trying to create a booking system by following a tutorial video. You can check out the video here
The issue I'm facing is that even though my code is identical to the one in the tutorial, it's not working and I'm getting this error message:
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
C:\Users\Abdulrahman\Desktop\bookings1\app.js:12
graphqlHttp({
^
TypeError: graphqlHttp is not a function
at Object.<anonymous> (C:\Users\Abdulrahman\Desktop\bookings1\app.js:12:5)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
[nodemon] app crashed - waiting for file changes before starting...
Here is the code snippet from my app.js file:
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);
Do you have any suggestions on how to troubleshoot and fix this error? Any help or guidance would be greatly appreciated! Thanks in advance!