Merge: `existing' not always empty with network-only

Hello,

I’m using a lazy query to search for some repos using GitHub’s GraphQL API:

const [gqlSearchRepos, { loading, error, data, fetchMore }] = useLazyQuery(SEARCH_REPOS, {
  notifyOnNetworkStatusChange: true,
  fetchPolicy: 'network-only'
})

gqlSearchRepos is executed when the user clicks the Search button. The user can choose the query string (e.g. user:nyg) and the number of repos to be fetched per request (repo count).

My problem:

  1. If the user clicks the Search button multiple times without changing the repo count, then in the merge function the existing parameter is always empty. :+1:

  2. If the user changes the repo count and clicks Search, then the existing parameter contains the results of the previous search. This causes an issue because it means I need to manually remove duplicates in the merge function.

  3. If the user then clicks on the Search button once more, without changing the repo count, then the existing parameter is again empty.

I don’t understand the behavior of 2. :slight_smile:. I would expect existing to always be empty when executing gqlSearchRepos. As is the case if I set the fetch policy to cache-first.

keyArgs for the field policy is only set to query and repo count is not included.

Could someone explain why existing is sometimes not empty? and why it differs from cache-first?

Thanks a lot !

If you need to see more code: https://github.com/nyg/dependabot-vuln-viewer. Lazy query is in components/search-results.js, type policy is graphql/apollo.js and the GraphQL query in graphql/queries.js.