-
How do we get the list of user-selected fields? The examples in the docs all show returning the full object, but that's often overfetching. Is there a way to select just the fields that the user has asked for? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Answering my own question, you can put the |
Beta Was this translation helpful? Give feedback.
-
The solution you are describing is the field look-ahead strategy and it can be quite powerful for optimizing fetching. In general, I would not recommend it though. One big disadvantage is that you cannot look-ahead into fragments of subtypes because at the time of looking-ahead GraphQL Java still does not know what type will the fragment resolve into. To avoid over-fetching I would instead recommend fetching just the minimal "skeleton" objects and resolving all additional fields using methods in |
Beta Was this translation helpful? Give feedback.
The solution you are describing is the field look-ahead strategy and it can be quite powerful for optimizing fetching. In general, I would not recommend it though. One big disadvantage is that you cannot look-ahead into fragments of subtypes because at the time of looking-ahead GraphQL Java still does not know what type will the fragment resolve into.
To avoid over-fetching I would instead recommend fetching just the minimal "skeleton" objects and resolving all additional fields using methods in
GraphQLResolver<MyType>
. If you then combine it with the GraphQL Java DataLoader concept you will have a very flexible and fast architecture with little to no overfetching.