下面是我的简单 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/