0

Let's say I have the following schema

type Query {
  shows: [Show]
}

type Show {
  # The showId may or may not be there, depending on the scenario.
  showId: ID
  title: String
  reviews(filter: MyFilter): [Review]
}

type Review {
  starRating: Int
  text: String
}

I want to use Netflix DGS pre-loading to fetch reviews in one DB query with the shows as I can easily join it in the DB. Moreover implementing it effectively using DataLoaders is far from straightforward. The question is how to access the review filter MyFilter from the shows fetcher?

Lukas
  • 13,606
  • 9
  • 31
  • 40

1 Answers1

0

If I get your question right,

There are several possible ways to obtain arguments.

DataFetchingEnvironment should contain all needed info

  1. Getting argument by name MyFilter dfe = dfe.getArgument("filter"); where dfe instance of DataFetchingEnvironment that should be passed to dataFetcher. Like it is done in DGS example..
@DgsData(parentType = "Query", field = "shows")
public DataFetcherResult<List<Show>> shows(DataFetchingEnvironment dfe) {
  dfe.getSelectionSet().contains("reviews")
....
  1. Getting all available arguments via DataFetchingEnvironment method Map<String, Object> getArguments(). It should return the arguments that have been passed in via the graphql query.

  2. If any previous options don't suitable, then there is one more.

Getting DataFetchingFieldSelectionSet via DataFetchingEnvironment method getSelectionSet()

DataFetchingFieldSelectionSet has a method

Map<String,Map<String,Object>> getArguments()

It returns a map of the arguments for each field in the selection set.

Danil Kuznetsov
  • 714
  • 3
  • 5
  • Thanks, 1. returns the filter of the `shows` query 2. unfortunately returns "raw" GraphQL Objects. For example, query variables are not resolved. 3. I can't find the methods you are describing but I suspect they will have the same issue as 2. – Lukas Mar 30 '23 at 14:05