-
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
Make client writeFragment and writeQuery behaviour consistent with cache #9124
Make client writeFragment and writeQuery behaviour consistent with cache #9124
Conversation
@andrebrantom: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
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.
LGTM with one more idea for better alignment. Thanks @andrebrantom!
src/core/ApolloClient.ts
Outdated
): void { | ||
this.cache.writeFragment<TData, TVariables>(options); | ||
): Reference | undefined { | ||
const ref = this.cache.writeFragment<TData, TVariables>(options); | ||
this.queryManager.broadcastQueries(); |
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.
this.queryManager.broadcastQueries(); | |
if (options.broadcast !== false) { | |
this.queryManager.broadcastQueries(); | |
} |
While you're here, here's another alignment/consistency issue. Requesting broadcast: false
should prevent the this.queryManager.broadcastQueries()
call.
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.
Thanks, I just realised that writeQuery
suffers the same set of inconsistencies, should update both and re-title the PR?
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.
@andrebrantom Yes please!
9958f4b
to
89ae716
Compare
Apologies for letting this hang, I've just updated both |
89ae716
to
e5a80f8
Compare
🦋 Changeset detectedLatest commit: 25e63ca The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Thanks a bunch @andrebrantom 🎉 ! We'll get this out with the next patch release!
This change makes the API and behaviour of
ApolloClient::writeFragment
consistent with that ofCache::writeFragment
in that it returns the Reference of the changed object. This is useful if you have some cache manipulation functions that need to run either against the client in a hook or component, or in a mutationupdate()
handler.I created an issue here: apollographql/apollo-feature-requests#319