GraphQLCache class

Optimistic GraphQL Entity cache with normalize TypePolicy support and configurable store.

NOTE: The default InMemoryStore does not persist to disk. The recommended store for persistent environments is the HiveStore.

dataIdFromObject and typePolicies are passed down to normalize operations, which say:

IDs are determined by the following:

  1. If a TypePolicy is provided for the given type, it's TypePolicy.keyFields are used.
  2. If a dataIdFromObject funciton is provided, the result is used.
  3. The id or _id field (respectively) are used.


GraphQLCache({Store? store, DataIdResolver? dataIdFromObject, Map<String, TypePolicy> typePolicies = const {}, Map<String, Set<String>> possibleTypes = const {}, PartialDataCachePolicy partialDataPolicy = PartialDataCachePolicy.acceptForOptimisticData, Object? sanitizeVariables(Object?) = sanitizeFilesForCache})


acceptPartialData bool
Whether it is permissible to write partial data, as determined by partialDataPolicy.
no setter
addTypename bool
Whether to add __typename automatically.
getter/setter pairinherited
broadcastRequested bool
Flag used to request a (re)broadcast from the QueryManager.
getter/setter pairinherited
dataIdFromObject → DataIdResolver?
Optional dataIdFromObject function to pass through to normalize
hashCode int
The hash code for this object.
no setterinherited
inflightOptimisticTransactions int
Tracks the number of ongoing transactions (cache updates) to prevent rebroadcasts until they are completed.
getter/setter pair
optimisticPatches List<OptimisticPatch>
List of patches recorded through recordOptimisticTransaction
getter/setter pair
partialDataPolicy PartialDataCachePolicy
Determines how partial data should be handled when written to the cache
possibleTypes Map<String, Set<String>>
possibleTypes to pass down to normalize
returnPartialData bool
Used for testing.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sanitizeVariables ↔ SanitizeVariables
Input variable sanitizer for referencing custom scalar types in cache keys.
finalgetter/setter pairinherited-setter
store Store
Stores the underlying normalized data. Defaults to an InMemoryStore
typePolicies Map<String, TypePolicy>
typePolicies to pass down to normalize


noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
readFragment(FragmentRequest fragmentRequest, {bool optimistic = true}) Map<String, dynamic>?
Reads a GraphQL fragment from any arbitrary id.
readNormalized(String rootId, {bool? optimistic = true}) Map<String, dynamic>?
Reads dereferences an entity from the first valid optimistic layer, defaulting to the base internal HashMap.
readQuery(Request request, {bool optimistic = true}) Map<String, dynamic>?
Reads a GraphQL query from the root query id.
recordOptimisticTransaction(CacheTransaction transaction, String addId) → void
Record the given transaction into a patch with the id addId
removeOptimisticPatch(String removeId) → void
Remove a given patch from the list
shouldBroadcast({bool claimExecution = false}) bool
Whether a cache operation has requested a broadcast and it is safe to do.
toString() String
A string representation of this object.
writeFragment(FragmentRequest request, {required Map<String, dynamic> data, bool? broadcast = true}) → void
Writes a GraphQL fragment to any arbitrary id. then broadcast changes to watchers unless broadcast: false
writeNormalized(String dataId, Map<String, dynamic>? value) → void
Write normalized data into the cache, deeply merging maps with existing values
writeQuery(Request request, {required Map<String, dynamic> data, bool? broadcast = true}) → void
Writes a GraphQL query to the root query id, then broadcast changes to watchers unless broadcast: false


operator ==(Object other) bool
The equality operator.