mutation is also cached, with SplayTreeMap
MODIFY
lib/src/core/query_manager.dart
lib/src/core/query_manager.dart
@@ -119,10 +119,7 @@ class QueryManager {
).first;
// save the data from fetchResult to the cache
- if (
- // should never cache a mutation
- !(options is MutationOptions) &&
- fetchResult.data != null &&
+ if (fetchResult.data != null &&
options.fetchPolicy != FetchPolicy.noCache) {
cache.write(
operation.toKey(),

MODIFY
lib/src/link/operation.dart
lib/src/link/operation.dart
-import 'dart:convert';
+import 'dart:collection' show SplayTreeMap;
+import 'dart:convert' show json;
+import 'dart:io' show File;
class Operation {
- Operation({
+ factory Operation({
+ String document,
+ Map<String, dynamic> variables,
+ String operationName,
+ Map<String, dynamic> extensions,
+ }) =>
+ Operation._(
+ document: document,
+ variables: SplayTreeMap<String, dynamic>.of(variables),
+ operationName: operationName,
+ extensions: extensions,
+ );
+
+ Operation._({
this.document,
this.variables,
this.operationName,
@@ -9,13 +24,13 @@ class Operation {
});
final String document;
- final Map<String, dynamic> variables;
+ final SplayTreeMap<String, dynamic> variables;
final String operationName;
final Map<String, dynamic> extensions;
final Map<String, dynamic> _context = <String, dynamic>{};
- /// Sets the context of an opration by merging the new context with the old one.
+ /// Sets the context of an operation by merging the new context with the old one.
void setContext(Map<String, dynamic> next) {
_context.addAll(next);
}
@@ -28,9 +43,14 @@ class Operation {
}
String toKey() {
- /// XXX we're assuming here that variables will be serialized in the same order.
- /// that might not always be true
- final String encodedVariables = json.encode(variables);
+ /// SplayTreeMap is always sorted
+ final String encodedVariables =
+ json.encode(variables, toEncodable: (dynamic object) {
+ if (object is File) {
+ return object.path;
+ }
+ return object;
+ });
return '$document|$encodedVariables|$operationName';
}

mutation is also cached, with SplayTreeMap (#7)