Skip to content

Allow empty string as valid 'deprecationReason' #2167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/type/__tests__/definition-test.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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