Skip to content

Commit fb0fc76

Browse files
committed
Merge Breaking changes and Dangerous changes
1 parent bc2db60 commit fb0fc76

File tree

7 files changed

+87
-115
lines changed

7 files changed

+87
-115
lines changed

src/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ export {
403403
// Compares two GraphQLSchemas and detects breaking changes.
404404
BreakingChangeType,
405405
DangerousChangeType,
406-
findBreakingChanges,
407-
findDangerousChanges,
406+
findSchemaChanges,
408407
// Report all deprecated usage within a GraphQL document.
409408
findDeprecatedUsages,
410409
} from './utilities';
@@ -433,6 +432,5 @@ export type {
433432
IntrospectionEnumValue,
434433
IntrospectionDirective,
435434
BuildSchemaOptions,
436-
BreakingChange,
437-
DangerousChange,
435+
SchemaChange,
438436
} from './utilities';

src/utilities/__tests__/findBreakingChanges-test.js

+62-35
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ import { buildSchema } from '../buildASTSchema';
1414
import {
1515
BreakingChangeType,
1616
DangerousChangeType,
17-
findBreakingChanges,
18-
findDangerousChanges,
17+
findSchemaChanges,
1918
} from '../findBreakingChanges';
2019

21-
describe('findBreakingChanges', () => {
20+
describe('findSchemaChanges', () => {
2221
it('should detect if a type was removed or not', () => {
2322
const oldSchema = buildSchema(`
2423
type Type1
@@ -28,13 +27,13 @@ describe('findBreakingChanges', () => {
2827
const newSchema = buildSchema(`
2928
type Type2
3029
`);
31-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
30+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
3231
{
3332
type: BreakingChangeType.TYPE_REMOVED,
3433
description: 'Type1 was removed.',
3534
},
3635
]);
37-
expect(findBreakingChanges(oldSchema, oldSchema)).to.deep.equal([]);
36+
expect(findSchemaChanges(oldSchema, oldSchema)).to.deep.equal([]);
3837
});
3938

4039
it('should detect if a type changed its type', () => {
@@ -49,7 +48,7 @@ describe('findBreakingChanges', () => {
4948
union TypeWasInterfaceBecomesUnion
5049
input TypeWasObjectBecomesInputObject
5150
`);
52-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
51+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
5352
{
5453
type: BreakingChangeType.TYPE_CHANGED_KIND,
5554
description:
@@ -119,7 +118,7 @@ describe('findBreakingChanges', () => {
119118
}
120119
`);
121120

122-
const changes = findBreakingChanges(oldSchema, newSchema);
121+
const changes = findSchemaChanges(oldSchema, newSchema);
123122
expect(changes).to.deep.equal([
124123
{
125124
type: BreakingChangeType.FIELD_REMOVED,
@@ -216,7 +215,7 @@ describe('findBreakingChanges', () => {
216215
}
217216
`);
218217

219-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
218+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
220219
{
221220
type: BreakingChangeType.FIELD_REMOVED,
222221
description: 'InputType1.field2 was removed.',
@@ -281,12 +280,22 @@ describe('findBreakingChanges', () => {
281280
}
282281
`);
283282

284-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
283+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
285284
{
286285
type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
287286
description:
288287
'A required field requiredField on input type InputType1 was added.',
289288
},
289+
{
290+
description:
291+
'An optional field optionalField1 on input type InputType1 was added.',
292+
type: 'OPTIONAL_INPUT_FIELD_ADDED',
293+
},
294+
{
295+
description:
296+
'An optional field optionalField2 on input type InputType1 was added.',
297+
type: 'OPTIONAL_INPUT_FIELD_ADDED',
298+
},
290299
]);
291300
});
292301

@@ -306,7 +315,11 @@ describe('findBreakingChanges', () => {
306315
union UnionType1 = Type1 | Type3
307316
`);
308317

309-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
318+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
319+
{
320+
description: 'Type3 was added to union type UnionType1.',
321+
type: 'TYPE_ADDED_TO_UNION',
322+
},
310323
{
311324
type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
312325
description: 'Type2 was removed from union type UnionType1.',
@@ -331,7 +344,11 @@ describe('findBreakingChanges', () => {
331344
}
332345
`);
333346

334-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
347+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
348+
{
349+
description: 'VALUE3 was added to enum type EnumType1.',
350+
type: 'VALUE_ADDED_TO_ENUM',
351+
},
335352
{
336353
type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
337354
description: 'VALUE1 was removed from enum type EnumType1.',
@@ -360,7 +377,7 @@ describe('findBreakingChanges', () => {
360377
}
361378
`);
362379

363-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
380+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
364381
{
365382
type: BreakingChangeType.ARG_REMOVED,
366383
description: 'Interface1.field1 arg arg1 was removed.',
@@ -421,7 +438,7 @@ describe('findBreakingChanges', () => {
421438
}
422439
`);
423440

424-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
441+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
425442
{
426443
type: BreakingChangeType.ARG_CHANGED_KIND,
427444
description:
@@ -503,11 +520,21 @@ describe('findBreakingChanges', () => {
503520
}
504521
`);
505522

506-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
523+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
507524
{
508525
type: BreakingChangeType.REQUIRED_ARG_ADDED,
509526
description: 'A required arg newRequiredArg on Type1.field1 was added.',
510527
},
528+
{
529+
description:
530+
'An optional arg newOptionalArg1 on Type1.field1 was added.',
531+
type: 'OPTIONAL_ARG_ADDED',
532+
},
533+
{
534+
description:
535+
'An optional arg newOptionalArg2 on Type1.field1 was added.',
536+
type: 'OPTIONAL_ARG_ADDED',
537+
},
511538
]);
512539
});
513540

@@ -532,7 +559,7 @@ describe('findBreakingChanges', () => {
532559
}
533560
`);
534561

535-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([]);
562+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([]);
536563
});
537564

538565
it('should consider args that move away from NonNull as non-breaking', () => {
@@ -548,7 +575,7 @@ describe('findBreakingChanges', () => {
548575
}
549576
`);
550577

551-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([]);
578+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([]);
552579
});
553580

554581
it('should detect interfaces removed from types', () => {
@@ -564,7 +591,7 @@ describe('findBreakingChanges', () => {
564591
type Type1
565592
`);
566593

567-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
594+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
568595
{
569596
type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
570597
description: 'Type1 no longer implements interface Interface1.',
@@ -587,7 +614,7 @@ describe('findBreakingChanges', () => {
587614
type Type1 implements SecondInterface & FirstInterface
588615
`);
589616

590-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([]);
617+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([]);
591618
});
592619

593620
it('should detect all breaking changes', () => {
@@ -657,7 +684,7 @@ describe('findBreakingChanges', () => {
657684
}
658685
`);
659686

660-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
687+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
661688
{
662689
type: BreakingChangeType.TYPE_REMOVED,
663690
description: 'Int was removed.',
@@ -730,7 +757,7 @@ describe('findBreakingChanges', () => {
730757
directive @DirectiveThatStays on FIELD_DEFINITION
731758
`);
732759

733-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
760+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
734761
{
735762
type: BreakingChangeType.DIRECTIVE_REMOVED,
736763
description: 'DirectiveThatIsRemoved was removed.',
@@ -745,7 +772,7 @@ describe('findBreakingChanges', () => {
745772
directives: [GraphQLSkipDirective, GraphQLIncludeDirective],
746773
});
747774

748-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
775+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
749776
{
750777
type: BreakingChangeType.DIRECTIVE_REMOVED,
751778
description: `${GraphQLDeprecatedDirective.name} was removed.`,
@@ -762,7 +789,7 @@ describe('findBreakingChanges', () => {
762789
directive @DirectiveWithArg on FIELD_DEFINITION
763790
`);
764791

765-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
792+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
766793
{
767794
type: BreakingChangeType.DIRECTIVE_ARG_REMOVED,
768795
description: 'arg1 was removed from DirectiveWithArg.',
@@ -783,7 +810,7 @@ describe('findBreakingChanges', () => {
783810
) on FIELD_DEFINITION
784811
`);
785812

786-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
813+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
787814
{
788815
type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
789816
description:
@@ -801,7 +828,7 @@ describe('findBreakingChanges', () => {
801828
directive @DirectiveName on FIELD_DEFINITION
802829
`);
803830

804-
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
831+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
805832
{
806833
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
807834
description: 'QUERY was removed from DirectiveName.',
@@ -810,7 +837,7 @@ describe('findBreakingChanges', () => {
810837
});
811838
});
812839

813-
describe('findDangerousChanges', () => {
840+
describe('findSchemaChanges', () => {
814841
it('should detect if a defaultValue changed on an argument', () => {
815842
const oldSDL = `
816843
input Input1 {
@@ -836,7 +863,7 @@ describe('findDangerousChanges', () => {
836863

837864
const oldSchema = buildSchema(oldSDL);
838865
const copyOfOldSchema = buildSchema(oldSDL);
839-
expect(findDangerousChanges(oldSchema, copyOfOldSchema)).to.deep.equal([]);
866+
expect(findSchemaChanges(oldSchema, copyOfOldSchema)).to.deep.equal([]);
840867

841868
const newSchema = buildSchema(`
842869
input Input1 {
@@ -860,7 +887,7 @@ describe('findDangerousChanges', () => {
860887
}
861888
`);
862889

863-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([
890+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
864891
{
865892
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
866893
description:
@@ -918,7 +945,7 @@ describe('findDangerousChanges', () => {
918945
}
919946
`);
920947

921-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([]);
948+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([]);
922949
});
923950

924951
it('should ignore changes in field definitions order', () => {
@@ -950,7 +977,7 @@ describe('findDangerousChanges', () => {
950977
}
951978
`);
952979

953-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([]);
980+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([]);
954981
});
955982

956983
it('should detect if a value was added to an enum type', () => {
@@ -969,7 +996,7 @@ describe('findDangerousChanges', () => {
969996
}
970997
`);
971998

972-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([
999+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
9731000
{
9741001
type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
9751002
description: 'VALUE2 was added to enum type EnumType1.',
@@ -992,7 +1019,7 @@ describe('findDangerousChanges', () => {
9921019
type Type1 implements OldInterface & NewInterface
9931020
`);
9941021

995-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([
1022+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
9961023
{
9971024
type: DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
9981025
description: 'NewInterface added to interfaces implemented by Type1.',
@@ -1015,7 +1042,7 @@ describe('findDangerousChanges', () => {
10151042
union UnionType1 = Type1 | Type2
10161043
`);
10171044

1018-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([
1045+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
10191046
{
10201047
type: DangerousChangeType.TYPE_ADDED_TO_UNION,
10211048
description: 'Type2 was added to union type UnionType1.',
@@ -1037,7 +1064,7 @@ describe('findDangerousChanges', () => {
10371064
}
10381065
`);
10391066

1040-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([
1067+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
10411068
{
10421069
type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
10431070
description:
@@ -1083,7 +1110,7 @@ describe('findDangerousChanges', () => {
10831110
union UnionTypeThatGainsAType = TypeInUnion1 | TypeInUnion2
10841111
`);
10851112

1086-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([
1113+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
10871114
{
10881115
type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
10891116
description: 'VALUE2 was added to enum type EnumType1.',
@@ -1119,7 +1146,7 @@ describe('findDangerousChanges', () => {
11191146
}
11201147
`);
11211148

1122-
expect(findDangerousChanges(oldSchema, newSchema)).to.deep.equal([
1149+
expect(findSchemaChanges(oldSchema, newSchema)).to.deep.equal([
11231150
{
11241151
type: DangerousChangeType.OPTIONAL_ARG_ADDED,
11251152
description: 'An optional arg arg2 on Type1.field1 was added.',

0 commit comments

Comments
 (0)