Is it possible to use a property from a higher level field as an input parameter for a lower level field in a GraphQL query?

Is it possible to use a property from a higher level field as an input parameter for a lower level field in a GraphQL query?

For example, a football club has players and seasons. In each season, a subgroup of club players plays games for the club. Club players may have different team numbers in each season.

I want to ask the club players for the season, as well as their team number for this season, and for each player I want a list of the games they played this season.

I can get a list of all the games (at any time of the year) that the player played for the club. But I want to filter this list, so only games in the requested season are included in the list.

query {
  club {
    players {
      fullName
    }
    seasons {
      id <-- I want to use this value as input parameter $seasonId below
      players {
        edges {
          squadNumber
          node {
            fullName
            games(seasonId: $seasonId) { <-- how to use the value here?
              homeTeam
              awayTeam
            }
          }
        }
      }
      games {
        players {
          edges {
            goalsCount
            node {
              fullName
              games(seasonId: $seasonId) { <-- how to use the value here?
                homeTeam
                awayTeam
              }
            }
          }
        }
      }
    }
  }
}

, SeasonPlayer GraphQL ( )? , ?

+4

Source: https://habr.com/ru/post/1623922/


All Articles