Skip to content

Sorting a result collection. #1900

Answered by paulbakker
melishatrout2 asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not aware of a great way of doing this - the problem is that there isn't really a "callback" to run code after the plants field datafetcher completed.

A workaround is to not have a separate datafetcher for plants, but resolve everything in the "root" searchSoilByIds datafetcher.

  1. Use getSelectionSet on the DataFetchingEnvironment to find out if the plants field is requested. (see https://netflix.github.io/dgs/advanced/context-passing/#pre-loading)
  2. Load soils, and in the same method, also load plants.
  3. Merge the soils and plants in the data structure you want to return, including the sorting.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by melishatrout2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants