@@ -50,20 +50,14 @@ class GQLEncoder extends Converter<GQLOperation, String> {
50
50
51
51
String _encodeOperation (GQLOperation operation) {
52
52
final GQLField field = operation;
53
- final rootResolver = _encodeOperationResolvers (operation);
54
- final operationType =
55
- operation.type == OperationType .mutation ? 'mutation' : 'query' ;
56
- var args = '' ;
53
+ final rootField = _encodeOperationFields (operation);
54
+ final args = (field is Arguments ) ? '(${field .args })' : '' ;
57
55
58
- if (field is Arguments ) {
59
- args = '(${field .args })' ;
60
- }
61
-
62
- return '$operationType ${operation .name } $args { $rootResolver }' ;
56
+ return '${operation .type } ${operation .name } $args { $rootField }' ;
63
57
}
64
58
65
- String _encodeOperationResolvers (GQLField operation) =>
66
- _extractFields (operation).map (_encodeResolver ).join (' ' );
59
+ String _encodeOperationFields (GQLField operation) =>
60
+ _extractFields (operation).map (_encodeField ).join (' ' );
67
61
68
62
String _encodeOperationInlineFragments (GQLField operation) =>
69
63
_extractFragments (operation).map (_encodeInlineFragment).join (' ' );
@@ -72,24 +66,27 @@ class GQLEncoder extends Converter<GQLOperation, String> {
72
66
_extractNestedFragments (operation).map (_encodeFragment).join ('\n ' );
73
67
74
68
String _encodeFragment (GQLFragment fragment) {
75
- final rootResolver = _encodeOperationResolvers (fragment);
69
+ final rootField = _encodeOperationFields (fragment);
76
70
final fragmentsGQL = _encodeNestedOperationFragments (fragment);
77
71
78
- return 'fragment ${fragment .name } on ${fragment .onType } { $rootResolver }${fragmentsGQL .isNotEmpty ? fragmentsGQL : '' }' ;
72
+ return 'fragment ${fragment .name } on ${fragment .onType } { $rootField }${fragmentsGQL .isNotEmpty ? fragmentsGQL : '' }' ;
79
73
}
80
74
81
- String _encodeResolver (GQLField operation) {
82
- final childrenGQL = _encodeOperationResolvers (operation);
75
+ String _encodeField (GQLField operation) {
76
+ final childrenGQL = _encodeOperationFields (operation);
83
77
final childrenFragment = _encodeOperationInlineFragments (operation);
84
78
85
79
final alias = (operation is Alias ) ? '${operation .alias }: ' : '' ;
86
80
final name = operation.name != null ? '${operation .name } ' : '' ;
87
81
final args = (operation is Arguments ) ? '(${operation .args }) ' : '' ;
82
+ final directive = (operation is Directives )
83
+ ? '@${operation .directive }(if: ${operation .directiveValue }) '
84
+ : '' ;
88
85
final fields = (childrenGQL.isNotEmpty || childrenFragment.isNotEmpty)
89
86
? '{ $childrenGQL $childrenFragment }'
90
87
: '' ;
91
88
92
- return '$alias $name $args $fields ' ;
89
+ return '$alias $name $args $directive $ fields ' ;
93
90
}
94
91
95
92
String _encodeInlineFragment (GQLFragment fragment) => '...${fragment .name }' ;
0 commit comments