title: ApolloClient v3 fetchMore with nested query results
body: <p>I'm using ApolloClient 3 the GitHub GraphQL API to retrieve all releases from a repo.</p>
  <p>This is what the query looks like:</p>
  <pre><code>query ($owner: String!, $name: String!, $first: Int, $after: String, $before: String) {
    repository(owner: $owner, name: $name) {
      id
      releases(orderBy: {field: CREATED_AT, direction: DESC}, first: $first, after: $after, before: $before) {
        nodes {
          name
          publishedAt
          resourcePath
          tagName
          url
          id
          isPrerelease
          description
          descriptionHTML
        }
        totalCount
        pageInfo {
          endCursor
          hasNextPage
          hasPreviousPage
          startCursor
        }
      }
    }
  }
  </code></pre>
  <p>This is what the result payload looks like:</p>
  <p><a href="https://i.stack.imgur.com/v3VFH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v3VFH.png" alt="Query result payload" /></a></p>
  <p>This returns me the first x entries (<code>nodes</code>). So far, all good.</p>
  <p>I need to implement pagination and I make use of the <code>fetchMore</code> function provided by ApolloClient <code>useQuery</code>. Calling <code>fetchMore</code> fetches the next x entries successfully but these are not displayed in my component list.</p>
  <p>According to the <a href="https://www.apollographql.com/docs/react/pagination/overview/" rel="nofollow noreferrer">ApolloClient Pagination documentation</a>, it seems necessary to handle the <code>merging</code> of the <code>fetchMore</code> results with the ApolloClient caching mechanism. The documentation is understandable for simple situations but I am struggling to implement a solution for the situation where the actual array of results that needs to be merged togeher is deeply nested in the query result (<code>repository -&gt; releases -&gt; nodes</code>).</p>
  <p>This is my implementation of the InMemoryCache options merge:</p>
  <pre><code>const inMemoryCacheOptions = {
    addTypename: true,
    typePolicies: {
      ReleaseConnection: {
        fields: {
          nodes: {
            merge(existing, incoming, options) {
              const previous = existing || []
              const results = [...previous, ...incoming]
              return results
            }
          }
        }
      },
    }
  }
  </code></pre>
  <p>The <code>results</code> array here contains the full list, including the existing entries and the new x entries. This is essentially the correct result. However, my component list which is using the <code>useQuery</code> and <code>fetchMore</code> functionality does not get the new entries after the <code>fetchMore</code> is called.</p>
  <p>I have tried various combinations in the <code>inMemoryCacheOptions</code> code above but so far I have been unsuccessful.</p>
  <p>To add more context, this is the related component code:</p>
  <pre><code>export default function Releases() {
    const { loading, error, data, fetchMore } = useQuery(releasesQuery, {
      variables: {
        owner: &quot;theowner&quot;,
        name: &quot;myrepo&quot;,
        first: 15
      }
    });
  
    if (loading) return null;
  
    if (error) {
      console.error(error);
      return null;
    }
  
    if (data) {
      console.log(data?.repository?.releases?.pageInfo?.endCursor);
    }
  
    const handleFetchMore = () =&gt; {
      fetchMore({
        variables: {
          first: 15,
          after: data?.repository?.releases?.pageInfo?.endCursor
        }
      });
    };
  
    return (
      &lt;div&gt;
        &lt;ul&gt;
          {data?.repository?.releases?.nodes?.map(release =&gt; (
            &lt;li key={release.id}&gt;{release.name}&lt;/li&gt;
          ))}
        &lt;/ul&gt;
        &lt;button onClick={handleFetchMore}&gt;Fetch More&lt;/button&gt;
      &lt;/div&gt;
    );
  }
  </code></pre>
  <p>After <code>fetchMore</code> the component doesn't rerender with the new data.</p>
  <p>If anyone has any other ideas that I could try, I'd be grateful.</p>