Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

javascript - expressGraphQL is not a function

I am learning GraphQL for my project using this tutorial: https://www.youtube.com/watch?v=ZQL7tL2S0oQ&ab_channel=WebDevSimplified

and I get the error:

TypeError: expressGraphQL is not a function
at Object.<anonymous>

I have already tried:

  • this solution: graphqlHTTP is not a function - the program crashes all the same with {} parentheses and without them
  • adding a semicolon after various lines

The code for now looks like this:

const express = require ('express')
const { expressGraphQL } = require('express-graphql')
const app = express();

app.use('/graphql', expressGraphQL({
    graphiql: true,
})
)
app.listen(5000., () => console.log('Server Running'))

If I comment out this section:

app.use('/graphql', expressGraphQL({
graphiql: true,
})
)

the code works perfectly fine both with {} parentheses and without them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please replace your expressGraphQL with graphqlHTTP as it was destructured

Use:

const { graphqlHTTP } = require('express-graphql');

or

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

This is because a method called graphqlHTTP exist in the express-graphql module and you are destructure with another method name that does not exist in the module

I also noticed that you have a dot after 5000 on the app.listen function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...