0

I'm working on a cursor based pagination that requires the a nested field to access the args. So far, i've been unable to get the args to its desired field.

   type Game {
    players(first: Int, after: String, last: Int, before: String): GameToPlayerConnection
  }

  game(id: GameID!): Game

I am able to only access the args passed to the game and not the args passed to the players.

 game: async (parent: any, args: { id: string; first: number; last: number; after: 
       string; before: string; }, _ctx: any, info: any) => 
        {
        const { id, first, last, after, before } = args;
        console.log("args", args);
        }



  game(id: 'fortnite', first: 3){
    players(first: 2){
     ....
     }
    }

I am trying to access the args passed to the players

Mhd
  • 817
  • 1
  • 8
  • 21

1 Answers1

0

That's correct. Every resolver can only access the arguments for its own property. Each object also has its own set of resolvers, so you need one object for Query, and another for Game:

const resolvers = {
  Query: {
    game: async (parent, { id }, context, info) {
      return games.load(id);
    },
  },
  Game: {
    players: async ({ id }, { first, last, before, after }, context, info) {
      return playersByGame({
        gameId: id,
        first,
        last,
        before,
        after,
      });
    },
  },
};
Dan Crews
  • 3,067
  • 17
  • 20