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
184 views
in Technique[技术] by (71.8m points)

javascript - Need to use the graphqlHTTP function by importing it from graphql package but it is not working

I changed the codes multiple times for this part but it still showing errors, I don't know where else I should change the code. Yes, I did tried the methods from the previous post about graphqlHttp is not a function but I'm still getting the errors

errors: C:UsersjustjDocumentsWeb ProjectMERN Stack
Projectsevent-bookingapp.js:35 app.use('/graphql', graphqlHttp({

TypeError: graphqlHttp is not a function
    at Object.<anonymous> (C:UsersjustjDocumentsWeb ProjectMERN Stack Projectsevent-bookingapp.js:35:21)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 [nodemon] app crashed - waiting for file changes before starting...

Code:

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

app.use('/graphql', graphqlHTTP({
    schema: buildSchema(`
        type RootQuery {
            events: [String!]!

        }

        type RootMutation {
            createEvent(name: String): String 

        }

        schema {
            query: RootQuery
            mutation: RootMutation 
        }
        
    `), 

    rootValue: {
        events: () => {
            return ['Cooking', 'Sailing', 'Coding']; 

        },
        createEvent: (args) => {
            const eventName = args.name; 
            return eventName; 

        }
    },
    graphiql: true 
    
    })
); 
question from:https://stackoverflow.com/questions/65876020/need-to-use-the-graphqlhttp-function-by-importing-it-from-graphql-package-but-it

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

1 Reply

0 votes
by (71.8m points)

Look this Docs

The right way to execute code:

??????

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.


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

...