Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce batch delegation #1735

Merged
merged 5 commits into from Jul 8, 2020
Merged

Introduce batch delegation #1735

merged 5 commits into from Jul 8, 2020

Conversation

yaacovCR
Copy link
Collaborator

@yaacovCR yaacovCR commented Jul 6, 2020

Add ability to create a batchDelegate function that uses a dataloader scoped to each member of a list to batch delegateToSchema calls.

Adds option within type merging to retrieve additional fields for objects via a root field that returns a list instead of a particular item, using a batchDelegate function, see #1710

Fixes memoization (as initially introduced in #1728). Cache misses were occurring because of mistakes within the memoization algorithm as well as the functions not providing static keys.

@yaacovCR yaacovCR changed the title Fix memoization Fix type merging memoization Jul 6, 2020
@theguild-bot
Copy link
Collaborator

theguild-bot commented Jul 6, 2020

The latest changes of this PR are available as alpha in npm: 6.0.13-alpha-d319d279.0

Quickly update your package.json by running:

npx match-version @graphql-tools 6.0.13-alpha-d319d279.0

= memoize info using info.fieldNodes, which is memoized by upstream graphql-js

= refactor StitchingInfo type and handleObject and supporting methods to use consistent keys to enable memoization
@yaacovCR yaacovCR changed the title Fix type merging memoization Introduce batch delegation Jul 8, 2020
Add key option within type merging config to enable batch loading for lists.

This minimal version of batching uses cached dataLoaders to create a separate batch for each list rather than for every similar query within the resolution tree.

This is because a new dataloader is created for every new info.fieldNodes object, which is memoized upstream by graphql-js within resolution of a given list to allow the loader to be used for items of that list.

A future version could provide an option to batch by similar target fieldName/selectionSet, but this version may hit the sweet spot in terms of code complexity and batching behavior.

see:
#1710
remove unused isProxiedResult function

move unwrapResult and dehoistResult into createMergedResolver

WrapFields and HoistField transforms now use their own unwrapping and dehoisting logic, so these functions should be located only to the file that used them
@yaacovCR yaacovCR merged commit d319d27 into master Jul 8, 2020
@yaacovCR yaacovCR deleted the memoize branch July 8, 2020 13:13
@ardatan ardatan added the feature New addition or enhancement to existing solutions label Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature New addition or enhancement to existing solutions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants