1- import 'dart:convert' ;
1+ import 'dart:collection' show SplayTreeMap;
2+ import 'dart:convert' show json;
3+ import 'dart:io' show File;
24
35class Operation {
4- Operation ({
6+ factory Operation ({
7+ String document,
8+ Map <String , dynamic > variables,
9+ String operationName,
10+ Map <String , dynamic > extensions,
11+ }) =>
12+ Operation ._(
13+ document: document,
14+ variables: SplayTreeMap <String , dynamic >.of (variables),
15+ operationName: operationName,
16+ extensions: extensions,
17+ );
18+
19+ Operation ._({
520 this .document,
621 this .variables,
722 this .operationName,
823 this .extensions,
924 });
1025
1126 final String document;
12- final Map <String , dynamic > variables;
27+ final SplayTreeMap <String , dynamic > variables;
1328 final String operationName;
1429 final Map <String , dynamic > extensions;
1530
1631 final Map <String , dynamic > _context = < String , dynamic > {};
1732
18- /// Sets the context of an opration by merging the new context with the old one.
33+ /// Sets the context of an operation by merging the new context with the old one.
1934 void setContext (Map <String , dynamic > next) {
2035 _context.addAll (next);
2136 }
@@ -28,9 +43,14 @@ class Operation {
2843 }
2944
3045 String toKey () {
31- /// XXX we're assuming here that variables will be serialized in the same order.
32- /// that might not always be true
33- final String encodedVariables = json.encode (variables);
46+ /// SplayTreeMap is always sorted
47+ final String encodedVariables =
48+ json.encode (variables, toEncodable: (dynamic object) {
49+ if (object is File ) {
50+ return object.path;
51+ }
52+ return object;
53+ });
3454
3555 return '$document |$encodedVariables |$operationName ' ;
3656 }
0 commit comments