writeQuery method
void
writeQuery(})
inherited
Writes a GraphQL query to the root query id,
then broadcast
changes to watchers unless broadcast: false
normalize
the given data
into the cache using graphql metadata from request
.
Conceptually, this can be thought of as providing a manual execution result
in the form of data
For complex normalize
type policies that involve custom reads,
optimistic
will be the default.
Will throw a PartialDataException if the data
structure
doesn't match that of the request
operation.document
,
or a CacheMisconfigurationException if the write fails for some other reason.
Implementation
void writeQuery(
Request request, {
required Map<String, dynamic> data,
bool? broadcast = true,
}) {
try {
normalizeOperation(
// provided from cache
write: (dataId, value) => writeNormalized(dataId, value),
read: (dataId) => readNormalized(dataId),
typePolicies: typePolicies,
dataIdFromObject: dataIdFromObject,
acceptPartialData: acceptPartialData,
addTypename: addTypename,
// provided from request
document: request.operation.document,
operationName: request.operation.operationName,
variables: sanitizeVariables(request.variables)!,
// data
data: data,
possibleTypes: possibleTypes,
);
if (broadcast ?? true) {
broadcastRequested = true;
}
} on PartialDataException catch (e, stackTrace) {
if (request.validatesStructureOf(data)) {
throw CacheMisconfigurationException(
e,
stackTrace,
request: request,
data: data,
);
}
rethrow;
}
}