Get data from parent node in field converter

So what am I trying to do to make GraphQLthis if possible:

{
  people {
    _id
    name
    acted {
      _id
      title
      coactors {
        name
      }
    }
  }
}

So what I do, he gets the actors (people) and then makes the films they play in, it works great. So, I'm trying to attract associates in this film. I am going to pass the current actor identifier to the co-actors field as an argument like this:

{
  people {
    _id
    name
    acted {
      _id
      title
      coactors(actor: people._id) {
        name
      }
    }
  }
}

Obviously, I am getting an error message and do not know if this can be done internally.

So here are my types:

const MovieType = new GraphQLObjectType ({
    name: 'movie',
    fields: () => ({
        _id: {
            type: GraphQLInt
        },
        title: {
            type: GraphQLString
        },
        tagline: {
            type: GraphQLString
        },
        released: {
            type: GraphQLInt
        },
        actors: {
            type: new GraphQLList(PersonType),
            resolve: (movie) => {
                return [];
            }
        },
        coactors: {
            type: new GraphQLList(PersonType),
            args: {
                actor: {
                    type: GraphQLInt
                }
            },
            resolve: (movie, args) => {
                getCoActorsFor(movie, args.actor) // How can I do something like this
                    .then((actors) => {
                        return actors;
                    })
            }
        }
    })
});

const PersonType = new GraphQLObjectType({
    name: 'person',
    fields: ()=> ({
        _id: {
            type: GraphQLInt
        },
        name: {
            type: GraphQLString
        },
        born: {
            type: GraphQLInt
        },
        acted: {
            type: new GraphQLList(MovieType),
            resolve: (person) => {

                return [];

            }
        }
    })
});
+4
1

, , .

, , , "", , , "", , , .

API - - , . , , . - , , , , .

+3

All Articles