WebDevSimplified / Learn-GraphQL

200 stars 178 forks source link

Starting a server gives Error - TypeError: expressGraphQL is not a function #3

Open michaelmiscanuk opened 2 years ago

michaelmiscanuk commented 2 years ago

Hi, found a solution for this error when starting a server, so sharing:

I just changed a line when requiring express-graphql to:

const expressGraphQL = require('express-graphql').graphqlHTTP

Now it starts ok.

LucidMach commented 2 years ago

and another simple fix for it would be

// const expressGraphql = require("express-graphql");
const { graphqlHTTP } = require("express-graphql");

app.use("/graphql", graphqlHTTP({
    schema,
    graphiql: true,
  })
);