diff --git a/src/utilities/__tests__/findBreakingChanges-test.js b/src/utilities/__tests__/findBreakingChanges-test.js index b3fd7dae6e..7246f8b413 100644 --- a/src/utilities/__tests__/findBreakingChanges-test.js +++ b/src/utilities/__tests__/findBreakingChanges-test.js @@ -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 { @@ -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 { @@ -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.', @@ -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 diff --git a/src/utilities/findBreakingChanges.d.ts b/src/utilities/findBreakingChanges.d.ts index 97c427063d..37297e2f51 100644 --- a/src/utilities/findBreakingChanges.d.ts +++ b/src/utilities/findBreakingChanges.d.ts @@ -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'; }; diff --git a/src/utilities/findBreakingChanges.js b/src/utilities/findBreakingChanges.js index dcd344536b..ab566d479f 100644 --- a/src/utilities/findBreakingChanges.js +++ b/src/utilities/findBreakingChanges.js @@ -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', }); @@ -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({