|
1 | 1 | import { EnumType } from './types/EnumType';
|
2 | 2 | import { VariableType } from './types/VariableType';
|
3 | 3 |
|
4 |
| -export const configFields = ['__args', '__alias', '__aliasFor', '__variables', '__directives']; |
| 4 | +export const configFields = ['__args', '__alias', '__aliasFor', '__variables', '__directives', '__on', '__fragmentName']; |
5 | 5 |
|
6 | 6 | function stringify(obj_from_json: any): string {
|
7 | 7 | if (obj_from_json instanceof EnumType) {
|
@@ -86,6 +86,7 @@ function convertQuery(node: any, level: number, output: Array<[ string, number ]
|
86 | 86 | const subFields = fieldCount > 0;
|
87 | 87 | const argsExist = typeof node[key].__args === 'object';
|
88 | 88 | const directivesExist = typeof node[key].__directives === 'object';
|
| 89 | + const inlineFragmentsExist = typeof node[key].__on === 'object'; |
89 | 90 |
|
90 | 91 | let token = `${key}`;
|
91 | 92 |
|
@@ -121,10 +122,19 @@ function convertQuery(node: any, level: number, output: Array<[ string, number ]
|
121 | 122 | token = `${node[key].__alias}: ${token}`;
|
122 | 123 | }
|
123 | 124 |
|
124 |
| - output.push([ token + (fieldCount > 0 ? ' {' : ''), level ]); |
| 125 | + output.push([ token + (subFields || inlineFragmentsExist ? ' {' : ''), level ]); |
125 | 126 | convertQuery(node[key], level + 1, output, options);
|
126 | 127 |
|
127 |
| - if (subFields) { |
| 128 | + if (inlineFragmentsExist) { |
| 129 | + let inlineFragment = node[key].__on; |
| 130 | + if (inlineFragment && inlineFragment.__fragmentName) { |
| 131 | + output.push([`... on ${inlineFragment.__fragmentName} {`, level + 1]); |
| 132 | + convertQuery(inlineFragment, level + 2, output, options); |
| 133 | + output.push([ '}', level + 1 ]); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + if (subFields || inlineFragmentsExist) { |
128 | 138 | output.push([ '}', level ]);
|
129 | 139 | }
|
130 | 140 |
|
|
0 commit comments