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.
Inheritance

Constructors

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

Properties

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

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
readFragment(FragmentRequest fragmentRequest, {bool optimistic = true}) Map<String, dynamic>
Reads a GraphQL fragment from any arbitrary id. [...]
inherited
readNormalized(String rootId, {bool optimistic = true}) Object
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.
inherited
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. [...]
inherited
writeFragment(FragmentRequest request, {Map<String, dynamic> data, bool broadcast = true}) → void
Writes a GraphQL fragment to any arbitrary id. then broadcast changes to watchers unless broadcast: false [...]
inherited
writeNormalized(String dataId, dynamic value) → void
Write normalized data into the cache, deeply merging maps with existing values [...]
writeQuery(Request request, {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 [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited