Refetching data in multiple parts of the code at the same time
My problem is : I have a component named HeaderComponent with some props coming from graphql. This component is used in two pages of my app.
In the HeaderComponent in page (1), I modify one of the props by doing a mutation. Then I refetch the new data. In the HeaderComponent in page (2), I want to have the new data that was modify in page (1)
How can I do that ?
Because I try some stuffs but it didn't work. Thanks !
If I understand you correctly, this should "just work" as is. Since it seems like it doesn't, please post your code and we'll see if we can spot what's wrong.
You have to think in a different way when using Relay
You should return everything from your output fields of your mutation to update your frontend
If you are just editting a node, relay will take care to update the store based on the global id of this node
If you adding or removing an edge from a connection you need to use configs or updater to properly update relay store
So your queries/mutations/subscriptions updates the relay store, then relay will update all components that subscribed (using fragments) to this data
Thanks! So I started to use updater to update my Relay store. But I have some issues.
First of all this is my fragment container :

What I want, It's to add a new favorite in my favorites's list. So I need to create a new favorite. This is my mutation :

The mutation returns the new favorite with its ID.
When the query is completed, I want to update my Relay Store, so that the new data appears in the view. This is the updater function :

I thought I did good, but the Relay Store does not update. Do you have an idea on what I am doing wrong ?
Thanks for your time!
Mutations are:
- Write, then
- Read
Just ask for the fields of favorites on mutation and Relay will update it automatically
@ruben-kasaz I think it is because you're not passing the arguments to setLinkedRecords. Try passing the same arguments (third parameter) to that as you're doing to getLinkedRecords.
I was able to produce exactly what you are describing - having a component reused in multiple places updated following a mutation. The key to that is making proper use of Relay store with mutations.
Relay's experimental docs sample project helped with that a ton (note: that app was posting comments to the actual repo issues discussion!): https://github.com/relayjs/relay-examples/tree/master/issue-tracker
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.