title: Why are my Apollo cache updates not reflected in my queries?
body: <p>I am trying to use Apollo cache for local state management to store the state of a form so it can be returned to without clearing.</p>
  
  <p>I am experiencing a problem where the cache is being updated but subsequent queries to the cache are returning stale data. I have experienced this problem in React components using the <code>useQuery</code> hook, and also in Apollo DevTools which I will use to demonstrate it below:</p>
  
  <p>I have this mutation and query set in my resolvers (I am using Typescript):</p>
  
  <pre class="lang-js prettyprint-override"><code>const resolvers = {
    Mutation: {
      storeLetterDraft: (_root, args: { type: string, details: LetterSending }, { client, getCacheKey }) =&gt; {
        const id = getCacheKey({
          __typename: "LetterDraft",
          id: args.type,
        });
  
        const data = { ...args.details };
  
        client.writeFragment({
          data,
          id,
          fragment: LETTER_SENDING_FRAGMENT,
        });
      },
    },
    Query: {
      letterDraft: (_root, args: { type: string }, { client, getCacheKey }) =&gt; {
        // I HAVE TRIED A DEBUGGER STATEMENT HERE
        const id = getCacheKey({
          __typename: "LetterDraft",
          id: args.type,
        });
  
        return client.readFragment({
          id,
          fragment: LETTER_SENDING_FRAGMENT,
        });
      },
    },
  }
  </code></pre>
  
  <p>My fragment is:</p>
  
  <pre class="lang-js prettyprint-override"><code>export const LETTER_SENDING_FRAGMENT = gql`
    fragment DraftLetterSending on LetterDraft {
      date
      firstName
      lastName
      addressLine1
      addressLine2
      addressTown
      addressCounty
      addressPostcode
    }
  `;
  </code></pre>
  
  <p>I am initialising my cache with:</p>
  
  <pre class="lang-js prettyprint-override"><code>cache.writeData({
    data: {
      letterDrafts: [{
        __typename: "LetterDraft",
        id: "CREATE",
        addressCounty: "Northamptonshire",
        addressLine1: "1 Watkin Terrace",
        addressLine2: "",
        addressPostcode: "NN1 3ER",
        addressTown: "Northampton",
        date: "2019-11-01",
        firstName: "d",
        lastName: "d",
      }],
    },
  });
  </code></pre>
  
  <p>My mutation looks like:</p>
  
  <pre class="lang-js prettyprint-override"><code>export const storeCreateLetterSendingMutation = gql`
    mutation StoreCreateLetterSending($details: LetterSending!) {
      storeLetterDraft(type: "CREATE", details: $details) @client
    }
  `;
  </code></pre>
  
  <p>Before mutation, the cache in Apollo DevTools looks as expected:</p>
  
  <p><a href="https://i.stack.imgur.com/unzcI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/unzcI.png" alt="Cache before mutation"></a></p>
  
  <p>And a query returns as expected:</p>
  
  <p><a href="https://i.stack.imgur.com/bbVAN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bbVAN.png" alt="Query before mutation"></a></p>
  
  <p>After the mutation is performed, the cache updates:</p>
  
  <p><a href="https://i.stack.imgur.com/73UKh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/73UKh.png" alt="Cache after mutation"></a></p>
  
  <p>However, running the query again results in the stale data:</p>
  
  <p><a href="https://i.stack.imgur.com/hT65T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hT65T.png" alt="enter image description here"></a></p>
  
  <p>Interestingly if I put a debugger statement in the part above (<code>I HAVE TRIED A DEBUGGER STATEMENT HERE</code>), then it seems the query resolver is run the first time, but not the second time, so it appears the query is being cached - even though it is the cache I am updating! Therefore I think the issue is with the query not running the resolver subsequently.</p>