GraphQL类型字段具有与父代(周期)相同的类型

时间:2019-01-21 17:20:18

标签: graphql

在此示例中 https://graphql.org/graphql-js/constructing-types/

我们有可能实现Type引用其根吗?父母类型? (经理字段类型引用回userType)

var userType = new graphql.GraphQLObjectType({
   name: 'User',
   fields: {
     id: { type: graphql.GraphQLString },
     name: { type: graphql.GraphQLString },
     manager: { type: userType },
   }
});

1 个答案:

答案 0 :(得分:1)

Thunk解决了我的问题,返回了字段。

var userType = new graphql.GraphQLObjectType({
   name: 'User',
   fields: ()=> {
     return {
       id: { type: graphql.GraphQLString },
       name: { type: graphql.GraphQLString },
       manager: { type: userType }
    }
   }
});