graphqlHTTP is not a function
Quentin's answer was on spot. Apparently the npm documentation was updated but some of the tutorials on YouTube were not. That's why there's a certain degree of confusion for learners like myself. There are still outdated versions of the code like
This one: https://github.com/iamshaunjp/graphql-playlist/blob/lesson-36/server/app.js
This one: https://github.com/WebDevSimplified/Learn-GraphQL/blob/master/server.js
Or this one: https://github.com/bradtraversy/customerbase/blob/master/server.js
They should all be updated to
const { graphqlHTTP } = require('express-graphql');
and then
app.use('/graphql', graphqlHTTP({
schema:schema,
graphiql:true
}));
Look at the documentation:
const { graphqlHTTP } = require('express-graphql');
Note that it uses destructuring equivalent to:
const graphqlHTTP = require('express-graphql').graphqlHTTP;
require('express-graphql')
returns an object with a property called graphqlHTTP
that is the function you want to call.
You're trying to call the object itself as if it was a function.