Skip to content

Commit

Permalink
Add support for @OneOf directives in printSchema (#3969)
Browse files Browse the repository at this point in the history
fixes #3968
  • Loading branch information
hayes authored and benjie committed Jun 21, 2024
1 parent c67dc4d commit 06e93b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/utilities/__tests__/printSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,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
7 changes: 6 additions & 1 deletion src/utilities/printSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,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}` +
(type.isOneOf ? ' @oneOf' : '') +
printBlock(fields)
);
}

function printFields(type: GraphQLObjectType | GraphQLInterfaceType): string {
Expand Down

0 comments on commit 06e93b1

Please sign in to comment.