javascript - 错误: Expected undefined to be a GraphQL schema on hello world

标签 javascript node.js graphql graphql-js

下面是我的简单 graph ql hellow rold 代码,我直接从 graphql 官方文档开始使用它,不知何故它给了我错误:预期未定义为 hello world 上的 GraphQL 模式


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

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

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

最佳答案

文档似乎有误。它需要更新,您可以尝试更新如下代码吗?

来自

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

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

关于javascript - 错误: Expected undefined to be a GraphQL schema on hello world,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70567470/

相关文章:

javascript - Firefox iframe 历史

javascript - 哪个有更好更流畅的 DOM 操作 API? Chrome 还是火狐?

json - 使用 node express 代理 json 请求

node.js - gcloud无法部署nodejs应用程序

javascript - 将数组从 GraphQL 查询传递到 React-Table

javascript - Node.js:如何在写入流 'finish' 事件上写入()

javascript - HTTP请求错误码429抓不到

javascript - 如何在node.js中创建传输流?

python - GitHub GraphQL API 解析 JSON 时出现问题

node.js - Apollo Client V2 获取数据的顺序错误