grapqhql在null对象上不返回null

时间:2017-01-18 10:28:51

标签: express graphql

在API中我正在开发这个graphql查询

query { user(id: "nonexistentID") { name email } }

返回

{
  "data": {
    "user": {
      "name": null,
      "email": null
    }
  }
}

但是我希望像这样在用户身上返回null:

{
  "data": {
    "user": null
  }
}

所以API用户知道没有这样的用户。这是预期的行为,还是我错过了什么?

graphql-js(express)中的模式定义如下所示:

const schema = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: 'Query',
        fields: {
            user: {
                type: userType,
                args: {
                    id: { type: GraphQLString}
                },
                resolve: function resolve(root, args, info) {
                    return adapters.users.byId(args.id);
                }
            }
        }

    })

});

0 个答案:

没有答案
相关问题