Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

add client to the mutation result #3417

Merged

Conversation

joshalling
Copy link
Contributor

@joshalling joshalling commented Aug 27, 2019

This fixes #3366

According to the docs the client should be in the result. This updates the result to have the client on MutationData added to the result. If the client is undefined, it will refresh it and add it on there.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • If this was a change that affects the external API used in GitHunt-React, update GitHunt-React and post a link to the PR in the discussion.

@joshalling joshalling force-pushed the add-client-to-mutation-result branch from ba85e1c to 89a7d9a Compare August 28, 2019 04:55
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Thanks very much @joshalling!

@hwillson hwillson merged commit 91cbdcb into apollographql:master Aug 30, 2019
hwillson added a commit to apollographql/apollo-client that referenced this pull request Jan 9, 2020
apollographql/react-apollo#3417 adjusted `useMutation` to make sure
the current `ApolloClient` instance is available in the result
returned when `useMutation` is first called. Unfortunately, the changes
in that PR are unintentionally modifying the `useState` based `result`
object directly, instead of using `setResult`. This is ultimately
leading to inconsistencies around the `client` instance sometimes
being included in the result and stored as the `previousResult`, and
other times not being included. This can then lead to infinite
loop / too many render problems caused by the
`!equal(this.previousResult, result)` check in `updateResult` always
passing, and the state continuously being updated by repeated calls
to `setResult`.

This commit adjusts the returned `useMutation` result to be a copy
of the original `useState` based `result`, which then includes the
`client` instance. This ensures the `useState` controlled `result`
object is not mutated outside of calling `setResult`, and avoids
the infinite loop / too many render issue.
hwillson added a commit to apollographql/apollo-client that referenced this pull request Jan 9, 2020
apollographql/react-apollo#3417 adjusted `useMutation` to make sure
the current `ApolloClient` instance is available in the result
returned when `useMutation` is first called. Unfortunately, the changes
in that PR are unintentionally modifying the `useState` based `result`
object directly, instead of using `setResult`. This is ultimately
leading to inconsistencies around the `client` instance sometimes
being included in the result and stored as the `previousResult`, and
other times not being included. This can then lead to infinite
loop / too many render problems caused by the
`!equal(this.previousResult, result)` check in `updateResult` always
passing, and the state continuously being updated by repeated calls
to `setResult`.

This commit adjusts the returned `useMutation` result to be a copy
of the original `useState` based `result`, which then includes the
`client` instance. This ensures the `useState` controlled `result`
object is not mutated outside of calling `setResult`, and avoids
the infinite loop / too many render issue.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@apollo/react-components Mutation : client missing in props & function render props
2 participants