Skip to content

Watching a query leads to constant refetch when value of a nullable type is null #3092

Closed
apollographql/apollo-ios-dev
#25
@aleksanderlorenc-lw

Description

Summary

Hi, at Lifeworks we are watching queries in parts of the app. After upgrading to Apollo 1.2.1 we started observing failures when watching a query when a nullable type is null, leading to constant re-fetches of this query.

We ran a quick investigation and this is the result:

  1. Watch is done using GraphQLQueryWatcher.store
  2. GraphQLSelectionSetMapper is called with default initializer which assumes (handleMissingValues: HandleMissingValues = .disallow) in the accumulator parameter of transaction.readObject - which disallows null values for a field
  3. Because handleMissingValues is disallow, GraphQLSelectionSetMapper.acceptMissingValue throws JSONDecodingError.missingValue
  4. Error is passed to ApolloStore.withinReadTransaction
(lldb) po error
▿ GraphQLExecutionError
  ▿ path : some.field.on.schema.11.nullableFieldItself
    ▿ head : Optional<Node>
      ▿ some : <Node: 0x600001f0f600>
  - underlying : ApolloAPI.JSONDecodingError.missingValue
  1. GraphQLQueryWatcher.store failure condition triggers a re-fetch on failure, cycle repeats

We observed that contrary to load, the values are stored with allowForOptionalFields, if that is of any help.

To summarize:

  • cache shouldn’t fail when null if is nullable
  • the watcher probably shouldn't do a remote refresh on an error
  • insert/updates on the cache should fail if wrong data is being inserted (fail early, not let us insert and then fail when retrieving)

Version

1.2.1

Steps to reproduce the behavior

  1. Use a query which contains a nullable type
  2. Watch the query
  3. Backend should respond with the value being null
  4. When written to and loaded from the cache, an error will be thrown and will result in a remote refetch

Logs

(lldb) po error
▿ GraphQLExecutionError
  ▿ path : some.field.on.schema.11.nullableFieldItself
    ▿ head : Optional<Node>
      ▿ some : <Node: 0x600001f0f600>
  - underlying : ApolloAPI.JSONDecodingError.missingValue


### Anything else?

_No response_

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions