Skip to content

Commit 26fa120

Browse files
committed
Allow full inline fragments
(ex: ... Fragment rather than ... on Fragment { field })
1 parent 50ecfae commit 26fa120

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/jsonToGraphQLQuery.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function convertQuery(node: any, level: number, output: Array<[string, number]>,
9595
const subFields = fieldCount > 0;
9696
const argsExist = typeof value.__args === 'object';
9797
const directivesExist = typeof value.__directives === 'object';
98-
const inlineFragmentsExist = typeof value.__on === 'object';
98+
const inlineFragmentsExist = typeof value.__on === 'object' || typeof value.__on === 'string';
9999

100100
let token = `${key}`;
101101

@@ -135,6 +135,7 @@ function convertQuery(node: any, level: number, output: Array<[string, number]>,
135135
convertQuery(value, level + 1, output, options);
136136

137137
if (inlineFragmentsExist) {
138+
if (typeof value.__on === 'object') {
138139
const inlineFragments: Array<{ __typeName: string }>
139140
= value.__on instanceof Array ? value.__on : [value.__on];
140141
inlineFragments.forEach((inlineFragment) => {
@@ -143,6 +144,10 @@ function convertQuery(node: any, level: number, output: Array<[string, number]>,
143144
convertQuery(inlineFragment, level + 2, output, options);
144145
output.push(['}', level + 1]);
145146
});
147+
} else if (typeof value.__on === 'string') {
148+
const inlineFragment: string = value.__on;
149+
output.push([`... ${inlineFragment}`, level + 1]);
150+
}
146151
}
147152

148153
if (subFields || inlineFragmentsExist) {

0 commit comments

Comments
 (0)