Skip to content

Commit c2c95c1

Browse files
committed
Add @oneOf support to introspection query
1 parent d811c97 commit c2c95c1

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

src/utilities/__tests__/buildClientSchema-test.ts

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

574+
it('builds a schema with @oneOf directive', () => {
575+
const sdl = dedent`
576+
type Query {
577+
someField(someArg: SomeInputObject): String
578+
}
579+
580+
input SomeInputObject @oneOf {
581+
someInputField1: String
582+
someInputField2: String
583+
}
584+
`;
585+
586+
expect(cycleIntrospection(sdl)).to.equal(sdl);
587+
});
588+
574589
it('can use client schema for limited execution', () => {
575590
const schema = buildSchema(`
576591
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
@@ -311,6 +311,7 @@ export function buildClientSchema(
311311
name: inputObjectIntrospection.name,
312312
description: inputObjectIntrospection.description,
313313
fields: () => buildInputValueDefMap(inputObjectIntrospection.inputFields),
314+
isOneOf: inputObjectIntrospection.isOneOf,
314315
});
315316
}
316317

src/utilities/getIntrospectionQuery.ts

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

3741
/**
@@ -45,6 +49,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
4549
directiveIsRepeatable: false,
4650
schemaDescription: false,
4751
inputValueDeprecation: false,
52+
inputValueOneOf: false,
4853
...options,
4954
};
5055

@@ -62,6 +67,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
6267
function inputDeprecation(str: string) {
6368
return optionsWithDefault.inputValueDeprecation ? str : '';
6469
}
70+
const inputValueOneOf = optionsWithDefault.inputValueOneOf ? 'isOneOf' : '';
6571

6672
return `
6773
query IntrospectionQuery {
@@ -90,6 +96,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
9096
name
9197
${descriptions}
9298
${specifiedByUrl}
99+
${inputValueOneOf}
93100
fields(includeDeprecated: true) {
94101
name
95102
${descriptions}
@@ -223,6 +230,7 @@ export interface IntrospectionObjectType {
223230
readonly interfaces: ReadonlyArray<
224231
IntrospectionNamedTypeRef<IntrospectionInterfaceType>
225232
>;
233+
readonly isOneOf: boolean;
226234
}
227235

228236
export interface IntrospectionInterfaceType {
@@ -259,6 +267,7 @@ export interface IntrospectionInputObjectType {
259267
readonly name: string;
260268
readonly description?: Maybe<string>;
261269
readonly inputFields: ReadonlyArray<IntrospectionInputValue>;
270+
readonly isOneOf: boolean;
262271
}
263272

264273
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)