【发布时间】:2016-11-03 06:58:10
【问题描述】:
我正在尝试在 Node.js 中实现一个非常基本的 GraphQL 接口,但无论我做什么,我似乎都无法触发我的 foo 类型的 resolve 方法。当我在单元测试中运行以下代码时,它运行成功,但是我可以从(缺少)控制台输出中看到 resolve 没有被调用,因此当我调用 @987654324 时我得到一个空对象@。
任何对 GraphQL 更有经验的人可以提出我可能做错了什么吗?如果 GraphQL 找不到并调用应该返回结果的方法,我完全不知道整个操作如何成功完成......
const fooType = new GraphQLInterfaceType({
name: `Foo`,
description: `A foo`,
fields: () => ({
id: {
description: `The foo's id`,
type: new GraphQLNonNull(GraphQLInt),
},
title: {
description: `The foo's title`,
type: new GraphQLNonNull(GraphQLString),
}
})
});
const queryType = new GraphQLObjectType({
fields: {
foo: {
args: {
id: {
description: 'ID of the foo',
type: new GraphQLNonNull(GraphQLString)
}
},
resolve: (root, { id }) => {
console.log(12345);
return getFoo(id)
},
type: fooType,
}
},
name: 'Query',
});
export default new GraphQLSchema({
query: queryType,
types: [fooType],
});
// In test:
const query = `
foo {
title
}
`;
const result = graphql(FooSchema, query); // == {}
【问题讨论】:
标签: graphql graphql-js