-
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
Compare DocumentNode
used in refetchQueries
as strings
#12236
Merged
jerelmiller
merged 16 commits into
apollographql:main
from
charpeni:12164-refetch-queries-with-document-node
Dec 19, 2024
+326
−21
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d04679f
Add test for `refetchQueries` with a `DocumentNode`
charpeni 19d14a7
Test different references of a same query `DocumentNode`
charpeni 9f4b665
Compare `DocumentNode` as strings via `print`
charpeni 521b9d1
Add changeset
charpeni 71f4652
Run Prettier
charpeni ac07d25
Set changeset as a patch
charpeni 75c3420
Simplify changeset
charpeni 3c10ea5
Remove `legacyOneTimeQuery` reference
charpeni 7873f3c
Remove `legacyOneTimeQuery` reference
charpeni 8860968
Only show query name and support anonymous queries
charpeni 1dfb266
Update `.api-reports`
charpeni b632d5d
Fix grammar for anonymous query
charpeni af15100
Fix anonymous query test
charpeni 17c8056
Simplify the logic to get the query name
charpeni 95cd778
Update `.api-reports`
charpeni 03334ab
Update size limits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@apollo/client": patch | ||
--- | ||
|
||
Fix an issue with `refetchQueries` where comparing `DocumentNode`s internally by references could lead to an unknown query, even though the `DocumentNode` was indeed an active query—with a different reference. |
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
Oops, something went wrong.
Oops, something went wrong.
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'm not fully happy with how it ended up here.
At this stage,
nameOrQueryString
is always astring
, but we need to know whether it's a query name, or a printed document node. I'm not sure if we wanted to use AST utils here to parse the string and try to capture the operation node out of it, but it seems like it could be expensive, and they are built with invariants, too. I opted to check if it starts with eitherquery
or{
(a shorthand for an anonymous query starts with a selection set).Let me know what you think.
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.
It actually might be easiest to just add another
Map
where the key is the stringified query and the value is the query name (ornull
in the case that its anonymous), that way we can skip the parsing step and just add it where we know its aDocumentNode
on line 910.Then getting the query name would be as simple as:
In fact, it might also be best just to put the case where you're passing query strings in there as well, then you wouldn't need the
isQueryString
check:This way
queryNames.get(...)
will work in both cases. This at least skips the need toparse
again.Thoughts?
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.
Sounds like a good idea! I was on the fence between that or turning the actual map values into an object:
{ included, queryName }
, but I think it's probably better to split those concerns for now.Will do those changes, thank you!