diff --git a/src/utilities/__tests__/buildClientSchema-test.ts b/src/utilities/__tests__/buildClientSchema-test.ts index 818198bf7b..43bba63d8f 100644 --- a/src/utilities/__tests__/buildClientSchema-test.ts +++ b/src/utilities/__tests__/buildClientSchema-test.ts @@ -382,7 +382,7 @@ describe('Type System: build schema from introspection', () => { name: 'VEGETABLES', description: 'Foods that are vegetables.', value: 'VEGETABLES', - deprecationReason: null, + deprecationReason: undefined, extensions: {}, astNode: undefined, }, @@ -390,7 +390,7 @@ describe('Type System: build schema from introspection', () => { name: 'FRUITS', description: null, value: 'FRUITS', - deprecationReason: null, + deprecationReason: undefined, extensions: {}, astNode: undefined, }, diff --git a/src/utilities/__tests__/printSchema-test.ts b/src/utilities/__tests__/printSchema-test.ts index 78f793b183..94c213a4bb 100644 --- a/src/utilities/__tests__/printSchema-test.ts +++ b/src/utilities/__tests__/printSchema-test.ts @@ -591,6 +591,15 @@ describe('Type System Printer', () => { `); }); + it('Prints deprecated directives with explicitly `null` reason', () => { + const SDL = dedent` + type Query { + someField: String @deprecated(reason: null) + }`; + const schema = buildSchema(SDL); + expectPrintedSchema(schema).to.equal(SDL); + }); + it('Prints custom directives', () => { const SimpleDirective = new GraphQLDirective({ name: 'simpleDirective', diff --git a/src/utilities/buildClientSchema.ts b/src/utilities/buildClientSchema.ts index ab50728554..bd5b10d630 100644 --- a/src/utilities/buildClientSchema.ts +++ b/src/utilities/buildClientSchema.ts @@ -292,7 +292,9 @@ export function buildClientSchema( (valueIntrospection) => valueIntrospection.name, (valueIntrospection) => ({ description: valueIntrospection.description, - deprecationReason: valueIntrospection.deprecationReason, + deprecationReason: valueIntrospection.isDeprecated + ? valueIntrospection.deprecationReason + : undefined, }), ), }); @@ -350,7 +352,9 @@ export function buildClientSchema( return { description: fieldIntrospection.description, - deprecationReason: fieldIntrospection.deprecationReason, + deprecationReason: fieldIntrospection.isDeprecated + ? fieldIntrospection.deprecationReason + : undefined, type, args: buildInputValueDefMap(fieldIntrospection.args), }; @@ -383,7 +387,9 @@ export function buildClientSchema( description: inputValueIntrospection.description, type, defaultValue, - deprecationReason: inputValueIntrospection.deprecationReason, + deprecationReason: inputValueIntrospection.isDeprecated + ? inputValueIntrospection.deprecationReason + : undefined, }; } diff --git a/src/utilities/printSchema.ts b/src/utilities/printSchema.ts index c4caffc616..d130a86516 100644 --- a/src/utilities/printSchema.ts +++ b/src/utilities/printSchema.ts @@ -282,11 +282,15 @@ export function printDirective(directive: GraphQLDirective): string { } function printDeprecated(reason: Maybe): string { - if (reason == null) { + if (reason === undefined) { return ''; } if (reason !== DEFAULT_DEPRECATION_REASON) { - const astValue = print({ kind: Kind.STRING, value: reason }); + const astValue = print( + reason === null + ? { kind: Kind.NULL } + : { kind: Kind.STRING, value: reason }, + ); return ` @deprecated(reason: ${astValue})`; } return ' @deprecated';