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

findBreakingChanges: add check for removing repeatable from directive #2415

Merged
merged 1 commit into from
Jan 30, 2020
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
26 changes: 26 additions & 0 deletions src/utilities/__tests__/findBreakingChanges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ describe('findBreakingChanges', () => {
directive @NonNullDirectiveAdded on FIELD_DEFINITION
directive @DirectiveThatWasRepeatable repeatable on FIELD_DEFINITION
directive @DirectiveName on FIELD_DEFINITION | QUERY
type ArgThatChanges {
Expand Down Expand Up @@ -679,6 +681,8 @@ describe('findBreakingChanges', () => {
directive @NonNullDirectiveAdded(arg1: Boolean!) on FIELD_DEFINITION
directive @DirectiveThatWasRepeatable on FIELD_DEFINITION
directive @DirectiveName on FIELD_DEFINITION
type ArgThatChanges {
Expand Down Expand Up @@ -761,6 +765,11 @@ describe('findBreakingChanges', () => {
description:
'A required arg arg1 on directive NonNullDirectiveAdded was added.',
},
{
type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
description:
'Repeatable flag was removed from DirectiveThatWasRepeatable.',
},
{
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
description: 'QUERY was removed from DirectiveName.',
Expand Down Expand Up @@ -840,6 +849,23 @@ describe('findBreakingChanges', () => {
]);
});

it('should detect removal of repeatable flag', () => {
const oldSchema = buildSchema(`
directive @DirectiveName repeatable on OBJECT
`);

const newSchema = buildSchema(`
directive @DirectiveName on OBJECT
`);

expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
description: 'Repeatable flag was removed from DirectiveName.',
},
]);
});

it('should detect locations removed from a directive', () => {
const oldSchema = buildSchema(`
directive @DirectiveName on FIELD_DEFINITION | QUERY
Expand Down
1 change: 1 addition & 0 deletions src/utilities/findBreakingChanges.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type _BreakingChangeType = {
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED';
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED';
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED';
DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED';
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED';
};

Expand Down
8 changes: 8 additions & 0 deletions src/utilities/findBreakingChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const BreakingChangeType = Object.freeze({
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED',
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED',
});

Expand Down Expand Up @@ -148,6 +149,13 @@ function findDirectiveChanges(
});
}

if (oldDirective.isRepeatable && !newDirective.isRepeatable) {
schemaChanges.push({
type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
description: `Repeatable flag was removed from ${oldDirective.name}.`,
});
}

for (const location of oldDirective.locations) {
if (newDirective.locations.indexOf(location) === -1) {
schemaChanges.push({
Expand Down