You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How get input data from mutation in body UpdateCacheHandler?
final UpdateCacheHandler<$MyMutation> myMutationHandler = (
CacheProxy proxy,
QueryResponse<$MyMutation> response,
) {
final query = MyQueryToUpdate();
final result = proxy.readQuery(query);
/// update the result
proxy.writeQuery(query, result);
};
The text was updated successfully, but these errors were encountered:
You can access the mutation via the queryRequest property on QueryResponse.
Also, if you want to pass in additional data that isn't an input to the mutation, you can pass in a Context object when creating the mutation.
For example:
/// Create a ContextEntry subclassclassUserContextEntryextendsContextEntry {
finalString userId;
UserContextEntry(this.userId);
@overrideList<Object> get fieldsForEquality => [userId];
}
/// When instantiating your mutation...final mutation =MyMutation(
updateCacheHandlerKey:"myMutationKey",
/// ...pass in an instance of the ContextEntry subclass
context:Context.fromList([UserContextEntry("user123")]),
);
finalUpdateCacheHandler<$MyMutation> myMutationHandler = (
CacheProxy proxy,
QueryResponse<$MyMutation> response,
) {
final query =MyQueryToUpdate();
final result = proxy.readQuery(query);
/// Access the data passed in through ContextEntryfinal userId = response.queryRequest.context.entry<UserContextEntry>().userId;
/// update the result
proxy.writeQuery(query, result);
};
I recognize that subclassing ContextEntry as demonstrated above just to pass in a userId String is a bit verbose. I'm open to suggestions to improve the API (@klavs any thoughts here)?
Hi!
How get input data from mutation in body UpdateCacheHandler?
The text was updated successfully, but these errors were encountered: