Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在GraphQL中获取相同的嵌套对象_Node.js_Graphql Js_Express Graphql - Fatal编程技术网

Node.js 如何在GraphQL中获取相同的嵌套对象

Node.js 如何在GraphQL中获取相同的嵌套对象,node.js,graphql-js,express-graphql,Node.js,Graphql Js,Express Graphql,我有一个催收电话人员,其字段很少:- { "_id": { "$oid": "5f26e8ef969cc80d9710b250" }, "firstName": "xxxxxxx", "lastName": "xxxxxx", "email": "xxxxxxxx@gmai

我有一个催收电话人员,其字段很少:-

{
    "_id": {
        "$oid": "5f26e8ef969cc80d9710b250"
    },
    "firstName": "xxxxxxx",
    "lastName": "xxxxxx",
    "email": "xxxxxxxx@gmail.com",
    "userName": "xxxxxx",
    "friends": [
       {
          "$numberInt": "2001" // person identity
       }, 
       {
         "$numberInt": "1002" // person identity
       }
    ],
    "personIdentityCount": {
        "$numberInt": "1000"
    }
}
Friends是一个数组,它具有唯一的个人身份计数,我们可以从中识别个人,这意味着如果我们搜索1002个人身份计数,它将为我们提供个人数据

我已装箱一个架构和类型:-

const personType=new GraphQLObjectType({
    name: "Person",
    fields:{
        id: { type: GraphQLID },
        firstName: { type: GraphQLString },
        lastName: { type: GraphQLString },
        email: { type: GraphQLString },
        userName: { type: GraphQLString },
        count: { type: GraphQLInt },
        friends:{
            type: new GraphQLList(PersonType), // getting an error " personType is not defined "
            resolve: (person) => person.friends.map(id => getPersonByPersonIdentityCount(id))
        }
    }
});
我收到一个错误,朋友类型中未定义personType({type:new GraphQList(personType)})

====GraphQL的架构=====

const scheam = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: "Query",
        fields: {
            people: {
                type: GraphQLList(personType),
                resolve: async (root, args, context, info) =>
                {
                    return PersonModel.find().exec();
                }
            },
            person: {
                type: personType,
                args: {
                    id: { type: GraphQLNonNull(GraphQLID) }
                },
                resolve: (root, args) => getPersonByPersonIdentityCount(args.id)
            }
        }
    })

});
我想如果我在graphQl请求中请求friend,那么friends值应该出现

#预期反应

    person(id:"5f26a1e8034dec6713cbd28e"){
    id,
    firstName,
    friends{
      id,
      firstName,
      lastName
    }
  }
}
我可以通过数据库级别解决这个问题,但我需要一个graphQL解决方案