score:4

every object should return id, _id or alternatively a custom id field (https://www.apollographql.com/docs/react/caching/cache-configuration) for automatic merges to function.

const cache = new inmemorycache({
  typepolicies: {
    product: {
      keyfields: ["custom-id-field"],
    },
  },
});

(!)people often forget that cache operations require the same variables used for the initial query (!)

mutation sample (adding a purchase):

update(cache, { data: newpurchase } }) => {
  let productcache = cache.readquery({
    query: productquery,
    variables: {
      id: productid
    }
  })
 
  cache.writequery({
    query: productquery,
    variables: { id: productid },
    data: {
      product: {
        ...productcache.product,
        purchases: productcache.product.purchases.concat(newpurchase)
      }
    }
  });
 };
}

(important: each purchase also requires it's own individual id that needs to be returned)

score:10

you may need to return an id for apollo to uniquely identify that object in the cache. i think this issue is similar to yours: link

const confirmation_code = gql`
  query {
    my {
      id
      sendnewtokenforconfirmation
    }
  }
`;

Related Query

More Query from same tag