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

react: MutationResult.client is always set #6617

Merged
merged 2 commits into from
Jul 20, 2020

Conversation

glasser
Copy link
Member

@glasser glasser commented Jul 16, 2020

As far as I can tell, whenever a MutationResult is provided to the user of
useMutation (or the component or HOC), it always contains a client; eg,
OperationData.refreshClient checks this invariant.

MutationResult is also used to type an internal state variable used by
MutationData and useMutation; this one doesn't contain a client. This PR
changes that variable to different type without client, and the actual exposed
MutationResult now has a non-optional client. This makes it match
QueryResult.

Now TypeScript consumers of useMutation don't need to check to see if client
exists before using it.

@glasser
Copy link
Member Author

glasser commented Jul 16, 2020

I believe this is backwards-compatible because MutationResults are only output
by the Apollo Client API, not received by them. (Unless I'm missing something,
eg if user code that checks if (client) will stop compiling because TypeScript (with certain flags?)
doesn't let you do a condition that will always be true?)

@glasser glasser force-pushed the glasser/mutation-result-client-always branch from c6695f2 to 040a192 Compare July 16, 2020 17:12
@benjamn benjamn requested a review from hwillson July 16, 2020 23:25
@benjamn benjamn added this to the Post 3.0 milestone Jul 16, 2020
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, and I agree that making an optional field of a provided object non-optional should be a compatible change. I say "provided object" because developers don't have to create these MutationResult objects themselves.

Also, we're about to release a minor version (3.1.0), so this kind of change should be even less of a surprise.

glasser and others added 2 commits July 20, 2020 16:15
As far as I can tell, whenever a MutationResult is provided to the user of
useMutation (or the component or HOC), it always contains a `client`; eg,
OperationData.refreshClient checks this invariant.

MutationResult is also used to type an internal state variable used by
MutationData and useMutation; this one doesn't contain a `client`. This PR
changes that variable to different type without `client`, and the actual exposed
MutationResult now has a non-optional `client`. This makes it match
`QueryResult`.

Now TypeScript consumers of `useMutation` don't need to check to see if `client`
exists before using it.
@benjamn benjamn force-pushed the glasser/mutation-result-client-always branch from 040a192 to 50d3217 Compare July 20, 2020 20:17
@benjamn benjamn merged commit 4a74e29 into master Jul 20, 2020
@benjamn benjamn deleted the glasser/mutation-result-client-always branch July 20, 2020 20:20
@benjamn
Copy link
Member

benjamn commented Jul 28, 2020

This is officially available now in @apollo/client@3.1.0 (just published to npm).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants