title: Apollo query has the wrong data from cache
body: <p>Apollo query has the wrong data from cache in my react app.</p>
  
  <p>If I set query's fetchPolicy to 'network-only', everything work properly.</p>
  
  <p>So I think it is a cache problem.</p>
  
  <p>I have been working hard trying to solve the problem and see articles about apollo cache, but I still can't solve the problem.</p>
  
  <p>Here are my results after querying:</p>
  
  <p>parameter memberId is null (result is correct)</p>
  
  <pre><code>[
    {
      "id": 87,
      "totalQuantity": 12,
      "Orders": [
        {
          "id": 1,
          "quantity": 11,
          "Member": {
            "id": 1,
            "name": "A"
          }
        },
        {
          "id": 28,
          "quantity": 1,
          "Member": {
            "id": 9,
            "name": "B"
          }
        }
      ]
    },
    {
      "id": 88,
      "totalQuantity": 1,
      "Orders": [
        {
          "id": 2,
          "quantity": 1,
          "Member": {
            "id": 1,
            "name": "A"
          }
        }
      ]
    }
  ]
  </code></pre>
  
  <p>parameter memberId is 9 (result is correct)</p>
  
  <pre><code>[
    {
      "id": 87,
      "totalQuantity": 1,
      "Orders": [
        {
          "id": 28,
          "quantity": 1,
          "Member": {
            "id": 9,
            "name": "B"
          }
        }
      ]
    }
  ]
  </code></pre>
  
  <p>parameter memberId is 1 (result is correct)</p>
  
  <pre><code>[
    {
      "id": 87,
      "totalQuantity": 11,
      "Orders": [
        {
          "id": 1,
          "quantity": 11,
          "Member": {
            "id": 1,
            "name": "A"
          }
        }
      ]
    },
    {
      "id": 88,
      "totalQuantity": 1,
      "Orders": [
        {
          "id": 2,
          "quantity": 1,
          "Member": {
            "id": 1,
            "name": "A"
          }
        }
      ]
    }
  ]
  </code></pre>
  
  <p>but when I back to parameter is null the result is wrong</p>
  
  <pre><code>[
    {
      "id": 87,
      "totalQuantity": 11,
      "Orders": [
        {
          "id": 1,
          "quantity": 11,
          "Member": {
            "id": 1,
            "name": "A"
          }
        }
      ]
    },
    {
      "id": 88,
      "totalQuantity": 1,
      "Orders": [
        {
          "id": 2,
          "quantity": 1,
          "Member": {
            "id": 1,
            "name": "A"
          }
        }
      ]
    }
  ]
  </code></pre>
  
  <p>Member B (id = 9) is disappear.. </p>
  
  <p>and I back to parameter is 9 (result is wrong)</p>
  
  <pre><code>[
    {
      "id": 87,
      "totalQuantity": 11,
      "Orders": [
        {
          "id": 1,
          "quantity": 11,
          "Member": {
            "id": 1,
            "name": "A"
          }
        }
      ]
    }
  ]
  </code></pre>
  
  <p>I get the Member A's data instead of Member B</p>
  
  <p>Can someone help me? Thanks</p>
  
  <hr>
  
  <p>My client configuration (cache is InMemoryCache)</p>
  
  <pre><code>const client = new ApolloClient({
    link: ApolloLink.from([
      httpLink,
    ]),
    cache,
    dataIdFromObject: o =&gt; ${o.id}${o.__typename},
  });
  </code></pre>
  
  <p>I use queryHook to wrap my component</p>
  
  <pre><code>const queryHook = graphql(FETCH_ORDER_GROUP_SHIPMENT_LIST, {
    options: ownProps =&gt; ({
    variables: {
      memberId: ownProps.options.memberId || null,
    },
  }),
    props: ({
      data: {
        orderGroupShipmentList,
      },
    }) =&gt; ({
      orderGroupShipmentList: orderGroupShipmentList || [],
    });
  </code></pre>
  
  <p>Also I use Query tag(other data) to wrap my content</p>
  
  <p>and its parameter is memberId as well.</p>
  
  <p>the structure like this</p>
  
  <pre><code>&lt;Query
    variables={{ memberId: options.memberId || null }}
    query={FETCH_MEMBER_LIST_QUERY}&gt;
    content that use orderGroupShipmentList and memberList
  &lt;/Query&gt;
  </code></pre>
  
  <p>I don't know if this is specific enough</p>
  
  <p>Let me know if this is not specific enough</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>2019-09-16</p>
  
  <p>For those who facing the same problem:</p>
  
  <p><a href="https://kamranicus.com/posts/2018-03-06-graphql-apollo-object-caching" rel="nofollow noreferrer">https://kamranicus.com/posts/2018-03-06-graphql-apollo-object-caching</a></p>