Skip to content

Commit

Permalink
findBreakingChanges: add check for removing repeatable from directive
Browse files Browse the repository at this point in the history
Code is taken from graphql#1541
  • Loading branch information
IvanGoncharov committed Jan 30, 2020
1 parent 82c2eea commit f506aec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/utilities/__tests__/findBreakingChanges-test.js
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
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
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

0 comments on commit f506aec

Please sign in to comment.