question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Store ListQuery not updated after mutation

See original GitHub issue

Hi,

following situation:

  • I have a Query to get a list of items
  • a react component to render the list
  • a mutation to add an item
  • a react component to render a form and use the mutation to create a new item
  • the form is rendered in a new page, the list component gets unmounted

In the mutation options i define the list in the refetchQueries. In the network tab the refetch is executed, the new item is included in the result, in the apollo dev tools cache the new item is added. The list in the root query does not include the new item. When i get back to the page where the list is rendered the new item is missing.

Weird: if i render the form in an overlay (the list component doesn’t get unmounted) the refetchQuery works as aspected and the new item is in the new list.

I guess i can use the update in the mutation to add the item manually to the list, but the list is filtered and sorted and would not add this logic to the client, also it works when the list component doesn’t get unmounted. Or use the fetchPolicy: 'network-only' but this is not long term solution.

I’ve found this similar issues: https://github.com/apollographql/apollo-client/issues/1290 but its almost one year old and no new activity.

Did anybody had the same issue and can help?

Many thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

1reaction
rvaitkus23commented, Mar 8, 2018

I have a similar issue. When editing and refetching query, all changes are present. But when an item is added, despite it is returned from the server, it is not present in data.queryName list. fetchPolicy: 'cache-and-network', didn’t helped.

Using:

"apollo-client": "^2.1.0",
"react-apollo": "^2.0.1",
0reactions
shircommented, May 26, 2018

Have same issue with:

    "react-apollo": "^2.1.4",
    "apollo-boost": "^0.1.6",

But cache-and-network helps. Actually I prefer behaviour with cache-and-network but issue should be fixed anyway

Read more comments on GitHub >

github_iconTop Results From Across the Web

Components never get updated after `writeData` or `writeQuery`
I tested render, and it appears not to receive new props after a writeQuery from the mutation update even though the cache seems...
Read more >
How exactly do you update an array in the cache after a ...
Hi, after executing a query getItems, it returns an array of Items which consist of an _id and title, and this appears in...
Read more >
Apollo / GraphQl - Single entity mutation does not update ...
Any ideas on how to have a fresh update of data after each modification ? Here is the mutation code: export const UPDATE_BRAND...
Read more >
Updating the Store – Angular - GraphQL Code Generator
Updating After a Mutation. In some cases, just using dataIdFromObject is not enough for your application UI to update correctly.
Read more >
Query and store data - New Relic Developers
Here you can learn how to use the SDK query components, which allow you to make queries and mutations via NerdGraph, our GraphQL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found