Replies: 1 comment
-
dataloader is nominally graphql agnostic. That is knows nothing of graphql field selection and so on. Just K -> V value loading. You would need to send in "context" to the batch loader such that this "selection" was sent down to the lower levels if they are to be "efficient". Its up to you on how to do encode this. Have a look at |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have two unrelated questions:
1. Error handling
Neither
org.dataloader.BatchLoader::load
nororg.dataloader.BatchLoaderWithContext::load
allow one to throw an exception while attempting to fetch some data from some source, because the interface does not declare that an exception is thrown:What is the correct way to handle an error, when, for example, my repository blows up while trying to load a list of entities by the provided keys? Similarly, what if some external HTTP request to fetch a list of entities fails in an unrecoverable way? It seems wrong in these cases to return an empty list; I would prefer to throw an exception and cause the entire GraphQL call stack to unwind instead of returning partial data.
2. Field selection
The
BatchLoaderEnvironment
passed to aBatchLoaderWithContext::load
call does not allow me to inspect the request for the selected fields that caused loading of some entities to occur. Is there a way to do this? I prefer to select only the columns absolutely necessary from the database/API/etc. to optimize performance.I can imagine that it may be difficult to traverse all nodes on the query to aggregate the minimum acceptable selection of fields from a given type, but it doesn't seem impossible. What I'm hoping is possible is something like this:
Given a query like this:
...that I can be able to then only select fields A, B, C, and D, instead of a
SELECT *
(assuming a relational database is the backing store).Thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions