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 Nov 10, 2023
1 parent e081838 commit 0b7590f
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 @@ -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
7 changes: 6 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}` +
(type.isOneOf ? ' @oneOf' : '') +
printBlock(fields)
);
}

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

0 comments on commit 0b7590f

Please sign in to comment.