Skip to content

Commit 0b7590f

Browse files
authored
Add support for @OneOf directives in printSchema (#3969)
fixes #3968
1 parent e081838 commit 0b7590f

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
@@ -509,6 +509,23 @@ describe('Type System Printer', () => {
509509
`);
510510
});
511511

512+
it('Print Input Type with @oneOf directive', () => {
513+
const InputType = new GraphQLInputObjectType({
514+
name: 'InputType',
515+
isOneOf: true,
516+
fields: {
517+
int: { type: GraphQLInt },
518+
},
519+
});
520+
521+
const schema = new GraphQLSchema({ types: [InputType] });
522+
expectPrintedSchema(schema).to.equal(dedent`
523+
input InputType @oneOf {
524+
int: Int
525+
}
526+
`);
527+
});
528+
512529
it('Custom Scalar', () => {
513530
const OddType = new GraphQLScalarType({ name: 'Odd' });
514531

src/utilities/printSchema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ function printInputObject(type: GraphQLInputObjectType): string {
204204
const fields = Object.values(type.getFields()).map(
205205
(f, i) => printDescription(f, ' ', !i) + ' ' + printInputValue(f),
206206
);
207-
return printDescription(type) + `input ${type.name}` + printBlock(fields);
207+
return (
208+
printDescription(type) +
209+
`input ${type.name}` +
210+
(type.isOneOf ? ' @oneOf' : '') +
211+
printBlock(fields)
212+
);
208213
}
209214

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

0 commit comments

Comments
 (0)