小编Abu*_*der的帖子

新GraphQL buildSchema的嵌套查询

如何使用新的GraphQL Schema语言为我的friendList制作解析器?friendList有一组人_id.

我的新朋友使用GraphQL Schema语言输入:

const schema = buildSchema(`
  type People {
    _id: String
    firstName: String
    lastName: String
    demo: String
    friendList: [People]
  }
  type Query {
    getPeople(_id: String): People
  }
`);
Run Code Online (Sandbox Code Playgroud)

我的老人用GraphQLObjectType输入:

const PeopleType = new GraphQLObjectType({
  name: 'People',
  fields: () => ({
    _id: {
      type: GraphQLString,
    },
    firstName: {
      type: GraphQLString,
    },
    lastName: {
      type: GraphQLString,
    },
    friendList: {
      type: new GraphQLList(PeopleType),
      // pass @friends parentValue
      resolve: ({ friends }) {
        return People.find({ _id: { $in: friends } …
Run Code Online (Sandbox Code Playgroud)

graphql graphql-js

8
推荐指数
2
解决办法
4910
查看次数

标签 统计

graphql ×1

graphql-js ×1