From 4c544cd3001a4ebb705f3c3d3c78d3f789cff068 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Sat, 9 Sep 2023 19:15:18 -0700 Subject: [PATCH] Add support for @oneOf directives in printSchema --- src/utilities/__tests__/printSchema-test.ts | 17 +++++++++++++++++ src/utilities/printSchema.ts | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/utilities/__tests__/printSchema-test.ts b/src/utilities/__tests__/printSchema-test.ts index 5b7116648a..78f793b183 100644 --- a/src/utilities/__tests__/printSchema-test.ts +++ b/src/utilities/__tests__/printSchema-test.ts @@ -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' }); diff --git a/src/utilities/printSchema.ts b/src/utilities/printSchema.ts index c987f64ae1..c4caffc616 100644 --- a/src/utilities/printSchema.ts +++ b/src/utilities/printSchema.ts @@ -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 {