Skip to content

Commit f180b57

Browse files
committed
Merge branch 'ConnorWhite-master'
2 parents 91cd8e5 + a319771 commit f180b57

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/__tests__/fragments.tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,17 @@ describe('jsonToGraphQLQuery() - fragments', () => {
5858
);
5959
});
6060

61+
it('supports full inline fragments', () => {
62+
const query = {
63+
query: {
64+
Posts: {
65+
__on: 'ConfigurablePost'
66+
}
67+
}
68+
};
69+
expect(jsonToGraphQLQuery(query)).to.equal(
70+
'query { Posts { ... ConfigurablePost } }'
71+
);
72+
});
73+
6174
});

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: [string, number][], opti
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: [string, number][], opti
135135
convertQuery(value, level + 1, output, options);
136136

137137
if (inlineFragmentsExist) {
138+
if (typeof value.__on === 'object') {
138139
const inlineFragments: { __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: [string, number][], opti
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)