Skip to content

Commit 2fb0662

Browse files
committed
Add support for @OneOf directives in printSchema
1 parent 8d7c8fc commit 2fb0662

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/utilities/__tests__/printSchema-test.ts

Lines changed: 18 additions & 1 deletion
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

@@ -663,7 +680,7 @@ describe('Type System Printer', () => {
663680
schema {
664681
query: Query
665682
}
666-
683+
667684
""""""
668685
directive @someDirective(
669686
""""""

src/utilities/printSchema.ts

Lines changed: 14 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+
printOneOf(type.isOneOf) +
211+
printBlock(fields)
212+
);
208213
}
209214

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

295+
function printOneOf(isOneOf: boolean): string {
296+
if (!isOneOf) {
297+
return '';
298+
}
299+
300+
return ' @oneOf';
301+
}
302+
290303
function printSpecifiedByURL(scalar: GraphQLScalarType): string {
291304
if (scalar.specifiedByURL == null) {
292305
return '';

0 commit comments

Comments
 (0)