【问题标题】:Error in graphql in Express , node jsExpress中的graphql错误,节点js
【发布时间】:2018-05-31 01:00:47
【问题描述】:

我正在尝试以 express 方式运行 graphql 服务器。但它会引发以下错误。

var graphqlHTTP = require('express-graphql'); // express graphql
var { buildSchema } = require('graphql');  // graphql
var schema=buildSchema(
    type Query {
        name:String});

var classifyRoot={
     name:()=>{
        classified.find({name:"shoes"},function(err,classified){
            //res.render("card",{classifieds:classifieds});
            return classified.name;
        });
    },};
app.use('/graphql', graphqlHTTP({
  schema: schema,
  rootValue: classifyRoot,
  graphiql: true,
}));

【问题讨论】:

  • 我认为您需要提供更多代码,仅凭错误就没有什么可处理的
  • 您好,感谢回复,请查找更新后的代码
  • 那么错误在哪一行?这几乎肯定只是某个地方的错字

标签: node.js express graphql express-graphql


【解决方案1】:

buildSchema 的参数应该是字符串。 (注意back-ticks

var schema=buildSchema(`
    type Query {
        name:String
    }
`);

【讨论】:

    【解决方案2】:

    它缺少=

    要使用类型,您需要这样做:

    type Query = {
      //Variables and types goes here:
      //ex:  username: string
    }
    

    希望我有帮助

    【讨论】:

    猜你喜欢
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2018-11-17
    • 2020-09-18
    • 1970-01-01
    • 2015-05-04
    • 2014-10-05
    相关资源
    最近更新 更多