Skip to content
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

fix: Permit isDeprecated field in presence of deprecationReason #2684

Closed
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
29 changes: 29 additions & 0 deletions src/type/__tests__/definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ describe('Type System: Objects', () => {
);
});

it('allows an Object type with an isDeprecated field if a deprecationReason field is present', () => {
const OldObject = new GraphQLObjectType({
name: 'OldObject',
// $DisableFlowOnNegativeTest
fields: {
field: {
type: ScalarType,
isDeprecated: false,
deprecationReason: undefined,
},
},
});

expect(() => OldObject.getFields()).not.to.throw();
});

it('rejects an Object type with incorrectly typed interfaces', () => {
const objType = new GraphQLObjectType({
name: 'SomeObject',
Expand Down Expand Up @@ -756,6 +772,19 @@ describe('Type System: Enums', () => {
'SomeEnum.FOO should provide "deprecationReason" instead of "isDeprecated".',
);
});

it('allows an Enum type with an isDeprecated field if a deprecationReason field is present', () => {
expect(
() =>
new GraphQLEnumType({
name: 'SomeEnum',
// $DisableFlowOnNegativeTest
values: {
FOO: { isDeprecated: true, deprecationReason: 'deprecated' },
},
}),
).not.to.throw();
});
});

describe('Type System: Input Objects', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ function defineFieldMap<TSource, TContext>(
`${config.name}.${fieldName} field config must be an object.`,
);
devAssert(
!('isDeprecated' in fieldConfig),
!('isDeprecated' in fieldConfig) || 'deprecationReason' in fieldConfig,
`${config.name}.${fieldName} should provide "deprecationReason" instead of "isDeprecated".`,
);
devAssert(
Expand Down Expand Up @@ -1428,8 +1428,9 @@ function defineEnumValues(
`${typeName}.${valueName} must refer to an object with a "value" key ` +
`representing an internal value but got: ${inspect(valueConfig)}.`,
);

devAssert(
!('isDeprecated' in valueConfig),
!('isDeprecated' in valueConfig) || 'deprecationReason' in valueConfig,
`${typeName}.${valueName} should provide "deprecationReason" instead of "isDeprecated".`,
);
return {
Expand Down