Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Syntax/pre-compilation issue with graphql and express

Hi I am following this video to make a booking system enter link description here

And my code is identical to the creator but it isn’t running (error message shown below)

    [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...

And code in the app.js file is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);

Any ideas how to fix this error? To get to this debugger? Thanks alot as I’ve been stuck on this for a while!
enter image description here

>Solution :

To fix the error TypeError: graphqlHttp is not a function, replace

const graphqlHttp = require('express-graphql');

with

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

(Notice the different case for HTTP, versus Http)

Of course, in the other lines, graphqlHttp must be replaced by graphqlHTTP.

https://graphql.org/graphql-js/express-graphql/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading