apollo-client: [2.0] old data after mutation | bug

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

About this issue

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

Most upvoted comments

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