Skip to content

Commit 06e93b1

Browse files
hayesbenjie
authored andcommitted
Add support for @OneOf directives in printSchema (#3969)
fixes #3968
1 parent c67dc4d commit 06e93b1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/utilities/__tests__/printSchema-test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,23 @@ describe('Type System Printer', () => {
503503
`);
504504
});
505505

506+
it('Print Input Type with @oneOf directive', () => {
507+
const InputType = new GraphQLInputObjectType({
508+
name: 'InputType',
509+
isOneOf: true,
510+
fields: {
511+
int: { type: GraphQLInt },
512+
},
513+
});
514+
515+
const schema = new GraphQLSchema({ types: [InputType] });
516+
expectPrintedSchema(schema).to.equal(dedent`
517+
input InputType @oneOf {
518+
int: Int
519+
}
520+
`);
521+
});
522+
506523
it('Custom Scalar', () => {
507524
const OddType = new GraphQLScalarType({ name: 'Odd' });
508525

src/utilities/printSchema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ function printInputObject(type: GraphQLInputObjectType): string {
209209
const fields = Object.values(type.getFields()).map(
210210
(f, i) => printDescription(f, ' ', !i) + ' ' + printInputValue(f),
211211
);
212-
return printDescription(type) + `input ${type.name}` + printBlock(fields);
212+
return (
213+
printDescription(type) +
214+
`input ${type.name}` +
215+
(type.isOneOf ? ' @oneOf' : '') +
216+
printBlock(fields)
217+
);
213218
}
214219

215220
function printFields(type: GraphQLObjectType | GraphQLInterfaceType): string {

0 commit comments

Comments
 (0)