【问题标题】:Error: Expected undefined to be a GraphQL schema on hello world错误:预期 undefined 是 hello world 上的 GraphQL 模式
【发布时间】:2022-01-04 01:03:56
【问题描述】:

下面是我直接从 graphql 官方文档开始使用的简单图形 ql hello rold 代码,不知何故它给了我错误:Expected undefined to be a GraphQL schema on hello world


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

var root = { hello: () => "Hello world!" };

graphql(schema, "{ hello }", root).then((response) => {
  console.log(response);
});

【问题讨论】:

标签: javascript node.js graphql graphql-js


【解决方案1】:

似乎文档是错误的。需要更新,可以尝试更新如下代码吗?

来自

graphql(schema, "{ hello }", root).then((response) => {
  console.log(response);
});

收件人

graphql({
    schema: schema, 
    source: '{ hello }', 
    rootValue: root
}).then((response) => {
  console.log(response);
});

【讨论】:

  • 正确答案!
  • 标记是否有帮助
猜你喜欢
  • 2018-11-09
  • 2018-10-02
  • 2016-08-04
  • 2010-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多