Skip to content

Commit

Permalink
Add support for @OneOf directives in printSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Sep 10, 2023
1 parent 8d7c8fc commit 2fb0662
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/utilities/__tests__/printSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,23 @@ describe('Type System Printer', () => {
`);
});

it('Print Input Type with @oneOf directive', () => {
const InputType = new GraphQLInputObjectType({
name: 'InputType',
isOneOf: true,
fields: {
int: { type: GraphQLInt },
},
});

const schema = new GraphQLSchema({ types: [InputType] });
expectPrintedSchema(schema).to.equal(dedent`
input InputType @oneOf {
int: Int
}
`);
});

it('Custom Scalar', () => {
const OddType = new GraphQLScalarType({ name: 'Odd' });

Expand Down Expand Up @@ -663,7 +680,7 @@ describe('Type System Printer', () => {
schema {
query: Query
}
""""""
directive @someDirective(
""""""
Expand Down
15 changes: 14 additions & 1 deletion src/utilities/printSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ function printInputObject(type: GraphQLInputObjectType): string {
const fields = Object.values(type.getFields()).map(
(f, i) => printDescription(f, ' ', !i) + ' ' + printInputValue(f),
);
return printDescription(type) + `input ${type.name}` + printBlock(fields);
return (
printDescription(type) +
`input ${type.name}` +
printOneOf(type.isOneOf) +
printBlock(fields)
);
}

function printFields(type: GraphQLObjectType | GraphQLInterfaceType): string {
Expand Down Expand Up @@ -287,6 +292,14 @@ function printDeprecated(reason: Maybe<string>): string {
return ' @deprecated';
}

function printOneOf(isOneOf: boolean): string {
if (!isOneOf) {
return '';
}

return ' @oneOf';
}

function printSpecifiedByURL(scalar: GraphQLScalarType): string {
if (scalar.specifiedByURL == null) {
return '';
Expand Down

0 comments on commit 2fb0662

Please sign in to comment.