graphqlHTTP不是函数 [英] graphqlHTTP is not a function

查看:403
本文介绍了graphqlHTTP不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我简单的graphql Express应用程序

Here is my simple graphql express app

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

const app = express();
app.use(
    '/graphql',
    graphqlHTTP({
      graphiql: true,
    })
  );

app.listen(4000, () => {
    console.log("listening for request!");
});

运行它时出现以下错误:

I'm getting the following errors when I run it:

 graphqlHTTP({
    ^

TypeError: graphqlHTTP is not a function
    at Object.<anonymous> (D:\PersonalProjects\GraphQL\server\app.js:7:5)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)  
    at internal/main/run_main_module.js:17:47

我该如何解决?预先感谢!

How can I fix it? Thanks in advance!

推荐答案

查看文档:

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

请注意,它使用的解构等效于:

Note that it uses destructuring equivalent to:

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

require('express-graphql')返回具有属性对象,该属性称为graphqlHTTP,这是您要调用的函数.

require('express-graphql') returns an object with a property called graphqlHTTP that is the function you want to call.

您正试图像调用一个函数一样调用对象本身.

You're trying to call the object itself as if it was a function.

这篇关于graphqlHTTP不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆