为什么这个来自graphql doc的嵌套graphql解析器在graphql-js中不起作用?

时间:2020-02-19 12:46:48

标签: node.js graphql graphql-js

我是graphql的新手,正在尝试从graphql.org上的文档运行代码。

我简化了代码在此页面中:https://graphql.org/learn/execution/, 但这不起作用

const {buildSchema, graphql} = require('graphql');

const schema = buildSchema(`
type Query {
  human(id: ID!): Human
}

type Human {
  name: String
}
`
);
const resolver = {
    Query: {
        human(obj, args, context, info) {
            return {name: "fakeOne"}; // fake human
        }
    }
};

graphql(schema, '{ human(id: 1002) {name} }', resolver).then((response) => {
    console.log(response);
});

解析器永远不会运行。

然后将其更改为:

const resolver = {
    human(obj, args, context, info) {
        return {name: "fakeOne"}; // fake human
    }
};

现在,它运作良好。我只是想知道为什么它会像这样,我该如何使前一个起作用?

0 个答案:

没有答案