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.

[2.0] old data after mutation | bug

See original GitHub issue

Hi, I have next query

query getMini($id: ID!) {
  mini(id: $id) {
    id
    cover(maxWidth: 600, maxHeight: 400)
  }
}

and next mutation

mutation ($signature: String!) {
    mini: submitMiniCoverS3DirectUpload(signature: $signature) {
      id
      cover(maxWidth: 600, maxHeight: 400)
    }
  }

as you can see after success mutation I will get new cover photo. So far so good. Everything is working fine with apolo 1.x. In apollo 2 I will get same cached cover photo after mutation. I checked response from server. There are valid new fields. But apollo is using old cached data.

I am using latest versions of all libraries:

    "apollo-cache-inmemory": "^0.2.0-rc.1",
    "apollo-client": "^2.0.0-rc.3",
    "apollo-link": "^0.8.0",
    "apollo-link-http": "^0.8.0",
    "apollo-link-batch-http": "^0.4.0",
    "apollo-link-retry": "^0.8.0",
    "apollo-link-dedup": "^0.6.0",

I think that this is related also to last comment https://github.com/apollographql/apollo-client/issues/2266#issuecomment-335933377.

FYI: fetchPolicy: ‘network-only’ is not working

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:25 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
seedencommented, Oct 20, 2017
2reactions
bknifflercommented, Oct 24, 2017

So, I got 2 queries and 1 mutation:

export const gqlList = gql`
  query list($start: DateTime, $end: DateTime) {
    list(start: $start, end: $end) {
      id
      name
    }
  }
`;
export const gqlItem = gql`
  query item($id: String!) {
    item(id: $id) {
      id
      name
      text
    }
  }
`;
export const gqlMutation = gql`
  mutation item($id: String, $input: ItemInput!) {
    item(id: $id, input: $input) {
      id
      name
      text
    }
  }
`;
export const withItem = graphql(gqlItem, {
  options: ({ id }) => ({
    variables: { id },
    fetchPolicy: !id ? 'cache-only' : undefined,
  }),
  props: ({ ownProps, data }) => ({
    ...ownProps,
    data,
    item: data.item || {},
  }),
});

export const withList = graphql(gqlList, {
  options: ({ start, end }) => ({
    pollInterval: 20000,
    variables: {
      start,
      end,
    },
  }),
  props: ({ ownProps, data }) => ({
    list: data.list || [],
  }),
});

...

client.mutate({
          mutation: gqlMutation,
          variables: variables
        })

When I update an existing item (inside a modal that closes after save, so unmounting), I’m getting the new values returned from the mutation and the list immediately updates accordingly (so far everything good). But when I reopen the item/modal, it has the old values. As soon as the list polling interval kicks in, the modal immediately shows the correct values.

fixed by rc7

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
This article demonstrates how to send updates to your GraphQL server with the useMutation hook. You'll also learn how to update the Apollo...
Read more >
Apollo Client mutation error and updating components
If the mutation was successful, the component's data is updated using the proxy param, but I can't see an equivalent way of dealing...
Read more >
How to update the Apollo Client's cache after a mutation
writeQuery({ query, variables: { published: true }, data }); } catch(error) { console.error(error); }},. That's it. While this use case is ...
Read more >
React Query mutating data - Daily Dev Tips
How to manually update React Query cache with useMutation ... can return the old data, and we then merge the old data with...
Read more >
Announcing SWR 2.0
Announcing SWR 2.0: new mutation APIs and improvd optimistic UI capabilities, ... request returns us the latest data from the server, ...
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