-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Custom document transforms #10509
Merged
Merged
Custom document transforms #10509
Changes from 1 commit
Commits
Show all changes
132 commits
Select commit
Hold shift + click to select a range
c455aa6
First pass at adding the ability to configure custom document transfo…
jerelmiller b72fcdd
Create a DocumentTransformer class to handle transforming the document.
jerelmiller e07d1c6
Add tests to validate custom document transforms work correctly
jerelmiller 518be12
Add tests to ensure default transforms use existing behavior
jerelmiller c57c7d0
Remove transformDocument options that sends @client fields through th…
jerelmiller 5739704
Add changeset
jerelmiller 5bb2afc
Enforce immutability for document argument for the transform.
jerelmiller 9c76e09
Adjust hwo document transforms are added to save some bundle size
jerelmiller 1e9c666
Remove Readonly modifier since DocumentNode is already readonly
jerelmiller bdfbfc2
Create a new DocumentTransform class to handle individual transforms
jerelmiller 52f371c
Add documentTransform option to ApolloClient
jerelmiller 2ec0a52
Minor refactor to destructure client and server query together in get…
jerelmiller 020629c
Run queries and mutations through the document transform
jerelmiller e4a7bee
Run subscriptions through the document transform
jerelmiller 9ee7fc9
Pass query to getResultsFromLink instead of pulling it from queryInfo
jerelmiller c75e0e4
Remove DocumentTransformer and revert cache to original implementation
jerelmiller e107546
Replace typenameDocumentCache with DocumentTransform
jerelmiller 91beba0
Update snapshots
jerelmiller af101b2
Update document transform test to ensure caching has no effect when c…
jerelmiller 2c49428
Add test to ensure concatenated transforms run in proper order
jerelmiller 536d258
Create a custom toMatchDocument jest matcher
jerelmiller 0e23529
Update DocumentTransform tests to use new custom matcher
jerelmiller 5d21430
Create a default transform that runs transform through link
jerelmiller 1c656fc
Remove transformForLink from default transform for now
jerelmiller 04c89f6
Fix lint errors with import type
jerelmiller 56e5ef5
Add tests for document transforms on client.query() calls
jerelmiller e98ee23
Add tests for document transforms on client.mutate() calls
jerelmiller 63cc53e
Add tests for document transforms on client.subscribe() calls
jerelmiller ec9c708
Run document transforms before setting the query on ObservableQuery
jerelmiller 26cbd0c
Disable cache in tests that check number of times transform is called
jerelmiller e8b8924
Don't run transforms via `watchQuery` until request is kicked off
jerelmiller 8f6a25e
Strip accidentally commited trailing whitespace
jerelmiller 52d6b40
Add test to validate document transforms are run on refetch
jerelmiller 75044f9
Add more tests for verifying transfrom is re-run on fetchMore/setOpti…
jerelmiller 63aedb4
Update test name
jerelmiller 851fa7c
Add test to ensure fetchMore with different query runs transforms
jerelmiller b58b731
Check against full result for calls to mock
jerelmiller a489d44
Add failing assertions for value of computed `query` property for tra…
jerelmiller a4a87c8
Add tests to ensure default transforms are called with watchQuery
jerelmiller ae1b664
Add fragments from the fragment registry in transformDocument instead…
jerelmiller d042be4
Remove it.only
jerelmiller 48ea041
Minor update to comment
jerelmiller 2d5c0ef
Refactor out fetchQueryObservable that forwarded the call to another …
jerelmiller e25830e
Remove call to this.transform in fetchConcastWithInfo
jerelmiller 9962e3a
Create function to get information about query
jerelmiller be5076e
Call new getDocumentInfo from getVariables
jerelmiller dff62b4
Add assertion on number of times transform is called
jerelmiller 2e7cb13
Don't call transform on query passed to fetchConcastWithInfo
jerelmiller dbe965a
Add a lastQuery property and use for computed query property in Obser…
jerelmiller 18a9118
Transform the document in reobserveAsConcast and set as lastQuery
jerelmiller f124b1d
Transform query in fetchQuery when calling client.query
jerelmiller 5dd31a9
Don't run this.transform on mutation document, only call transformDoc…
jerelmiller 9ea514e
Use toHaveBeenLastCalledWith in document transform tests
jerelmiller e3c5ec7
Always set lastQuery in ObservableQuery when calling reobserve
jerelmiller e6e7f60
Move transformation of query on client.query up to query function
jerelmiller 338ac3a
Properly handle document transforms with fetchMore
jerelmiller 196aecb
Add some edge case expectations for fetchMore with query
jerelmiller 2557aaf
Fix incorrect test setup resulting in false negative
jerelmiller 8ec4ee4
Create transformDocument helper in ObservableQuery
jerelmiller e376d94
Fix other failing tests due to incorrect test setup
jerelmiller 1d5e466
Fix failing test due to change in object identity
jerelmiller ae1024f
Run custom transforms on the original document when calling `fetchMor…
jerelmiller 11b1893
Update test name to reflect behavior
jerelmiller 09b8bc1
Use ternary for setting lastQuery
jerelmiller c21fe45
Minor tweak to comment
jerelmiller c8a8643
Make test more obvious what the change in query is
jerelmiller 04c1229
Add test to ensure setOptions with new query works as expected
jerelmiller 2e40235
Switch over to getDocumentInfo for most usages of queryManager.transform
jerelmiller e4030ff
No need to wrap query in this.transform when creating a subscription
jerelmiller c678c47
Switch another usage to getDocumentInfo
jerelmiller f11f429
Run checkDocument in DocumentTransform before running the transform f…
jerelmiller 104e289
Run checkDocument immediately when calling `watchQuery`
jerelmiller 821dbcf
Fix prettier applying changes to some files that shouldn't
jerelmiller 36e0f52
Add note about the difference between computed query property and opt…
jerelmiller b82ff2a
Update fragment registry test to include missing __typename in result
jerelmiller e706352
Add tests to ensure document transforms are run before the cache is read
jerelmiller 86a4d8d
Ensure refetchQueries works with document transforms
jerelmiller 8c32d7e
Add test to ensure refetchQueries with mutate works with legacy option
jerelmiller 8893fb0
QueryManager.transform is now implemented with document transforms
jerelmiller 0c4948e
Ensure useSuspenseQuery default queries return __typename
jerelmiller 10e0387
Pass this.query when checking hasForcedResolvers
jerelmiller 3747f83
Set the transformed query on queryInfo immediately after calling watc…
jerelmiller d39058d
Remove document from getDocumentInfo cache entry
jerelmiller abe8793
Adjust size limit
jerelmiller a857181
Merge branch 'release-3.8' into custom-document-transforms
jerelmiller 9b73288
Rename cacheOutput to cacheResult
jerelmiller 4180679
Adjust size-limit again
jerelmiller 48d79f5
Update changeset with updated API
jerelmiller bee883b
Run getDocumentInfo on transformed query when running mutation
jerelmiller 5caf545
Run transform first when calling watchQuery to avoid checkDocument ca…
jerelmiller b5e75af
Run `checkDocument` after checking cache in `transformDocument` to av…
jerelmiller 019c6f2
Export isQuery, isMutation, and isSubscription helpers from utilities
jerelmiller b6ccc80
Add a static `split` method to DocumentTransform to conditionally exe…
jerelmiller a05ce44
Disable cache for concatenated transforms to let each transform deter…
jerelmiller eddaa30
Only create the transform cache when necessary
jerelmiller 4022e0d
Return whether the document was invalidated
jerelmiller b6ab3ee
Don't cache identity transform
jerelmiller 7a62ac0
Minor refactor of `split` to cut down on repetition
jerelmiller 9a3e82a
Ensure `invalidateDocument` invalidates the chain of transform caches…
jerelmiller 0339f45
Determine nonreactive based on transformed query, not the original query
jerelmiller 43619d5
Rename isQuery/isSubscription/isMutation to include Operation suffix
jerelmiller 0440c7a
Increase size-limit
jerelmiller e6b1711
Clarify how invalidateDocument works with `.split` transform.
jerelmiller 208aff9
Update document transform tests to assert on cache size when calling …
jerelmiller 54873b6
Allow for custom invalidation for each transform. Fix transforms with…
jerelmiller 2c60856
Use a noop in several places
jerelmiller 37677d1
Add test to validate .split with .concat properly invalidates
jerelmiller 473de15
Update test name
jerelmiller 9176b84
Rename private method
jerelmiller cab8a49
Add tests to demonstrate behavior of custom `invalidate`
jerelmiller dc1aa01
Return transformed doc from invalidateDocument. Add test to validate …
jerelmiller 8ea5c3b
Add test to ensure invalidating a document with no cache is ok
jerelmiller bfe651d
Add a documentTransform computed property on ApolloClient to get a re…
jerelmiller a17765f
Minor tweak to test name
jerelmiller 2372ce2
Run the transform during invalidation if custom invalidate is not pas…
jerelmiller 635aca6
Fix incorrect ordering of toMatchDocument diff
jerelmiller ddb1f5a
Better validation message in toMatchDocument when argument is not a D…
jerelmiller b5148c1
Allow `next` function to return the transformed document
jerelmiller 018d14e
Update tests to assert `invalidateDocument` now returns cached transf…
jerelmiller bf9f535
Add more document transform tests to ensure validation works as expected
jerelmiller 8c3dd25
Remove ability to invalidate the caches for a document. Will rely on …
jerelmiller 2e9f140
Add ability to create custom cache keys
jerelmiller 9e90b13
Immediately return a transformed document back from the document tran…
jerelmiller 1fe533b
Update test to show uncached transforms return transformed document
jerelmiller c4b7092
Update size-limit
jerelmiller 782d162
Add tests to describe query property
jerelmiller ee0b4ae
Simplify DocumentTransform caching using Trie entries.
benjamn 3187c3a
Minor tweak to comment about why cache is disabled for `concat` and `…
jerelmiller 4ec1b52
Ensure `getCacheKey` option allows `undefined` return type
jerelmiller fbc436e
No need for intermediate variable in `.split`
jerelmiller f7890ae
Format code updated in ee0b4ae
jerelmiller 46748ba
Add formatting changes to git-blame-ignore-revs
jerelmiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found it useful in the past for cache-key-generating functions like
getCacheKey
to have the option of refusing to generate a key when the cache should be skipped/ignored. Specifically,getCacheKey
could returnDocumentTransformCacheKey | undefined
, withundefined
indicating to skip the cache for this document. That decision could be made dynamically based on the contents of thedocument
, for example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change as part of ee0b4ae.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes a ton of sense. Thanks so much for this update!