Skip to content

Commit 43b7645

Browse files
committed
Allow empty string as valid 'deprecationReason' (#2167)
1 parent 1756a2f commit 43b7645

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

src/type/__tests__/definition-test.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,23 @@ describe('Type System: Objects', () => {
183183
type: ScalarType,
184184
deprecationReason: 'A terrible reason',
185185
},
186+
baz: {
187+
type: ScalarType,
188+
deprecationReason: '',
189+
},
186190
},
187191
});
188192

189-
expect(TypeWithDeprecatedField.getFields().bar).to.deep.equal({
193+
expect(TypeWithDeprecatedField.getFields().bar).to.include({
190194
name: 'bar',
191-
description: undefined,
192-
type: ScalarType,
193-
args: [],
194-
resolve: undefined,
195-
subscribe: undefined,
196195
isDeprecated: true,
197196
deprecationReason: 'A terrible reason',
198-
extensions: undefined,
199-
astNode: undefined,
197+
});
198+
199+
expect(TypeWithDeprecatedField.getFields().baz).to.include({
200+
name: 'baz',
201+
isDeprecated: true,
202+
deprecationReason: '',
200203
});
201204
});
202205

@@ -519,17 +522,22 @@ describe('Type System: Enums', () => {
519522
it('defines an enum type with deprecated value', () => {
520523
const EnumTypeWithDeprecatedValue = new GraphQLEnumType({
521524
name: 'EnumWithDeprecatedValue',
522-
values: { foo: { deprecationReason: 'Just because' } },
525+
values: {
526+
foo: { deprecationReason: 'Just because' },
527+
bar: { deprecationReason: '' },
528+
},
523529
});
524530

525-
expect(EnumTypeWithDeprecatedValue.getValues()[0]).to.deep.equal({
531+
expect(EnumTypeWithDeprecatedValue.getValues()[0]).to.include({
526532
name: 'foo',
527-
description: undefined,
528533
isDeprecated: true,
529534
deprecationReason: 'Just because',
530-
value: 'foo',
531-
extensions: undefined,
532-
astNode: undefined,
535+
});
536+
537+
expect(EnumTypeWithDeprecatedValue.getValues()[1]).to.include({
538+
name: 'bar',
539+
isDeprecated: true,
540+
deprecationReason: '',
533541
});
534542
});
535543

src/type/definition.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ function defineFieldMap<TSource, TContext>(
797797
args,
798798
resolve: fieldConfig.resolve,
799799
subscribe: fieldConfig.subscribe,
800-
isDeprecated: Boolean(fieldConfig.deprecationReason),
800+
isDeprecated: fieldConfig.deprecationReason != null,
801801
deprecationReason: fieldConfig.deprecationReason,
802802
extensions: fieldConfig.extensions && toObjMap(fieldConfig.extensions),
803803
astNode: fieldConfig.astNode,
@@ -1291,7 +1291,7 @@ function defineEnumValues(
12911291
name: valueName,
12921292
description: valueConfig.description,
12931293
value: valueConfig.value !== undefined ? valueConfig.value : valueName,
1294-
isDeprecated: Boolean(valueConfig.deprecationReason),
1294+
isDeprecated: valueConfig.deprecationReason != null,
12951295
deprecationReason: valueConfig.deprecationReason,
12961296
extensions: valueConfig.extensions && toObjMap(valueConfig.extensions),
12971297
astNode: valueConfig.astNode,

src/utilities/__tests__/buildClientSchema-test.js

+14
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,20 @@ describe('Type System: build schema from introspection', () => {
509509
expect(cycleIntrospection(sdl)).to.equal(sdl);
510510
});
511511

512+
it('builds a schema with empty deprecation reasons', () => {
513+
const sdl = dedent`
514+
type Query {
515+
someField: String @deprecated(reason: "")
516+
}
517+
518+
enum SomeEnum {
519+
SOME_VALUE @deprecated(reason: "")
520+
}
521+
`;
522+
523+
expect(cycleIntrospection(sdl)).to.equal(sdl);
524+
});
525+
512526
it('can use client schema for limited execution', () => {
513527
const schema = buildSchema(`
514528
scalar CustomScalar

src/utilities/schemaPrinter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function printDeprecated(fieldOrEnumVal) {
305305
}
306306
const reason = fieldOrEnumVal.deprecationReason;
307307
const reasonAST = astFromValue(reason, GraphQLString);
308-
if (reasonAST && reason !== '' && reason !== DEFAULT_DEPRECATION_REASON) {
308+
if (reasonAST && reason !== DEFAULT_DEPRECATION_REASON) {
309309
return ' @deprecated(reason: ' + print(reasonAST) + ')';
310310
}
311311
return ' @deprecated';

0 commit comments

Comments
 (0)