Skip to content

Commit

Permalink
Allow empty string as valid 'deprecationReason' (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 15, 2019
1 parent 1756a2f commit 43b7645
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
36 changes: 22 additions & 14 deletions src/type/__tests__/definition-test.js
Expand Up @@ -183,20 +183,23 @@ describe('Type System: Objects', () => {
type: ScalarType,
deprecationReason: 'A terrible reason',
},
baz: {
type: ScalarType,
deprecationReason: '',
},
},
});

expect(TypeWithDeprecatedField.getFields().bar).to.deep.equal({
expect(TypeWithDeprecatedField.getFields().bar).to.include({
name: 'bar',
description: undefined,
type: ScalarType,
args: [],
resolve: undefined,
subscribe: undefined,
isDeprecated: true,
deprecationReason: 'A terrible reason',
extensions: undefined,
astNode: undefined,
});

expect(TypeWithDeprecatedField.getFields().baz).to.include({
name: 'baz',
isDeprecated: true,
deprecationReason: '',
});
});

Expand Down Expand Up @@ -519,17 +522,22 @@ describe('Type System: Enums', () => {
it('defines an enum type with deprecated value', () => {
const EnumTypeWithDeprecatedValue = new GraphQLEnumType({
name: 'EnumWithDeprecatedValue',
values: { foo: { deprecationReason: 'Just because' } },
values: {
foo: { deprecationReason: 'Just because' },
bar: { deprecationReason: '' },
},
});

expect(EnumTypeWithDeprecatedValue.getValues()[0]).to.deep.equal({
expect(EnumTypeWithDeprecatedValue.getValues()[0]).to.include({
name: 'foo',
description: undefined,
isDeprecated: true,
deprecationReason: 'Just because',
value: 'foo',
extensions: undefined,
astNode: undefined,
});

expect(EnumTypeWithDeprecatedValue.getValues()[1]).to.include({
name: 'bar',
isDeprecated: true,
deprecationReason: '',
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/type/definition.js
Expand Up @@ -797,7 +797,7 @@ function defineFieldMap<TSource, TContext>(
args,
resolve: fieldConfig.resolve,
subscribe: fieldConfig.subscribe,
isDeprecated: Boolean(fieldConfig.deprecationReason),
isDeprecated: fieldConfig.deprecationReason != null,
deprecationReason: fieldConfig.deprecationReason,
extensions: fieldConfig.extensions && toObjMap(fieldConfig.extensions),
astNode: fieldConfig.astNode,
Expand Down Expand Up @@ -1291,7 +1291,7 @@ function defineEnumValues(
name: valueName,
description: valueConfig.description,
value: valueConfig.value !== undefined ? valueConfig.value : valueName,
isDeprecated: Boolean(valueConfig.deprecationReason),
isDeprecated: valueConfig.deprecationReason != null,
deprecationReason: valueConfig.deprecationReason,
extensions: valueConfig.extensions && toObjMap(valueConfig.extensions),
astNode: valueConfig.astNode,
Expand Down
14 changes: 14 additions & 0 deletions src/utilities/__tests__/buildClientSchema-test.js
Expand Up @@ -509,6 +509,20 @@ describe('Type System: build schema from introspection', () => {
expect(cycleIntrospection(sdl)).to.equal(sdl);
});

it('builds a schema with empty deprecation reasons', () => {
const sdl = dedent`
type Query {
someField: String @deprecated(reason: "")
}
enum SomeEnum {
SOME_VALUE @deprecated(reason: "")
}
`;

expect(cycleIntrospection(sdl)).to.equal(sdl);
});

it('can use client schema for limited execution', () => {
const schema = buildSchema(`
scalar CustomScalar
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/schemaPrinter.js
Expand Up @@ -305,7 +305,7 @@ function printDeprecated(fieldOrEnumVal) {
}
const reason = fieldOrEnumVal.deprecationReason;
const reasonAST = astFromValue(reason, GraphQLString);
if (reasonAST && reason !== '' && reason !== DEFAULT_DEPRECATION_REASON) {
if (reasonAST && reason !== DEFAULT_DEPRECATION_REASON) {
return ' @deprecated(reason: ' + print(reasonAST) + ')';
}
return ' @deprecated';
Expand Down

0 comments on commit 43b7645

Please sign in to comment.