Explain apollo graphql partialRefetch like I'm five
Robin Kretzschmar

Robin Kretzschmar @darksmile92

About: Started coding at the age of 13, now a professional software engineer and Scrum Master, creating and maintaining enterprise solutions. Eat - Sleep - Code - Lift - Repeat 💪🏾

Location:
Mannheim, Germany
Joined:
Nov 14, 2017

Explain apollo graphql partialRefetch like I'm five

Publish Date: Nov 29 '20
6 3

Apollo GraphQL Query hook has an option called partialRefetch and the docs state:

If true, perform a query refetch if the query result is marked as being partial, and the returned data is reset to an empty Object by the Apollo Client QueryManager (due to a cache miss). The default value is false for backwards-compatibility's sake, but should be changed to true for most use-cases.

Sadly I don't fully get it by reading the docs and searching online.

  • What is different for queries using this parameter?
  • When to use it?

Please go ahead and ELI5!

Comments 3 total

  • Michael Stramel
    Michael StramelMar 25, 2021

    Hey, I was looking for this too. This was the best and pretty much only answer I could find.

    When a Query component is mounted, and a mutation is executed that returns the same ID as the mounted Query, but has less fields in its result, Apollo Client's QueryManager returns the data as an empty Object since a hit can't be found in the cache. This can lead to application errors when the UI elements rendered by the original Query component are expecting certain data values to exist, and they're all of a sudden stripped away. The recommended way to handle this is to use the mutations update prop to reconcile the mutation result with the data in the cache, getting everything into the expected state. This can definitely be a cumbersome process however, so to help address this the partialRefetch prop can be used to automatically refetch the original query and update the cache.

Add comment