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:
- If a
TypePolicy
is provided for the given type, it'sTypePolicy.keyFields
are used.- If a
dataIdFromObject
funciton is provided, the result is used.- The
id
or_id
field (respectively) are used.
- Inheritance
-
- Object
- GraphQLDataProxy
- GraphQLCache
Constructors
-
GraphQLCache({Store? store, DataIdResolver? dataIdFromObject, Map<
String, TypePolicy> typePolicies = const {}, Map<String, Set< possibleTypes = const {}, PartialDataCachePolicy partialDataPolicy = PartialDataCachePolicy.acceptForOptimisticData, Object? sanitizeVariables(Object?) = sanitizeFilesForCache})String> >
Properties
- 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 tonormalize
final - 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
final
-
possibleTypes
→ Map<
String, Set< String> > -
possibleTypes
to pass down tonormalize
final - 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
final
-
typePolicies
→ Map<
String, TypePolicy> -
typePolicies
to pass down tonormalize
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent 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}) → 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.
inherited
-
recordOptimisticTransaction(
CacheTransaction transaction, String addId) → void -
Record the given
transaction
into a patch with the idaddId
-
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, {required Map< String, dynamic> data, bool? broadcast = true}) → void -
Writes a GraphQL fragment to any arbitrary id.
then
broadcast
changes to watchers unlessbroadcast: false
inherited -
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 unlessbroadcast: false
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited