Syntax/pre-compilation graphql 和 express 问题

Syntax/pre-compilation issue with graphql and express

嗨,我正在关注这个视频来制作预订系统enter link description here

我的代码与创建者相同,但不是 运行(如下所示的错误消息)

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

app.js 文件中的代码是

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

有什么办法可以解决这个错误吗?去这个调试器?非常感谢,因为我已经坚持了一段时间!

要修复错误 TypeError: graphqlHttp is not a function,请替换

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

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

(注意 HTTPHttp 的不同情况)

当然,在其他行中,graphqlHttp必须替换为graphqlHTTP

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