Skip to content

Commit 5fd46be

Browse files
maciesielkabenjie
authored andcommitted
Add @oneOf support to introspection query (#4078)
1 parent 06e93b1 commit 5fd46be

5 files changed

+35
-0
lines changed

src/utilities/__tests__/buildClientSchema-test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,21 @@ describe('Type System: build schema from introspection', () => {
573573
expect(cycleIntrospection(sdl)).to.equal(sdl);
574574
});
575575

576+
it('builds a schema with @oneOf directive', () => {
577+
const sdl = dedent`
578+
type Query {
579+
someField(someArg: SomeInputObject): String
580+
}
581+
582+
input SomeInputObject @oneOf {
583+
someInputField1: String
584+
someInputField2: String
585+
}
586+
`;
587+
588+
expect(cycleIntrospection(sdl)).to.equal(sdl);
589+
});
590+
576591
it('can use client schema for limited execution', () => {
577592
const schema = buildSchema(`
578593
scalar CustomScalar

src/utilities/__tests__/getIntrospectionQuery-test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ describe('getIntrospectionQuery', () => {
117117
);
118118
});
119119

120+
it('include "isOneOf" field on input objects', () => {
121+
expectIntrospectionQuery().toNotMatch('isOneOf');
122+
123+
expectIntrospectionQuery({ inputObjectOneOf: true }).toMatch('isOneOf', 1);
124+
125+
expectIntrospectionQuery({ inputObjectOneOf: false }).toNotMatch('isOneOf');
126+
});
127+
120128
it('include deprecated input field and args', () => {
121129
expectIntrospectionQuery().toMatch('includeDeprecated: true', 2);
122130

src/utilities/buildClientSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export function buildClientSchema(
304304
name: inputObjectIntrospection.name,
305305
description: inputObjectIntrospection.description,
306306
fields: () => buildInputValueDefMap(inputObjectIntrospection.inputFields),
307+
isOneOf: inputObjectIntrospection.isOneOf,
307308
});
308309
}
309310

src/utilities/getIntrospectionQuery.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export interface IntrospectionOptions {
3232
* Default: false
3333
*/
3434
inputValueDeprecation?: boolean;
35+
36+
/**
37+
* Whether target GraphQL server supports `@oneOf` input objects.
38+
* Default: false
39+
*/
40+
inputObjectOneOf?: boolean;
3541
}
3642

3743
/**
@@ -45,6 +51,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
4551
directiveIsRepeatable: false,
4652
schemaDescription: false,
4753
inputValueDeprecation: false,
54+
inputObjectOneOf: false,
4855
...options,
4956
};
5057

@@ -62,6 +69,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
6269
function inputDeprecation(str: string) {
6370
return optionsWithDefault.inputValueDeprecation ? str : '';
6471
}
72+
const inputObjectOneOf = optionsWithDefault.inputObjectOneOf ? 'isOneOf' : '';
6573

6674
return `
6775
query IntrospectionQuery {
@@ -90,6 +98,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
9098
name
9199
${descriptions}
92100
${specifiedByUrl}
101+
${inputObjectOneOf}
93102
fields(includeDeprecated: true) {
94103
name
95104
${descriptions}
@@ -259,6 +268,7 @@ export interface IntrospectionInputObjectType {
259268
readonly name: string;
260269
readonly description?: Maybe<string>;
261270
readonly inputFields: ReadonlyArray<IntrospectionInputValue>;
271+
readonly isOneOf: boolean;
262272
}
263273

264274
export interface IntrospectionListTypeRef<

src/utilities/introspectionFromSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function introspectionFromSchema(
3030
directiveIsRepeatable: true,
3131
schemaDescription: true,
3232
inputValueDeprecation: true,
33+
inputObjectOneOf: true,
3334
...options,
3435
};
3536

0 commit comments

Comments
 (0)