Skip to content

Commit f506aec

Browse files
committed
findBreakingChanges: add check for removing repeatable from directive
Code is taken from #1541
1 parent 82c2eea commit f506aec

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/utilities/__tests__/findBreakingChanges-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ describe('findBreakingChanges', () => {
645645
646646
directive @NonNullDirectiveAdded on FIELD_DEFINITION
647647
648+
directive @DirectiveThatWasRepeatable repeatable on FIELD_DEFINITION
649+
648650
directive @DirectiveName on FIELD_DEFINITION | QUERY
649651
650652
type ArgThatChanges {
@@ -679,6 +681,8 @@ describe('findBreakingChanges', () => {
679681
680682
directive @NonNullDirectiveAdded(arg1: Boolean!) on FIELD_DEFINITION
681683
684+
directive @DirectiveThatWasRepeatable on FIELD_DEFINITION
685+
682686
directive @DirectiveName on FIELD_DEFINITION
683687
684688
type ArgThatChanges {
@@ -761,6 +765,11 @@ describe('findBreakingChanges', () => {
761765
description:
762766
'A required arg arg1 on directive NonNullDirectiveAdded was added.',
763767
},
768+
{
769+
type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
770+
description:
771+
'Repeatable flag was removed from DirectiveThatWasRepeatable.',
772+
},
764773
{
765774
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
766775
description: 'QUERY was removed from DirectiveName.',
@@ -840,6 +849,23 @@ describe('findBreakingChanges', () => {
840849
]);
841850
});
842851

852+
it('should detect removal of repeatable flag', () => {
853+
const oldSchema = buildSchema(`
854+
directive @DirectiveName repeatable on OBJECT
855+
`);
856+
857+
const newSchema = buildSchema(`
858+
directive @DirectiveName on OBJECT
859+
`);
860+
861+
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
862+
{
863+
type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
864+
description: 'Repeatable flag was removed from DirectiveName.',
865+
},
866+
]);
867+
});
868+
843869
it('should detect locations removed from a directive', () => {
844870
const oldSchema = buildSchema(`
845871
directive @DirectiveName on FIELD_DEFINITION | QUERY

src/utilities/findBreakingChanges.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type _BreakingChangeType = {
2020
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED';
2121
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED';
2222
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED';
23+
DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED';
2324
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED';
2425
};
2526

src/utilities/findBreakingChanges.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const BreakingChangeType = Object.freeze({
5151
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
5252
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
5353
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
54+
DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED',
5455
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED',
5556
});
5657

@@ -148,6 +149,13 @@ function findDirectiveChanges(
148149
});
149150
}
150151

152+
if (oldDirective.isRepeatable && !newDirective.isRepeatable) {
153+
schemaChanges.push({
154+
type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
155+
description: `Repeatable flag was removed from ${oldDirective.name}.`,
156+
});
157+
}
158+
151159
for (const location of oldDirective.locations) {
152160
if (newDirective.locations.indexOf(location) === -1) {
153161
schemaChanges.push({

0 commit comments

Comments
 (0)