GraphQLDataProxy class abstract

A proxy to the normalized data living in our store.

This interface allows a user to read and write denormalized data which feels natural to the user whilst in the background this data is being converted into the normalized store format.

Here is a complete and expository rundown of the usage of GraphQLDataProxy's methods (readQuery, writeQuery, readFragment, writeFragment), given an instance of GraphQLClient client as an example

/// entity identifiers for normalization
final idFields = {'__typename': 'MyType', 'id': 1};

/// The direct cache API uses `gql_link` Requests directly
/// These can also be obtained via `options.asRequest` from any `Options` object,
/// or via `Operation(document: gql(...)).asRequest()`
final queryRequest = Request(
  operation: Operation(
    document: gql(
        someField {

final queryData = {
  'someField': {
    'myField': 'originalValue',

/// `broadcast: true` (the default) would rebroadcast cache updates to all safe instances of `ObservableQuery`
/// **NOTE**: only `GraphQLClient` can immediately call for a query rebroadcast. if you request a rebroadcast directly
/// from the cache, it still has to wait for the client to check in on it
client.writeQuery(queryRequest, data: queryData, broadcast: false);

/// `optimistic: true` (the default) integrates optimistic data
/// written to the cache into your read.
    client.readQuery(queryRequest, optimistic: false), equals(queryData));

/// While fragments are never executed themselves, we provide a `gql_link`-like API for consistency.
/// These can also be obtained via `Fragment(document: gql(...)).asRequest()`.
final fragmentRequest = FragmentRequest(
    fragment: Fragment(
      document: gql(
          fragment mySmallSubset on MyType {
    idFields: idFields);

/// We've specified `idFields` and are only editing a subset of the data
final fragmentData = {
  'myField': 'updatedValue',
  'someNewField': [
    {'newData': false}

/// We didn't disable `broadcast`, so all instances of `ObservableQuery` will be notified of any changes
client.writeFragment(fragmentRequest, data: fragmentData);

/// __typename is automatically included in all reads
    '__typename': 'MyType',

final updatedQueryData = {
  'someField': {
    'myField': 'updatedValue',

/// `myField` is updated, but we don't have `someNewField`, as expected.
expect(client.readQuery(queryRequest), equals(updatedQueryData));




hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
readFragment(FragmentRequest fragmentRequest, {bool optimistic}) Map<String, dynamic>?
Reads a GraphQL fragment from any arbitrary id.
readQuery(Request request, {bool optimistic}) Map<String, dynamic>?
Reads a GraphQL query from the root query id.
toString() String
A string representation of this object.
writeFragment(FragmentRequest fragmentRequest, {required Map<String, dynamic> data, bool? broadcast}) → void
Writes a GraphQL fragment to any arbitrary id. then broadcast changes to watchers unless broadcast: false
writeQuery(Request request, {required Map<String, dynamic> data, bool? broadcast}) → 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.