Allow dispatch() caller to get stats back. #56
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For context: I'm working on a change to allow better composability of
DataLoader
s. Right now, you can't nestDataLoader.load().thenApply()
within another similar call. When a GraphQL field resolution expects a result typeV
, you can return aCompletableFuture<T>
(e.g. due to aDataLoader
), but you can't return aCompletableFuture<CompletableFuture<T>>
and so on. So, instead of being able to chainDataLoader
s together, you have to come up with a specializedDataLoader
to calculate the one specific field you want. I'm trying to make it so that you can chainDataLoader
s together.The bulk of the change is going to be in
graphql-java
, in another PR. But that change is going to need insight into what happened when adispatchAll
was done in theDataLoaderRegistry
. That's what this PR is about.Actual change: Added
dispatchWithCounts
which now returns aDispatchResult
which includes the previously returnedCompletableFuture<List<X>>
, plus a count of how many entries (keys) were dispatched. No API change to existing methods. (Aside: I did also think about changing theCompletableFuture<List<X>>
to aList<CompletableFuture<X>>
, which would accomplish the same thing. But that would change the API, so I opted for this approach instead.)