-
Notifications
You must be signed in to change notification settings - Fork 786
Component does not re-render after mutation in React, apollo-react,graphql #3493
Comments
You shouldn't modify |
@dylanwulf By freezing do you mean cache results become immutable ? In that case how do I re-render the list that I have just deleted an item from. I am not using redux store etc. |
@dylanwulf I create a new object. Transfer cachedResponse (along with new data) to the new object and write the new object in store.writeQuery. is that what you meant ? |
I'm seeing this issue and I'm definitely constructing a new object when doing |
@bwesner @dylanwulf I got this to work, basically I was calling mutation2 in another component altogether and updating cache there. Instead I wrote mutation2 in parent component and passed it as a function (useMutation gives a functional instance), to the child component2. Whenever child component2 calls that function (onClick events etc) mutation happens and state is re-rendered as required. |
@dylanwulf Is this a breaking change in version 3? Since updating, a lot of my code relying on being able to mutate the response from |
As far as I know it's not a breaking change in react-apollo v3, but I think mutating the existing data was never a recommended approach. When apollo-client v3 releases, |
@dylanwulf Will |
@kartikjain26 I don't know if |
@dylanwulf Thanks and yes I am doing cache update in |
@kartikjain26 Turns out I was wrong. The |
Hi guys, I have ran into the following problem while integrating graphql server with React UI using Apollo-react and its hooks.
I have 2 components, Lets say ComponentA and ComponentB. These 2 are in separate files, if that matters anyhow.
BaseComponent class is where the flow begins.
There are 3 queries, QUERY1, QUERY2 (mutation), QUERY3 (mutation)
In first code block, I fetch a list with QUERY1, then I update the list with QUERY2, then I append/delete cachedResponse of QUERY1 after mutation on . (List has to be updated after mutation) -> Works fine, List gets updated real-time as component is re-rendered with new cachedResponse.
When I click I render a new Component2, with same instance of Apollo Client passed as props.
In component 2 I trigger QUERY3 (mutation query), then as before I update the cacheResponse of Query1 (List has to be updated after QUERY3 also).
However unlike first mutation, component does not re-render even after the cache is updated for QUERY1.
Can someone give me insight or point out areas in which I may be going wrong ?
Dependencies
"@apollo/react-hooks": "^3.1.0",
"react-apollo": "^3.1.0",
"graphql": "14.4.2",
The text was updated successfully, but these errors were encountered: