Skip to content

Commit

Permalink
Added DIRECTIVE_REPEATABLE_REMOVED breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegIlyenko committed Oct 4, 2018
1 parent 1180d92 commit f8378d0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/utilities/__tests__/findBreakingChanges-test.js
Expand Up @@ -35,6 +35,7 @@ import {
findAddedNonNullDirectiveArgs,
findRemovedLocationsForDirective,
findRemovedDirectiveLocations,
findRemovedDirectiveRepeatable,
} from '../findBreakingChanges';

import {
Expand Down Expand Up @@ -1007,6 +1008,23 @@ describe('findBreakingChanges', () => {
},
]);
});

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

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

expect(findRemovedDirectiveRepeatable(oldSchema, newSchema)).to.eql([
{
type: BreakingChangeType.DIRECTIVE_REPEATABLE_REMOVED,
description: 'Repeatable flag was removed from foo',
},
]);
});
});

describe('findDangerousChanges', () => {
Expand Down
27 changes: 27 additions & 0 deletions src/utilities/findBreakingChanges.js
Expand Up @@ -50,6 +50,7 @@ export const BreakingChangeType = {
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED',
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED',
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED',
DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED',
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED',
};

Expand Down Expand Up @@ -94,6 +95,7 @@ export function findBreakingChanges(
...findRemovedDirectiveArgs(oldSchema, newSchema),
...findAddedNonNullDirectiveArgs(oldSchema, newSchema),
...findRemovedDirectiveLocations(oldSchema, newSchema),
...findRemovedDirectiveRepeatable(oldSchema, newSchema),
];
}

Expand Down Expand Up @@ -840,6 +842,31 @@ export function findRemovedDirectiveLocations(
return removedLocations;
}

export function findRemovedDirectiveRepeatable(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange> {
const removedRepeatable = [];
const oldSchemaDirectiveMap = getDirectiveMapForSchema(oldSchema);

for (const newDirective of newSchema.getDirectives()) {
const oldDirective = oldSchemaDirectiveMap[newDirective.name];

if (!oldDirective) {
continue;
}

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

return removedRepeatable;
}

function getDirectiveMapForSchema(
schema: GraphQLSchema,
): ObjMap<GraphQLDirective> {
Expand Down

0 comments on commit f8378d0

Please sign in to comment.