Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @oneOf support to introspection query #4078

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/utilities/__tests__/buildClientSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,21 @@ describe('Type System: build schema from introspection', () => {
expect(cycleIntrospection(sdl)).to.equal(sdl);
});

it('builds a schema with @oneOf directive', () => {
const sdl = dedent`
type Query {
someField(someArg: SomeInputObject): String
}
input SomeInputObject @oneOf {
someInputField1: String
someInputField2: String
}
`;

expect(cycleIntrospection(sdl)).to.equal(sdl);
});

it('can use client schema for limited execution', () => {
const schema = buildSchema(`
scalar CustomScalar
Expand Down
8 changes: 8 additions & 0 deletions src/utilities/__tests__/getIntrospectionQuery-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ describe('getIntrospectionQuery', () => {
);
});

it('include "isOneOf" field on input objects', () => {
expectIntrospectionQuery().toNotMatch('isOneOf');

expectIntrospectionQuery({ inputObjectOneOf: true }).toMatch('isOneOf', 1);

expectIntrospectionQuery({ inputObjectOneOf: false }).toNotMatch('isOneOf');
});

it('include deprecated input field and args', () => {
expectIntrospectionQuery().toMatch('includeDeprecated: true', 2);

Expand Down
1 change: 1 addition & 0 deletions src/utilities/buildClientSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export function buildClientSchema(
name: inputObjectIntrospection.name,
description: inputObjectIntrospection.description,
fields: () => buildInputValueDefMap(inputObjectIntrospection.inputFields),
isOneOf: inputObjectIntrospection.isOneOf,
});
}

Expand Down
10 changes: 10 additions & 0 deletions src/utilities/getIntrospectionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export interface IntrospectionOptions {
* Default: false
*/
inputValueDeprecation?: boolean;

/**
* Whether target GraphQL server supports `@oneOf` input objects.
* Default: false
*/
inputObjectOneOf?: boolean;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed the pattern above for making this configurable, but wasn't sure if that was necessary.

}

/**
Expand All @@ -45,6 +51,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
directiveIsRepeatable: false,
schemaDescription: false,
inputValueDeprecation: false,
inputObjectOneOf: false,
...options,
};

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

return `
query IntrospectionQuery {
Expand Down Expand Up @@ -90,6 +98,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
name
${descriptions}
${specifiedByUrl}
${inputObjectOneOf}
fields(includeDeprecated: true) {
name
${descriptions}
Expand Down Expand Up @@ -259,6 +268,7 @@ export interface IntrospectionInputObjectType {
readonly name: string;
readonly description?: Maybe<string>;
readonly inputFields: ReadonlyArray<IntrospectionInputValue>;
readonly isOneOf: boolean;
}

export interface IntrospectionListTypeRef<
Expand Down
1 change: 1 addition & 0 deletions src/utilities/introspectionFromSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function introspectionFromSchema(
directiveIsRepeatable: true,
schemaDescription: true,
inputValueDeprecation: true,
inputObjectOneOf: true,
...options,
};

Expand Down