Skip to content

Commit eccf27d

Browse files
committed
Preserve @deprecated when reason = null
1 parent 2aedf25 commit eccf27d

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/utilities/__tests__/buildClientSchema-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,15 @@ describe('Type System: build schema from introspection', () => {
382382
name: 'VEGETABLES',
383383
description: 'Foods that are vegetables.',
384384
value: 'VEGETABLES',
385-
deprecationReason: null,
385+
deprecationReason: undefined,
386386
extensions: {},
387387
astNode: undefined,
388388
},
389389
{
390390
name: 'FRUITS',
391391
description: null,
392392
value: 'FRUITS',
393-
deprecationReason: null,
393+
deprecationReason: undefined,
394394
extensions: {},
395395
astNode: undefined,
396396
},

src/utilities/__tests__/printSchema-test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,15 @@ describe('Type System Printer', () => {
591591
`);
592592
});
593593

594+
it('Prints deprecated directives with explicitly `null` reason', () => {
595+
const SDL = dedent`
596+
type Query {
597+
someField: String @deprecated(reason: null)
598+
}`;
599+
const schema = buildSchema(SDL);
600+
expectPrintedSchema(schema).to.equal(SDL);
601+
});
602+
594603
it('Prints custom directives', () => {
595604
const SimpleDirective = new GraphQLDirective({
596605
name: 'simpleDirective',

src/utilities/buildClientSchema.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ export function buildClientSchema(
292292
(valueIntrospection) => valueIntrospection.name,
293293
(valueIntrospection) => ({
294294
description: valueIntrospection.description,
295-
deprecationReason: valueIntrospection.deprecationReason,
295+
deprecationReason: valueIntrospection.isDeprecated
296+
? valueIntrospection.deprecationReason
297+
: undefined,
296298
}),
297299
),
298300
});
@@ -350,7 +352,9 @@ export function buildClientSchema(
350352

351353
return {
352354
description: fieldIntrospection.description,
353-
deprecationReason: fieldIntrospection.deprecationReason,
355+
deprecationReason: fieldIntrospection.isDeprecated
356+
? fieldIntrospection.deprecationReason
357+
: undefined,
354358
type,
355359
args: buildInputValueDefMap(fieldIntrospection.args),
356360
};
@@ -383,7 +387,9 @@ export function buildClientSchema(
383387
description: inputValueIntrospection.description,
384388
type,
385389
defaultValue,
386-
deprecationReason: inputValueIntrospection.deprecationReason,
390+
deprecationReason: inputValueIntrospection.isDeprecated
391+
? inputValueIntrospection.deprecationReason
392+
: undefined,
387393
};
388394
}
389395

src/utilities/printSchema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,15 @@ export function printDirective(directive: GraphQLDirective): string {
282282
}
283283

284284
function printDeprecated(reason: Maybe<string>): string {
285-
if (reason == null) {
285+
if (reason === undefined) {
286286
return '';
287287
}
288288
if (reason !== DEFAULT_DEPRECATION_REASON) {
289-
const astValue = print({ kind: Kind.STRING, value: reason });
289+
const astValue = print(
290+
reason === null
291+
? { kind: Kind.NULL }
292+
: { kind: Kind.STRING, value: reason },
293+
);
290294
return ` @deprecated(reason: ${astValue})`;
291295
}
292296
return ' @deprecated';

0 commit comments

Comments
 (0)