【发布时间】:2017-09-19 13:52:55
【问题描述】:
我正在使用express-graphql 以及以下查询:
invitations {
sent
received
}
架构定义(简化)如下:
const InvitationType = new GraphQLObjectType({
name: 'InvitationType',
description: 'Friends invitations',
fields: {
sent: {
type: new GraphQLList(GraphQLString),
description: 'Invitations sent to friends.',
resolve() {
return ['sentA'];
}
},
received: {
type: new GraphQLList(GraphQLString),
description: 'Invitations received from friends.',
resolve() {
return ['receivedA', 'receivedB'];
}
}
}
});
// Root schema
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
invitations: {
type: InvitationType // no resolve() method here.
}
}
})
});
但是,resolve 方法永远不会为 sent 和 received 字段调用。上面的查询返回:
{data: {invitations: {sent: null, received: null}}}
有没有办法解决嵌套字段(sent 和 received)而不在父字段(invitations)上定义 resolve() 方法?
【问题讨论】:
标签: javascript express graphql