@graphql-inspector/core 0.0.0-canary.da4bdcc → 0.0.0-canary.e5ed377

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,34 @@
1
- import { Kind, TypeInfo, visit, visitWithTypeInfo, GraphQLError, getNamedType, isWrappingType, isListType, isNonNullType, isInterfaceType, isEnumType, isUnionType, isInputObjectType, isObjectType, isScalarType, parse, extendSchema, print, validate as validate$1, printType } from 'graphql';
1
+ import { __awaiter } from 'tslib';
2
+ import { Kind, TypeInfo, visit, visitWithTypeInfo, GraphQLError, getNamedType, isScalarType, isInterfaceType, isObjectType, isUnionType, isInputObjectType, isListType, isNonNullType, isWrappingType, isEnumType, parse, extendSchema, print, validate as validate$1, printType } from 'graphql';
3
+ import inspect from 'object-inspect';
2
4
  import { DepGraph } from 'dependency-graph';
3
5
 
6
+ function keyMap(list, keyFn) {
7
+ return list.reduce((map, item) => {
8
+ map[keyFn(item)] = item;
9
+ return map;
10
+ }, Object.create(null));
11
+ }
4
12
  function isEqual(a, b) {
5
13
  if (Array.isArray(a) && Array.isArray(b)) {
6
14
  if (a.length !== b.length)
7
15
  return false;
8
16
  for (var index = 0; index < a.length; index++) {
9
- if (a[index] !== b[index]) {
17
+ if (!isEqual(a[index], b[index])) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ }
23
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
24
+ const aRecord = a;
25
+ const bRecord = b;
26
+ const aKeys = Object.keys(aRecord);
27
+ const bKeys = Object.keys(bRecord);
28
+ if (aKeys.length !== bKeys.length)
29
+ return false;
30
+ for (const key of aKeys) {
31
+ if (!isEqual(aRecord[key], bRecord[key])) {
10
32
  return false;
11
33
  }
12
34
  }
@@ -20,12 +42,62 @@ function isNotEqual(a, b) {
20
42
  function isVoid(a) {
21
43
  return typeof a === 'undefined' || a === null;
22
44
  }
23
-
24
45
  function diffArrays(a, b) {
25
- return a.filter(c => !b.some(d => d === c));
46
+ return a.filter(c => !b.some(d => isEqual(d, c)));
47
+ }
48
+ function compareLists(oldList, newList, callbacks) {
49
+ const oldMap = keyMap(oldList, ({ name }) => name);
50
+ const newMap = keyMap(newList, ({ name }) => name);
51
+ const added = [];
52
+ const removed = [];
53
+ const mutual = [];
54
+ for (const oldItem of oldList) {
55
+ const newItem = newMap[oldItem.name];
56
+ if (newItem === undefined) {
57
+ removed.push(oldItem);
58
+ }
59
+ else {
60
+ mutual.push({
61
+ newVersion: newItem,
62
+ oldVersion: oldItem,
63
+ });
64
+ }
65
+ }
66
+ for (const newItem of newList) {
67
+ if (oldMap[newItem.name] === undefined) {
68
+ added.push(newItem);
69
+ }
70
+ }
71
+ if (callbacks) {
72
+ if (callbacks.onAdded) {
73
+ added.forEach(callbacks.onAdded);
74
+ }
75
+ if (callbacks.onRemoved) {
76
+ removed.forEach(callbacks.onRemoved);
77
+ }
78
+ if (callbacks.onMutual) {
79
+ mutual.forEach(callbacks.onMutual);
80
+ }
81
+ }
82
+ return {
83
+ added,
84
+ removed,
85
+ mutual,
86
+ };
26
87
  }
27
- function unionArrays(a, b) {
28
- return a.filter(c => b.some(d => d === c));
88
+
89
+ function isDeprecated(fieldOrEnumValue) {
90
+ var _a, _b;
91
+ if ('isDeprecated' in fieldOrEnumValue) {
92
+ return fieldOrEnumValue['isDeprecated'];
93
+ }
94
+ if (fieldOrEnumValue.deprecationReason != null) {
95
+ return true;
96
+ }
97
+ if ((_b = (_a = fieldOrEnumValue.astNode) === null || _a === void 0 ? void 0 : _a.directives) === null || _b === void 0 ? void 0 : _b.some(directive => directive.name.value === 'deprecated')) {
98
+ return true;
99
+ }
100
+ return false;
29
101
  }
30
102
 
31
103
  function safeChangeForField(oldType, newType) {
@@ -37,8 +109,7 @@ function safeChangeForField(oldType, newType) {
37
109
  return safeChangeForField(ofType, newType.ofType);
38
110
  }
39
111
  if (isListType(oldType)) {
40
- return ((isListType(newType) &&
41
- safeChangeForField(oldType.ofType, newType.ofType)) ||
112
+ return ((isListType(newType) && safeChangeForField(oldType.ofType, newType.ofType)) ||
42
113
  (isNonNullType(newType) && safeChangeForField(oldType, newType.ofType)));
43
114
  }
44
115
  return false;
@@ -51,7 +122,7 @@ function safeChangeForInputValue(oldType, newType) {
51
122
  return safeChangeForInputValue(oldType.ofType, newType.ofType);
52
123
  }
53
124
  if (isNonNullType(oldType)) {
54
- const ofType = isNonNullType(newType) ? newType : newType;
125
+ const ofType = isNonNullType(newType) ? newType.ofType : newType;
55
126
  return safeChangeForInputValue(oldType.ofType, ofType);
56
127
  }
57
128
  return false;
@@ -70,10 +141,10 @@ function getTypePrefix(type) {
70
141
  [Kind.ENUM_TYPE_DEFINITION]: 'enum',
71
142
  [Kind.INPUT_OBJECT_TYPE_DEFINITION]: 'input',
72
143
  };
73
- return kindsMap[kind];
144
+ return kindsMap[kind.toString()];
74
145
  }
75
146
  function isPrimitive(type) {
76
- return (['String', 'Int', 'Float', 'Boolean', 'ID'].indexOf(typeof type === 'string' ? type : type.name) !== -1);
147
+ return ['String', 'Int', 'Float', 'Boolean', 'ID'].indexOf(typeof type === 'string' ? type : type.name) !== -1;
77
148
  }
78
149
  function isForIntrospection(type) {
79
150
  return ([
@@ -91,9 +162,23 @@ function findDeprecatedUsages(schema, ast) {
91
162
  const errors = [];
92
163
  const typeInfo = new TypeInfo(schema);
93
164
  visit(ast, visitWithTypeInfo(typeInfo, {
165
+ Argument(node) {
166
+ const argument = typeInfo.getArgument();
167
+ if (argument) {
168
+ const reason = argument.deprecationReason;
169
+ if (reason) {
170
+ const fieldDef = typeInfo.getFieldDef();
171
+ if (fieldDef) {
172
+ errors.push(new GraphQLError(`The argument '${argument === null || argument === void 0 ? void 0 : argument.name}' of '${fieldDef.name}' is deprecated. ${reason}`, [
173
+ node,
174
+ ]));
175
+ }
176
+ }
177
+ }
178
+ },
94
179
  Field(node) {
95
180
  const fieldDef = typeInfo.getFieldDef();
96
- if (fieldDef && fieldDef.isDeprecated) {
181
+ if (fieldDef && isDeprecated(fieldDef)) {
97
182
  const parentType = typeInfo.getParentType();
98
183
  if (parentType) {
99
184
  const reason = fieldDef.deprecationReason;
@@ -103,7 +188,7 @@ function findDeprecatedUsages(schema, ast) {
103
188
  },
104
189
  EnumValue(node) {
105
190
  const enumVal = typeInfo.getEnumValue();
106
- if (enumVal && enumVal.isDeprecated) {
191
+ if (enumVal && isDeprecated(enumVal)) {
107
192
  const type = getNamedType(typeInfo.getInputType());
108
193
  if (type) {
109
194
  const reason = enumVal.deprecationReason;
@@ -128,6 +213,71 @@ function removeDirectives(node, directiveNames) {
128
213
  }
129
214
  return node;
130
215
  }
216
+ function getReachableTypes(schema) {
217
+ const reachableTypes = new Set();
218
+ const collect = (type) => {
219
+ const typeName = type.name;
220
+ if (reachableTypes.has(typeName)) {
221
+ return;
222
+ }
223
+ reachableTypes.add(typeName);
224
+ if (isScalarType(type)) {
225
+ return;
226
+ }
227
+ else if (isInterfaceType(type) || isObjectType(type)) {
228
+ if (isInterfaceType(type)) {
229
+ const { objects, interfaces } = schema.getImplementations(type);
230
+ for (const child of objects) {
231
+ collect(child);
232
+ }
233
+ for (const child of interfaces) {
234
+ collect(child);
235
+ }
236
+ }
237
+ const fields = type.getFields();
238
+ for (const fieldName in fields) {
239
+ const field = fields[fieldName];
240
+ collect(resolveOutputType(field.type));
241
+ const args = field.args;
242
+ for (const argName in args) {
243
+ const arg = args[argName];
244
+ collect(resolveInputType(arg.type));
245
+ }
246
+ }
247
+ }
248
+ else if (isUnionType(type)) {
249
+ const types = type.getTypes();
250
+ for (const child of types) {
251
+ collect(child);
252
+ }
253
+ }
254
+ else if (isInputObjectType(type)) {
255
+ const fields = type.getFields();
256
+ for (const fieldName in fields) {
257
+ const field = fields[fieldName];
258
+ collect(resolveInputType(field.type));
259
+ }
260
+ }
261
+ };
262
+ for (const type of [schema.getQueryType(), schema.getMutationType(), schema.getSubscriptionType()]) {
263
+ if (type) {
264
+ collect(type);
265
+ }
266
+ }
267
+ return reachableTypes;
268
+ }
269
+ function resolveOutputType(output) {
270
+ if (isListType(output) || isNonNullType(output)) {
271
+ return resolveOutputType(output.ofType);
272
+ }
273
+ return output;
274
+ }
275
+ function resolveInputType(input) {
276
+ if (isListType(input) || isNonNullType(input)) {
277
+ return resolveInputType(input.ofType);
278
+ }
279
+ return input;
280
+ }
131
281
 
132
282
  var ChangeType;
133
283
  (function (ChangeType) {
@@ -151,6 +301,8 @@ var ChangeType;
151
301
  ChangeType["EnumValueAdded"] = "ENUM_VALUE_ADDED";
152
302
  ChangeType["EnumValueDescriptionChanged"] = "ENUM_VALUE_DESCRIPTION_CHANGED";
153
303
  ChangeType["EnumValueDeprecationReasonChanged"] = "ENUM_VALUE_DEPRECATION_REASON_CHANGED";
304
+ ChangeType["EnumValueDeprecationReasonAdded"] = "ENUM_VALUE_DEPRECATION_REASON_ADDED";
305
+ ChangeType["EnumValueDeprecationReasonRemoved"] = "ENUM_VALUE_DEPRECATION_REASON_REMOVED";
154
306
  // Field
155
307
  ChangeType["FieldRemoved"] = "FIELD_REMOVED";
156
308
  ChangeType["FieldAdded"] = "FIELD_ADDED";
@@ -349,9 +501,7 @@ function directiveLocationRemoved(directive, location) {
349
501
  function directiveArgumentAdded(directive, arg) {
350
502
  return {
351
503
  criticality: {
352
- level: isNonNullType(arg.type)
353
- ? CriticalityLevel.Breaking
354
- : CriticalityLevel.NonBreaking,
504
+ level: isNonNullType(arg.type) ? CriticalityLevel.Breaking : CriticalityLevel.NonBreaking,
355
505
  },
356
506
  type: ChangeType.DirectiveArgumentAdded,
357
507
  message: `Argument '${arg.name}' was added to directive '${directive.name}'`,
@@ -414,7 +564,7 @@ function enumValueRemoved(oldEnum, value) {
414
564
  reason: `Removing an enum value will cause existing queries that use this enum value to error.`,
415
565
  },
416
566
  type: ChangeType.EnumValueRemoved,
417
- message: `Enum value '${value.name}' was removed from enum '${oldEnum.name}'`,
567
+ message: `Enum value '${value.name}' ${isDeprecated(value) ? '(deprecated) ' : ''}was removed from enum '${oldEnum.name}'`,
418
568
  path: [oldEnum.name, value.name].join('.'),
419
569
  };
420
570
  }
@@ -446,35 +596,59 @@ function enumValueDeprecationReasonChanged(newEnum, oldValue, newValue) {
446
596
  criticality: {
447
597
  level: CriticalityLevel.NonBreaking,
448
598
  },
449
- type: ChangeType.EnumValueDescriptionChanged,
450
- message: oldValue.deprecationReason
451
- ? `Enum value '${newEnum.name}.${newValue.name}' deprecation reason changed from '${oldValue.deprecationReason}' to '${newValue.deprecationReason}'`
452
- : `Enum value '${newEnum.name}.${newValue.name}' was deprecated with reason '${newValue.deprecationReason}'`,
599
+ type: ChangeType.EnumValueDeprecationReasonChanged,
600
+ message: `Enum value '${newEnum.name}.${newValue.name}' deprecation reason changed from '${oldValue.deprecationReason}' to '${newValue.deprecationReason}'`,
601
+ path: [newEnum.name, oldValue.name].join('.'),
602
+ };
603
+ }
604
+ function enumValueDeprecationReasonAdded(newEnum, oldValue, newValue) {
605
+ return {
606
+ criticality: {
607
+ level: CriticalityLevel.NonBreaking,
608
+ },
609
+ type: ChangeType.EnumValueDeprecationReasonAdded,
610
+ message: `Enum value '${newEnum.name}.${newValue.name}' was deprecated with reason '${newValue.deprecationReason}'`,
611
+ path: [newEnum.name, oldValue.name].join('.'),
612
+ };
613
+ }
614
+ function enumValueDeprecationReasonRemoved(newEnum, oldValue, newValue) {
615
+ return {
616
+ criticality: {
617
+ level: CriticalityLevel.NonBreaking,
618
+ },
619
+ type: ChangeType.EnumValueDeprecationReasonRemoved,
620
+ message: `Deprecation reason was removed from enum value '${newEnum.name}.${newValue.name}'`,
453
621
  path: [newEnum.name, oldValue.name].join('.'),
454
622
  };
455
623
  }
456
624
 
457
- function changesInEnum(oldEnum, newEnum) {
458
- const changes = [];
459
- const oldNames = oldEnum.getValues().map(v => v.name);
460
- const newNames = newEnum.getValues().map(v => v.name);
461
- const added = diffArrays(newNames, oldNames).map(name => newEnum.getValue(name));
462
- const removed = diffArrays(oldNames, newNames).map(name => oldEnum.getValue(name));
463
- const common = unionArrays(oldNames, newNames).map(name => ({
464
- oldValue: oldEnum.getValue(name),
465
- newValue: newEnum.getValue(name),
466
- }));
467
- changes.push(...added.map(v => enumValueAdded(newEnum, v)));
468
- changes.push(...removed.map(v => enumValueRemoved(oldEnum, v)));
469
- common.forEach(({ oldValue, newValue }) => {
470
- if (isNotEqual(oldValue.description, newValue.description)) {
471
- changes.push(enumValueDescriptionChanged(newEnum, oldValue, newValue));
472
- }
473
- if (isNotEqual(oldValue.deprecationReason, newValue.deprecationReason)) {
474
- changes.push(enumValueDeprecationReasonChanged(newEnum, oldValue, newValue));
475
- }
625
+ function changesInEnum(oldEnum, newEnum, addChange) {
626
+ compareLists(oldEnum.getValues(), newEnum.getValues(), {
627
+ onAdded(value) {
628
+ addChange(enumValueAdded(newEnum, value));
629
+ },
630
+ onRemoved(value) {
631
+ addChange(enumValueRemoved(oldEnum, value));
632
+ },
633
+ onMutual(value) {
634
+ const oldValue = value.oldVersion;
635
+ const newValue = value.newVersion;
636
+ if (isNotEqual(oldValue.description, newValue.description)) {
637
+ addChange(enumValueDescriptionChanged(newEnum, oldValue, newValue));
638
+ }
639
+ if (isNotEqual(oldValue.deprecationReason, newValue.deprecationReason)) {
640
+ if (isVoid(oldValue.deprecationReason)) {
641
+ addChange(enumValueDeprecationReasonAdded(newEnum, oldValue, newValue));
642
+ }
643
+ else if (isVoid(newValue.deprecationReason)) {
644
+ addChange(enumValueDeprecationReasonRemoved(newEnum, oldValue, newValue));
645
+ }
646
+ else {
647
+ addChange(enumValueDeprecationReasonChanged(newEnum, oldValue, newValue));
648
+ }
649
+ }
650
+ },
476
651
  });
477
- return changes;
478
652
  }
479
653
 
480
654
  function unionMemberRemoved(union, type) {
@@ -500,17 +674,81 @@ function unionMemberAdded(union, type) {
500
674
  };
501
675
  }
502
676
 
503
- function changesInUnion(oldUnion, newUnion) {
504
- const changes = [];
677
+ function changesInUnion(oldUnion, newUnion, addChange) {
505
678
  const oldTypes = oldUnion.getTypes();
506
679
  const newTypes = newUnion.getTypes();
507
- const oldTypenames = oldTypes.map(t => t.name);
508
- const newTypenames = newTypes.map(t => t.name);
509
- const added = diffArrays(newTypenames, oldTypenames).map(name => newTypes.find(t => t.name === name));
510
- const removed = diffArrays(oldTypenames, newTypenames).map(name => oldTypes.find(t => t.name === name));
511
- changes.push(...added.map(type => unionMemberAdded(newUnion, type)));
512
- changes.push(...removed.map(type => unionMemberRemoved(oldUnion, type)));
513
- return changes;
680
+ compareLists(oldTypes, newTypes, {
681
+ onAdded(t) {
682
+ addChange(unionMemberAdded(newUnion, t));
683
+ },
684
+ onRemoved(t) {
685
+ addChange(unionMemberRemoved(oldUnion, t));
686
+ },
687
+ });
688
+ }
689
+
690
+ function compareTwoStrings(str1, str2) {
691
+ if (!str1.length && !str2.length)
692
+ return 1;
693
+ if (!str1.length || !str2.length)
694
+ return 0;
695
+ if (str1.toUpperCase() === str2.toUpperCase())
696
+ return 1;
697
+ if (str1.length === 1 && str2.length === 1)
698
+ return 0;
699
+ const pairs1 = wordLetterPairs(str1);
700
+ const pairs2 = wordLetterPairs(str2);
701
+ const union = pairs1.length + pairs2.length;
702
+ let intersection = 0;
703
+ pairs1.forEach(pair1 => {
704
+ for (let i = 0, pair2; (pair2 = pairs2[i]); i++) {
705
+ if (pair1 !== pair2)
706
+ continue;
707
+ intersection++;
708
+ pairs2.splice(i, 1);
709
+ break;
710
+ }
711
+ });
712
+ return (intersection * 2) / union;
713
+ }
714
+ function findBestMatch(mainString, targetStrings) {
715
+ if (!areArgsValid(mainString, targetStrings))
716
+ throw new Error('Bad arguments: First argument should be a string, second should be an array of strings');
717
+ const ratings = targetStrings.map(target => ({
718
+ target,
719
+ rating: compareTwoStrings(mainString, target.value),
720
+ }));
721
+ const bestMatch = Array.from(ratings).sort((a, b) => b.rating - a.rating)[0];
722
+ return { ratings, bestMatch };
723
+ }
724
+ function flattenDeep(arr) {
725
+ return Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
726
+ }
727
+ function areArgsValid(mainString, targetStrings) {
728
+ if (typeof mainString !== 'string')
729
+ return false;
730
+ if (!Array.isArray(targetStrings))
731
+ return false;
732
+ if (!targetStrings.length)
733
+ return false;
734
+ if (targetStrings.find(s => typeof s.value !== 'string'))
735
+ return false;
736
+ return true;
737
+ }
738
+ function letterPairs(str) {
739
+ const pairs = [];
740
+ for (let i = 0, max = str.length - 1; i < max; i++)
741
+ pairs[i] = str.substring(i, i + 2);
742
+ return pairs;
743
+ }
744
+ function wordLetterPairs(str) {
745
+ const pairs = str.toUpperCase().split(' ').map(letterPairs);
746
+ return flattenDeep(pairs);
747
+ }
748
+ function safeString(obj) {
749
+ return inspect(obj)
750
+ .replace(/\[Object\: null prototype\] /g, '')
751
+ .replace(/(^')|('$)/g, '');
514
752
  }
515
753
 
516
754
  function inputFieldRemoved(input, field) {
@@ -520,7 +758,7 @@ function inputFieldRemoved(input, field) {
520
758
  reason: 'Removing an input field will cause existing queries that use this input field to error.',
521
759
  },
522
760
  type: ChangeType.InputFieldRemoved,
523
- message: `Input field '${field.name}' was removed from input object type '${input.name}'`,
761
+ message: `Input field '${field.name}' ${isDeprecated(field) ? '(deprecated) ' : ''}was removed from input object type '${input.name}'`,
524
762
  path: [input.name, field.name].join('.'),
525
763
  };
526
764
  }
@@ -529,7 +767,7 @@ function inputFieldAdded(input, field) {
529
767
  criticality: isNonNullType(field.type)
530
768
  ? {
531
769
  level: CriticalityLevel.Breaking,
532
- reason: 'Adding a possible type to Unions may break existing clients that were not programming defensively against a new possible type.',
770
+ reason: 'Adding a required input field to an existing input object type is a breaking change because it will cause existing uses of this input object type to error.',
533
771
  }
534
772
  : {
535
773
  level: CriticalityLevel.Dangerous,
@@ -573,10 +811,10 @@ function inputFieldDefaultValueChanged(input, oldField, newField) {
573
811
  return {
574
812
  criticality: {
575
813
  level: CriticalityLevel.Dangerous,
576
- reason: 'Changing the default value for an argument may change the runtime behaviour of a field if it was never provided.',
814
+ reason: 'Changing the default value for an argument may change the runtime behavior of a field if it was never provided.',
577
815
  },
578
816
  type: ChangeType.InputFieldDefaultValueChanged,
579
- message: `Input field '${input.name}.${oldField.name}' default value changed from '${oldField.defaultValue}' to '${newField.defaultValue}'`,
817
+ message: `Input field '${input.name}.${oldField.name}' default value changed from '${safeString(oldField.defaultValue)}' to '${safeString(newField.defaultValue)}'`,
580
818
  path: [input.name, oldField.name].join('.'),
581
819
  };
582
820
  }
@@ -597,55 +835,46 @@ function inputFieldTypeChanged(input, oldField, newField) {
597
835
  };
598
836
  }
599
837
 
600
- function changesInInputObject(oldInput, newInput) {
601
- const changes = [];
838
+ function changesInInputObject(oldInput, newInput, addChange) {
602
839
  const oldFields = oldInput.getFields();
603
840
  const newFields = newInput.getFields();
604
- const oldNames = Object.keys(oldFields).map(name => oldFields[name].name);
605
- const newNames = Object.keys(newFields).map(name => newFields[name].name);
606
- const added = diffArrays(newNames, oldNames).map(name => newFields[name]);
607
- const removed = diffArrays(oldNames, newNames).map(name => oldFields[name]);
608
- const common = unionArrays(oldNames, newNames).map(name => ({
609
- inOld: oldFields[name],
610
- inNew: newFields[name],
611
- }));
612
- common.forEach(({ inOld, inNew }) => {
613
- changes.push(...changesInInputField(oldInput, inOld, inNew));
841
+ compareLists(Object.values(oldFields), Object.values(newFields), {
842
+ onAdded(field) {
843
+ addChange(inputFieldAdded(newInput, field));
844
+ },
845
+ onRemoved(field) {
846
+ addChange(inputFieldRemoved(oldInput, field));
847
+ },
848
+ onMutual(field) {
849
+ changesInInputField(oldInput, field.oldVersion, field.newVersion, addChange);
850
+ },
614
851
  });
615
- changes.push(...added.map(field => inputFieldAdded(newInput, field)));
616
- changes.push(...removed.map(field => inputFieldRemoved(oldInput, field)));
617
- return changes;
618
852
  }
619
- function changesInInputField(input, oldField, newField) {
620
- const changes = [];
853
+ function changesInInputField(input, oldField, newField, addChange) {
621
854
  if (isNotEqual(oldField.description, newField.description)) {
622
855
  if (isVoid(oldField.description)) {
623
- changes.push(inputFieldDescriptionAdded(input, newField));
856
+ addChange(inputFieldDescriptionAdded(input, newField));
624
857
  }
625
858
  else if (isVoid(newField.description)) {
626
- changes.push(inputFieldDescriptionRemoved(input, oldField));
859
+ addChange(inputFieldDescriptionRemoved(input, oldField));
627
860
  }
628
861
  else {
629
- changes.push(inputFieldDescriptionChanged(input, oldField, newField));
862
+ addChange(inputFieldDescriptionChanged(input, oldField, newField));
630
863
  }
631
864
  }
632
865
  if (isNotEqual(oldField.defaultValue, newField.defaultValue)) {
633
- if (Array.isArray(oldField.defaultValue) &&
634
- Array.isArray(newField.defaultValue)) {
866
+ if (Array.isArray(oldField.defaultValue) && Array.isArray(newField.defaultValue)) {
635
867
  if (diffArrays(oldField.defaultValue, newField.defaultValue).length > 0) {
636
- changes.push(inputFieldDefaultValueChanged(input, oldField, newField));
868
+ addChange(inputFieldDefaultValueChanged(input, oldField, newField));
637
869
  }
638
870
  }
639
- else if (JSON.stringify(oldField.defaultValue) !==
640
- JSON.stringify(newField.defaultValue)) {
641
- changes.push(inputFieldDefaultValueChanged(input, oldField, newField));
871
+ else if (JSON.stringify(oldField.defaultValue) !== JSON.stringify(newField.defaultValue)) {
872
+ addChange(inputFieldDefaultValueChanged(input, oldField, newField));
642
873
  }
643
874
  }
644
875
  if (isNotEqual(oldField.type.toString(), newField.type.toString())) {
645
- changes.push(inputFieldTypeChanged(input, oldField, newField));
876
+ addChange(inputFieldTypeChanged(input, oldField, newField));
646
877
  }
647
- // TODO: diff directives
648
- return changes;
649
878
  }
650
879
 
651
880
  function objectTypeInterfaceAdded(iface, type) {
@@ -681,7 +910,7 @@ function fieldRemoved(type, field) {
681
910
  : `Removing a field is a breaking change. It is preferable to deprecate the field before removing it.`,
682
911
  },
683
912
  type: ChangeType.FieldRemoved,
684
- message: `Field '${field.name}' ${field.isDeprecated ? '(deprecated) ' : ''}was removed from ${entity} '${type.name}'`,
913
+ message: `Field '${field.name}' ${isDeprecated(field) ? '(deprecated) ' : ''}was removed from ${entity} '${type.name}'`,
685
914
  path: [type.name, field.name].join('.'),
686
915
  };
687
916
  }
@@ -789,8 +1018,10 @@ function fieldTypeChanged(type, oldField, newField) {
789
1018
  };
790
1019
  }
791
1020
  function fieldArgumentAdded(type, field, arg) {
1021
+ const isBreaking = isNonNullType(arg.type) && typeof arg.defaultValue === 'undefined';
1022
+ const defaultValueMsg = typeof arg.defaultValue !== 'undefined' ? ' (with default value) ' : ' ';
792
1023
  return {
793
- criticality: isNonNullType(arg.type)
1024
+ criticality: isBreaking
794
1025
  ? {
795
1026
  level: CriticalityLevel.Breaking,
796
1027
  reason: `Adding a required argument to an existing field is a breaking change because it will cause existing uses of this field to error.`,
@@ -800,7 +1031,7 @@ function fieldArgumentAdded(type, field, arg) {
800
1031
  reason: `Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.`,
801
1032
  },
802
1033
  type: ChangeType.FieldArgumentAdded,
803
- message: `Argument '${arg.name}: ${arg.type}' added to field '${type.name}.${field.name}'`,
1034
+ message: `Argument '${arg.name}: ${arg.type}'${defaultValueMsg}added to field '${type.name}.${field.name}'`,
804
1035
  path: [type.name, field.name, arg.name].join('.'),
805
1036
  };
806
1037
  }
@@ -834,8 +1065,8 @@ function fieldArgumentDefaultChanged(type, field, oldArg, newArg) {
834
1065
  },
835
1066
  type: ChangeType.FieldArgumentDefaultChanged,
836
1067
  message: typeof oldArg.defaultValue === 'undefined'
837
- ? `Default value '${newArg.defaultValue}' was added to argument '${newArg.name}' on field '${type.name}.${field.name}'`
838
- : `Default value for argument '${newArg.name}' on field '${type.name}.${field.name}' changed from '${oldArg.defaultValue}' to '${newArg.defaultValue}'`,
1068
+ ? `Default value '${safeString(newArg.defaultValue)}' was added to argument '${newArg.name}' on field '${type.name}.${field.name}'`
1069
+ : `Default value for argument '${newArg.name}' on field '${type.name}.${field.name}' changed from '${safeString(oldArg.defaultValue)}' to '${safeString(newArg.defaultValue)}'`,
839
1070
  path: [type.name, field.name, oldArg.name].join('.'),
840
1071
  };
841
1072
  }
@@ -856,339 +1087,253 @@ function fieldArgumentTypeChanged(type, field, oldArg, newArg) {
856
1087
  };
857
1088
  }
858
1089
 
859
- function changesInArgument(type, field, oldArg, newArg) {
860
- const changes = [];
1090
+ function changesInArgument(type, field, oldArg, newArg, addChange) {
861
1091
  if (isNotEqual(oldArg.description, newArg.description)) {
862
- changes.push(fieldArgumentDescriptionChanged(type, field, oldArg, newArg));
1092
+ addChange(fieldArgumentDescriptionChanged(type, field, oldArg, newArg));
863
1093
  }
864
1094
  if (isNotEqual(oldArg.defaultValue, newArg.defaultValue)) {
865
- if (Array.isArray(oldArg.defaultValue) &&
866
- Array.isArray(newArg.defaultValue)) {
1095
+ if (Array.isArray(oldArg.defaultValue) && Array.isArray(newArg.defaultValue)) {
867
1096
  const diff = diffArrays(oldArg.defaultValue, newArg.defaultValue);
868
1097
  if (diff.length > 0) {
869
- changes.push(fieldArgumentDefaultChanged(type, field, oldArg, newArg));
1098
+ addChange(fieldArgumentDefaultChanged(type, field, oldArg, newArg));
870
1099
  }
871
1100
  }
872
- else if (JSON.stringify(oldArg.defaultValue) !==
873
- JSON.stringify(newArg.defaultValue)) {
874
- changes.push(fieldArgumentDefaultChanged(type, field, oldArg, newArg));
1101
+ else if (JSON.stringify(oldArg.defaultValue) !== JSON.stringify(newArg.defaultValue)) {
1102
+ addChange(fieldArgumentDefaultChanged(type, field, oldArg, newArg));
875
1103
  }
876
1104
  }
877
1105
  if (isNotEqual(oldArg.type.toString(), newArg.type.toString())) {
878
- changes.push(fieldArgumentTypeChanged(type, field, oldArg, newArg));
1106
+ addChange(fieldArgumentTypeChanged(type, field, oldArg, newArg));
879
1107
  }
880
- return changes;
881
1108
  }
882
1109
 
883
- function changesInField(type, oldField, newField) {
884
- const changes = [];
1110
+ function changesInField(type, oldField, newField, addChange) {
885
1111
  if (isNotEqual(oldField.description, newField.description)) {
886
1112
  if (isVoid(oldField.description)) {
887
- changes.push(fieldDescriptionAdded(type, newField));
1113
+ addChange(fieldDescriptionAdded(type, newField));
888
1114
  }
889
1115
  else if (isVoid(newField.description)) {
890
- changes.push(fieldDescriptionRemoved(type, oldField));
1116
+ addChange(fieldDescriptionRemoved(type, oldField));
891
1117
  }
892
1118
  else {
893
- changes.push(fieldDescriptionChanged(type, oldField, newField));
1119
+ addChange(fieldDescriptionChanged(type, oldField, newField));
894
1120
  }
895
1121
  }
896
- if (isNotEqual(oldField.isDeprecated, newField.isDeprecated)) {
897
- if (newField.isDeprecated) {
898
- changes.push(fieldDeprecationAdded(type, newField));
1122
+ if (isNotEqual(isDeprecated(oldField), isDeprecated(newField))) {
1123
+ if (isDeprecated(newField)) {
1124
+ addChange(fieldDeprecationAdded(type, newField));
899
1125
  }
900
1126
  else {
901
- changes.push(fieldDeprecationRemoved(type, oldField));
1127
+ addChange(fieldDeprecationRemoved(type, oldField));
902
1128
  }
903
1129
  }
904
1130
  if (isNotEqual(oldField.deprecationReason, newField.deprecationReason)) {
905
1131
  if (isVoid(oldField.deprecationReason)) {
906
- changes.push(fieldDeprecationReasonAdded(type, newField));
1132
+ addChange(fieldDeprecationReasonAdded(type, newField));
907
1133
  }
908
1134
  else if (isVoid(newField.deprecationReason)) {
909
- changes.push(fieldDeprecationReasonRemoved(type, oldField));
1135
+ addChange(fieldDeprecationReasonRemoved(type, oldField));
910
1136
  }
911
1137
  else {
912
- changes.push(fieldDeprecationReasonChanged(type, oldField, newField));
1138
+ addChange(fieldDeprecationReasonChanged(type, oldField, newField));
913
1139
  }
914
1140
  }
915
1141
  if (isNotEqual(oldField.type.toString(), newField.type.toString())) {
916
- changes.push(fieldTypeChanged(type, oldField, newField));
1142
+ addChange(fieldTypeChanged(type, oldField, newField));
917
1143
  }
918
- const oldArgs = oldField.args;
919
- const newArgs = newField.args;
920
- const oldNames = oldArgs.map(a => a.name);
921
- const newNames = newArgs.map(a => a.name);
922
- const added = diffArrays(newNames, oldNames).map(name => newArgs.find(a => a.name === name));
923
- const removed = diffArrays(oldNames, newNames).map(name => oldArgs.find(a => a.name === name));
924
- const common = unionArrays(oldNames, newNames).map(name => ({
925
- inOld: oldArgs.find(a => a.name === name),
926
- inNew: newArgs.find(a => a.name === name),
927
- }));
928
- common.forEach(({ inOld, inNew }) => {
929
- changes.push(...changesInArgument(type, oldField, inOld, inNew));
1144
+ compareLists(oldField.args, newField.args, {
1145
+ onAdded(arg) {
1146
+ addChange(fieldArgumentAdded(type, newField, arg));
1147
+ },
1148
+ onRemoved(arg) {
1149
+ addChange(fieldArgumentRemoved(type, oldField, arg));
1150
+ },
1151
+ onMutual(arg) {
1152
+ changesInArgument(type, oldField, arg.oldVersion, arg.newVersion, addChange);
1153
+ },
930
1154
  });
931
- changes.push(...added.map(arg => fieldArgumentAdded(type, newField, arg)));
932
- changes.push(...removed.map(arg => fieldArgumentRemoved(type, oldField, arg)));
933
- return changes;
934
1155
  }
935
1156
 
936
- function changesInObject(oldType, newType) {
937
- const changes = [];
938
- // Interfaces
939
- changes.push(...addedInterfaces(oldType, newType));
940
- changes.push(...removedInterfaces(oldType, newType));
941
- // Fields
942
- changes.push(...addedFields(oldType, newType));
943
- changes.push(...removedFields(oldType, newType));
944
- changedFields(oldType, newType).forEach(({ inOld, inNew }) => {
945
- changes.push(...changesInField(oldType, inOld, inNew));
946
- });
947
- return changes;
948
- }
949
- function addedInterfaces(oldType, newType) {
950
- const oldInterfaces = oldType.getInterfaces();
951
- const newInterfaces = newType.getInterfaces();
952
- const oldNames = oldInterfaces.map(i => i.name);
953
- const newNames = newInterfaces.map(i => i.name);
954
- return diffArrays(newNames, oldNames)
955
- .map(name => newInterfaces.find(i => i.name === name))
956
- .map(i => objectTypeInterfaceAdded(i, newType));
957
- }
958
- function removedInterfaces(oldType, newType) {
1157
+ function changesInObject(oldType, newType, addChange) {
959
1158
  const oldInterfaces = oldType.getInterfaces();
960
1159
  const newInterfaces = newType.getInterfaces();
961
- const oldNames = oldInterfaces.map(i => i.name);
962
- const newNames = newInterfaces.map(i => i.name);
963
- return diffArrays(oldNames, newNames)
964
- .map(name => oldInterfaces.find(i => i.name === name))
965
- .map(i => objectTypeInterfaceRemoved(i, newType));
966
- }
967
- function addedFields(oldType, newType) {
968
- const oldFields = oldType.getFields();
969
- const newFields = newType.getFields();
970
- const oldNames = Object.keys(oldFields);
971
- const newNames = Object.keys(newFields);
972
- return diffArrays(newNames, oldNames)
973
- .map(name => newFields[name])
974
- .map(f => fieldAdded(newType, f));
975
- }
976
- function removedFields(oldType, newType) {
977
1160
  const oldFields = oldType.getFields();
978
1161
  const newFields = newType.getFields();
979
- const oldNames = Object.keys(oldFields);
980
- const newNames = Object.keys(newFields);
981
- return diffArrays(oldNames, newNames)
982
- .map(name => oldFields[name])
983
- .map(f => fieldRemoved(oldType, f));
984
- }
985
- function changedFields(oldType, newType) {
986
- const oldFields = oldType.getFields();
987
- const newFields = newType.getFields();
988
- const oldNames = Object.keys(oldFields);
989
- const newNames = Object.keys(newFields);
990
- return unionArrays(oldNames, newNames).map(name => ({
991
- inOld: oldFields[name],
992
- inNew: newFields[name],
993
- }));
1162
+ compareLists(oldInterfaces, newInterfaces, {
1163
+ onAdded(i) {
1164
+ addChange(objectTypeInterfaceAdded(i, newType));
1165
+ },
1166
+ onRemoved(i) {
1167
+ addChange(objectTypeInterfaceRemoved(i, oldType));
1168
+ },
1169
+ });
1170
+ compareLists(Object.values(oldFields), Object.values(newFields), {
1171
+ onAdded(f) {
1172
+ addChange(fieldAdded(newType, f));
1173
+ },
1174
+ onRemoved(f) {
1175
+ addChange(fieldRemoved(oldType, f));
1176
+ },
1177
+ onMutual(f) {
1178
+ changesInField(oldType, f.oldVersion, f.newVersion, addChange);
1179
+ },
1180
+ });
994
1181
  }
995
1182
 
996
- function changesInInterface(oldInterface, newInterface) {
997
- const changes = [];
998
- changes.push(...addedFields$1(oldInterface, newInterface));
999
- changes.push(...removedFields$1(oldInterface, newInterface));
1000
- changedFields$1(oldInterface, newInterface).forEach(({ inOld, inNew }) => {
1001
- changes.push(...changesInField(oldInterface, inOld, inNew));
1183
+ function changesInInterface(oldInterface, newInterface, addChange) {
1184
+ compareLists(Object.values(oldInterface.getFields()), Object.values(newInterface.getFields()), {
1185
+ onAdded(field) {
1186
+ addChange(fieldAdded(newInterface, field));
1187
+ },
1188
+ onRemoved(field) {
1189
+ addChange(fieldRemoved(oldInterface, field));
1190
+ },
1191
+ onMutual(field) {
1192
+ changesInField(oldInterface, field.oldVersion, field.newVersion, addChange);
1193
+ },
1002
1194
  });
1003
- return changes;
1004
- }
1005
- function addedFields$1(oldInterface, newInterface) {
1006
- const oldFields = oldInterface.getFields();
1007
- const newFields = newInterface.getFields();
1008
- const oldNames = Object.keys(oldFields);
1009
- const newNames = Object.keys(newFields);
1010
- return diffArrays(newNames, oldNames)
1011
- .map(name => newFields[name])
1012
- .map(f => fieldAdded(newInterface, f));
1013
- }
1014
- function removedFields$1(oldInterface, newInterface) {
1015
- const oldFields = oldInterface.getFields();
1016
- const newFields = newInterface.getFields();
1017
- const oldNames = Object.keys(oldFields);
1018
- const newNames = Object.keys(newFields);
1019
- return diffArrays(oldNames, newNames)
1020
- .map(name => oldFields[name])
1021
- .map(f => fieldRemoved(oldInterface, f));
1022
- }
1023
- function changedFields$1(oldInterface, newInterface) {
1024
- const oldFields = oldInterface.getFields();
1025
- const newFields = newInterface.getFields();
1026
- const oldNames = Object.keys(oldFields);
1027
- const newNames = Object.keys(newFields);
1028
- return unionArrays(oldNames, newNames).map(name => ({
1029
- inOld: oldFields[name],
1030
- inNew: newFields[name],
1031
- }));
1032
1195
  }
1033
1196
 
1034
- function changesInDirective(oldDirective, newDirective) {
1035
- const changes = [];
1197
+ function changesInDirective(oldDirective, newDirective, addChange) {
1036
1198
  if (isNotEqual(oldDirective.description, newDirective.description)) {
1037
- changes.push(directiveDescriptionChanged(oldDirective, newDirective));
1199
+ addChange(directiveDescriptionChanged(oldDirective, newDirective));
1038
1200
  }
1201
+ const locations = {
1202
+ added: diffArrays(newDirective.locations, oldDirective.locations),
1203
+ removed: diffArrays(oldDirective.locations, newDirective.locations),
1204
+ };
1039
1205
  // locations added
1040
- changes.push(...diffArrays(newDirective.locations, oldDirective.locations).map(location => directiveLocationAdded(newDirective, location)));
1206
+ locations.added.forEach(location => addChange(directiveLocationAdded(newDirective, location)));
1041
1207
  // locations removed
1042
- changes.push(...diffArrays(oldDirective.locations, newDirective.locations).map(location => directiveLocationRemoved(oldDirective, location)));
1043
- const oldNames = oldDirective.args.map(a => a.name);
1044
- const newNames = newDirective.args.map(a => a.name);
1045
- // arguments added
1046
- changes.push(...diffArrays(newNames, oldNames).map(name => directiveArgumentAdded(newDirective, newDirective.args.find(a => a.name === name))));
1047
- // arguments removed
1048
- changes.push(...diffArrays(oldNames, newNames).map(name => directiveArgumentRemoved(oldDirective, oldDirective.args.find(a => a.name === name))));
1049
- // common arguments
1050
- unionArrays(oldNames, newNames).forEach(name => {
1051
- const oldArg = oldDirective.args.find(a => a.name === name);
1052
- const newArg = newDirective.args.find(a => a.name === name);
1053
- changes.push(...changesInDirectiveArgument(oldDirective, oldArg, newArg));
1208
+ locations.removed.forEach(location => addChange(directiveLocationRemoved(oldDirective, location)));
1209
+ compareLists(oldDirective.args, newDirective.args, {
1210
+ onAdded(arg) {
1211
+ addChange(directiveArgumentAdded(newDirective, arg));
1212
+ },
1213
+ onRemoved(arg) {
1214
+ addChange(directiveArgumentRemoved(oldDirective, arg));
1215
+ },
1216
+ onMutual(arg) {
1217
+ changesInDirectiveArgument(oldDirective, arg.oldVersion, arg.newVersion, addChange);
1218
+ },
1054
1219
  });
1055
- return changes;
1056
1220
  }
1057
- function changesInDirectiveArgument(directive, oldArg, newArg) {
1058
- const changes = [];
1221
+ function changesInDirectiveArgument(directive, oldArg, newArg, addChange) {
1059
1222
  if (isNotEqual(oldArg.description, newArg.description)) {
1060
- changes.push(directiveArgumentDescriptionChanged(directive, oldArg, newArg));
1223
+ addChange(directiveArgumentDescriptionChanged(directive, oldArg, newArg));
1061
1224
  }
1062
1225
  if (isNotEqual(oldArg.defaultValue, newArg.defaultValue)) {
1063
- changes.push(directiveArgumentDefaultValueChanged(directive, oldArg, newArg));
1226
+ addChange(directiveArgumentDefaultValueChanged(directive, oldArg, newArg));
1064
1227
  }
1065
1228
  if (isNotEqual(oldArg.type.toString(), newArg.type.toString())) {
1066
- changes.push(directiveArgumentTypeChanged(directive, oldArg, newArg));
1229
+ addChange(directiveArgumentTypeChanged(directive, oldArg, newArg));
1067
1230
  }
1068
- return changes;
1069
1231
  }
1070
1232
 
1071
1233
  function diffSchema(oldSchema, newSchema) {
1072
1234
  const changes = [];
1073
- const types = diffTypes(oldSchema, newSchema);
1074
- const directives = diffDirectives(oldSchema, newSchema);
1075
- // Added and removed types
1076
- changes.push(...types.added.map(typeAdded));
1077
- changes.push(...types.removed.map(typeRemoved));
1078
- // Added and removed directives
1079
- changes.push(...directives.added.map(directiveAdded));
1080
- changes.push(...directives.removed.map(directiveRemoved));
1081
- // Changes in Schema
1082
- changes.push(...changesInSchema(oldSchema, newSchema));
1083
- // Changes in Type
1084
- types.common.forEach(({ inOld, inNew }) => {
1085
- changes.push(...changesInType(inOld, inNew));
1235
+ function addChange(change) {
1236
+ changes.push(change);
1237
+ }
1238
+ changesInSchema(oldSchema, newSchema, addChange);
1239
+ compareLists(Object.values(oldSchema.getTypeMap()).filter(t => !isPrimitive(t)), Object.values(newSchema.getTypeMap()).filter(t => !isPrimitive(t)), {
1240
+ onAdded(type) {
1241
+ addChange(typeAdded(type));
1242
+ },
1243
+ onRemoved(type) {
1244
+ addChange(typeRemoved(type));
1245
+ },
1246
+ onMutual(type) {
1247
+ changesInType(type.oldVersion, type.newVersion, addChange);
1248
+ },
1086
1249
  });
1087
- // Changes in Directives
1088
- directives.common.forEach(({ inOld, inNew }) => {
1089
- changes.push(...changesInDirective(inOld, inNew));
1250
+ compareLists(oldSchema.getDirectives(), newSchema.getDirectives(), {
1251
+ onAdded(directive) {
1252
+ addChange(directiveAdded(directive));
1253
+ },
1254
+ onRemoved(directive) {
1255
+ addChange(directiveRemoved(directive));
1256
+ },
1257
+ onMutual(directive) {
1258
+ changesInDirective(directive.oldVersion, directive.newVersion, addChange);
1259
+ },
1090
1260
  });
1091
1261
  return changes;
1092
1262
  }
1093
- function diffTypes(oldSchema, newSchema) {
1094
- const oldTypeMap = oldSchema.getTypeMap();
1095
- const newTypeMap = newSchema.getTypeMap();
1096
- const oldTypenames = Object.keys(oldTypeMap).filter(name => !isPrimitive(name));
1097
- const newTypenames = Object.keys(newTypeMap).filter(name => !isPrimitive(name));
1098
- const added = diffArrays(newTypenames, oldTypenames).map(name => newTypeMap[name]);
1099
- const removed = diffArrays(oldTypenames, newTypenames).map(name => oldTypeMap[name]);
1100
- const common = unionArrays(oldTypenames, newTypenames).map(name => ({
1101
- inOld: oldTypeMap[name],
1102
- inNew: newTypeMap[name],
1103
- }));
1104
- return {
1105
- added,
1106
- removed,
1107
- common,
1108
- };
1109
- }
1110
- function diffDirectives(oldSchema, newSchema) {
1111
- const oldDirectives = oldSchema.getDirectives();
1112
- const newDirectives = newSchema.getDirectives();
1113
- const oldNames = oldDirectives.map(d => d.name);
1114
- const newNames = newDirectives.map(d => d.name);
1115
- const added = diffArrays(newNames, oldNames).map(name => newDirectives.find(d => d.name === name));
1116
- const removed = diffArrays(oldNames, newNames).map(name => oldDirectives.find(d => d.name === name));
1117
- const common = unionArrays(oldNames, newNames).map(name => ({
1118
- inOld: oldDirectives.find(d => d.name === name),
1119
- inNew: newDirectives.find(d => d.name === name),
1120
- }));
1121
- return {
1122
- added,
1123
- removed,
1124
- common,
1263
+ function changesInSchema(oldSchema, newSchema, addChange) {
1264
+ var _a, _b, _c, _d, _e, _f;
1265
+ const defaultNames = {
1266
+ query: 'Query',
1267
+ mutation: 'Mutation',
1268
+ subscription: 'Subscription',
1125
1269
  };
1126
- }
1127
- function changesInSchema(oldSchema, newSchema) {
1128
- const changes = [];
1129
1270
  const oldRoot = {
1130
- query: (oldSchema.getQueryType() || {}).name,
1131
- mutation: (oldSchema.getMutationType() || {}).name,
1132
- subscription: (oldSchema.getSubscriptionType() || {})
1133
- .name,
1271
+ query: (_a = (oldSchema.getQueryType() || {}).name) !== null && _a !== void 0 ? _a : defaultNames.query,
1272
+ mutation: (_b = (oldSchema.getMutationType() || {}).name) !== null && _b !== void 0 ? _b : defaultNames.mutation,
1273
+ subscription: (_c = (oldSchema.getSubscriptionType() || {}).name) !== null && _c !== void 0 ? _c : defaultNames.subscription,
1134
1274
  };
1135
1275
  const newRoot = {
1136
- query: (newSchema.getQueryType() || {}).name,
1137
- mutation: (newSchema.getMutationType() || {}).name,
1138
- subscription: (newSchema.getSubscriptionType() || {})
1139
- .name,
1276
+ query: (_d = (newSchema.getQueryType() || {}).name) !== null && _d !== void 0 ? _d : defaultNames.query,
1277
+ mutation: (_e = (newSchema.getMutationType() || {}).name) !== null && _e !== void 0 ? _e : defaultNames.mutation,
1278
+ subscription: (_f = (newSchema.getSubscriptionType() || {}).name) !== null && _f !== void 0 ? _f : defaultNames.subscription,
1140
1279
  };
1141
1280
  if (isNotEqual(oldRoot.query, newRoot.query)) {
1142
- changes.push(schemaQueryTypeChanged(oldSchema, newSchema));
1281
+ addChange(schemaQueryTypeChanged(oldSchema, newSchema));
1143
1282
  }
1144
1283
  if (isNotEqual(oldRoot.mutation, newRoot.mutation)) {
1145
- changes.push(schemaMutationTypeChanged(oldSchema, newSchema));
1284
+ addChange(schemaMutationTypeChanged(oldSchema, newSchema));
1146
1285
  }
1147
1286
  if (isNotEqual(oldRoot.subscription, newRoot.subscription)) {
1148
- changes.push(schemaSubscriptionTypeChanged(oldSchema, newSchema));
1287
+ addChange(schemaSubscriptionTypeChanged(oldSchema, newSchema));
1149
1288
  }
1150
- return changes;
1151
1289
  }
1152
- function changesInType(oldType, newType) {
1153
- let changes = [];
1290
+ function changesInType(oldType, newType, addChange) {
1154
1291
  if (isEnumType(oldType) && isEnumType(newType)) {
1155
- changes = changesInEnum(oldType, newType);
1292
+ changesInEnum(oldType, newType, addChange);
1156
1293
  }
1157
1294
  else if (isUnionType(oldType) && isUnionType(newType)) {
1158
- changes = changesInUnion(oldType, newType);
1295
+ changesInUnion(oldType, newType, addChange);
1159
1296
  }
1160
1297
  else if (isInputObjectType(oldType) && isInputObjectType(newType)) {
1161
- changes = changesInInputObject(oldType, newType);
1298
+ changesInInputObject(oldType, newType, addChange);
1162
1299
  }
1163
1300
  else if (isObjectType(oldType) && isObjectType(newType)) {
1164
- changes = changesInObject(oldType, newType);
1301
+ changesInObject(oldType, newType, addChange);
1165
1302
  }
1166
1303
  else if (isInterfaceType(oldType) && isInterfaceType(newType)) {
1167
- changes = changesInInterface(oldType, newType);
1304
+ changesInInterface(oldType, newType, addChange);
1168
1305
  }
1169
1306
  else if (isScalarType(oldType) && isScalarType(newType)) ;
1170
1307
  else {
1171
- changes = [typeKindChanged(oldType, newType)];
1308
+ addChange(typeKindChanged(oldType, newType));
1172
1309
  }
1173
1310
  if (isNotEqual(oldType.description, newType.description)) {
1174
1311
  if (isVoid(oldType.description)) {
1175
- changes.push(typeDescriptionAdded(newType));
1312
+ addChange(typeDescriptionAdded(newType));
1176
1313
  }
1177
1314
  else if (isVoid(newType.description)) {
1178
- changes.push(typeDescriptionRemoved(oldType));
1315
+ addChange(typeDescriptionRemoved(oldType));
1179
1316
  }
1180
1317
  else {
1181
- changes.push(typeDescriptionChanged(oldType, newType));
1318
+ addChange(typeDescriptionChanged(oldType, newType));
1182
1319
  }
1183
1320
  }
1184
- return changes;
1185
1321
  }
1186
1322
 
1323
+ const dangerousBreaking = ({ changes }) => {
1324
+ return changes.map(change => {
1325
+ if (change.criticality.level === CriticalityLevel.Dangerous) {
1326
+ return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: CriticalityLevel.Breaking }) });
1327
+ }
1328
+ return change;
1329
+ });
1330
+ };
1331
+
1187
1332
  function parsePath(path) {
1188
1333
  return path.split('.');
1189
1334
  }
1190
1335
 
1191
- const suppressRemovalOfDeprecatedField = ({ changes, oldSchema, }) => {
1336
+ const suppressRemovalOfDeprecatedField = ({ changes, oldSchema }) => {
1192
1337
  return changes.map(change => {
1193
1338
  if (change.type === ChangeType.FieldRemoved &&
1194
1339
  change.criticality.level === CriticalityLevel.Breaking &&
@@ -1197,7 +1342,31 @@ const suppressRemovalOfDeprecatedField = ({ changes, oldSchema, }) => {
1197
1342
  const type = oldSchema.getType(typeName);
1198
1343
  if (isObjectType(type) || isInterfaceType(type)) {
1199
1344
  const field = type.getFields()[fieldName];
1200
- if (field.isDeprecated) {
1345
+ if (isDeprecated(field)) {
1346
+ return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: CriticalityLevel.Dangerous }) });
1347
+ }
1348
+ }
1349
+ }
1350
+ if (change.type === ChangeType.EnumValueRemoved &&
1351
+ change.criticality.level === CriticalityLevel.Breaking &&
1352
+ change.path) {
1353
+ const [enumName, enumItem] = parsePath(change.path);
1354
+ const type = oldSchema.getType(enumName);
1355
+ if (isEnumType(type)) {
1356
+ const item = type.getValue(enumItem);
1357
+ if (item && isDeprecated(item)) {
1358
+ return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: CriticalityLevel.Dangerous }) });
1359
+ }
1360
+ }
1361
+ }
1362
+ if (change.type === ChangeType.InputFieldRemoved &&
1363
+ change.criticality.level === CriticalityLevel.Breaking &&
1364
+ change.path) {
1365
+ const [inputName, inputItem] = parsePath(change.path);
1366
+ const type = oldSchema.getType(inputName);
1367
+ if (isInputObjectType(type)) {
1368
+ const item = type.getFields()[inputItem];
1369
+ if (item && isDeprecated(item)) {
1201
1370
  return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: CriticalityLevel.Dangerous }) });
1202
1371
  }
1203
1372
  }
@@ -1223,20 +1392,73 @@ const ignoreDescriptionChanges = ({ changes }) => {
1223
1392
  return changes.filter(change => descriptionChangeTypes.indexOf(change.type) === -1);
1224
1393
  };
1225
1394
 
1395
+ const considerUsage = ({ changes, config }) => __awaiter(void 0, void 0, void 0, function* () {
1396
+ if (!config) {
1397
+ throw new Error(`considerUsage rule is missing config`);
1398
+ }
1399
+ const collectedBreakingField = [];
1400
+ changes.forEach(change => {
1401
+ if (change.criticality.level === CriticalityLevel.Breaking && change.path) {
1402
+ const [typeName, fieldName, argumentName] = parsePath(change.path);
1403
+ collectedBreakingField.push({
1404
+ type: typeName,
1405
+ field: fieldName,
1406
+ argument: argumentName,
1407
+ });
1408
+ }
1409
+ });
1410
+ // True if safe to break, false otherwise
1411
+ const usageList = yield config.checkUsage(collectedBreakingField);
1412
+ // turns an array of booleans into an array of `Type.Field` strings
1413
+ // includes only those that are safe to break the api
1414
+ const suppressedPaths = collectedBreakingField
1415
+ .filter((_, i) => usageList[i] === true)
1416
+ .map(({ type, field, argument }) => [type, field, argument].filter(Boolean).join('.'));
1417
+ return changes.map(change => {
1418
+ // Turns those "safe to break" changes into "dangerous"
1419
+ if (change.criticality.level === CriticalityLevel.Breaking &&
1420
+ change.path &&
1421
+ suppressedPaths.some(p => change.path.startsWith(p))) {
1422
+ return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: CriticalityLevel.Dangerous }), message: `${change.message} (non-breaking based on usage)` });
1423
+ }
1424
+ return change;
1425
+ });
1426
+ });
1427
+
1428
+ const safeUnreachable = ({ changes, oldSchema }) => {
1429
+ const reachable = getReachableTypes(oldSchema);
1430
+ return changes.map(change => {
1431
+ if (change.criticality.level === CriticalityLevel.Breaking && change.path) {
1432
+ const [typeName] = parsePath(change.path);
1433
+ if (!reachable.has(typeName)) {
1434
+ return Object.assign(Object.assign({}, change), { criticality: Object.assign(Object.assign({}, change.criticality), { level: CriticalityLevel.NonBreaking }), message: 'Unreachable from root' });
1435
+ }
1436
+ }
1437
+ return change;
1438
+ });
1439
+ };
1440
+
1226
1441
  const rules = /*#__PURE__*/Object.freeze({
1227
1442
  __proto__: null,
1443
+ dangerousBreaking: dangerousBreaking,
1228
1444
  suppressRemovalOfDeprecatedField: suppressRemovalOfDeprecatedField,
1229
- ignoreDescriptionChanges: ignoreDescriptionChanges
1445
+ ignoreDescriptionChanges: ignoreDescriptionChanges,
1446
+ considerUsage: considerUsage,
1447
+ safeUnreachable: safeUnreachable
1230
1448
  });
1231
1449
 
1232
1450
  const DiffRule = rules;
1233
- function diff(oldSchema, newSchema, rules = []) {
1451
+ function diff(oldSchema, newSchema, rules = [], config) {
1234
1452
  const changes = diffSchema(oldSchema, newSchema);
1235
- return rules.reduce((prev, rule) => rule({
1236
- changes: prev,
1237
- oldSchema,
1238
- newSchema,
1239
- }), changes);
1453
+ return rules.reduce((prev, rule) => __awaiter(this, void 0, void 0, function* () {
1454
+ const prevChanges = yield prev;
1455
+ return rule({
1456
+ changes: prevChanges,
1457
+ oldSchema,
1458
+ newSchema,
1459
+ config,
1460
+ });
1461
+ }), Promise.resolve(changes));
1240
1462
  }
1241
1463
 
1242
1464
  function readDocument(source) {
@@ -1355,13 +1577,26 @@ function calculateDepth({ node, currentDepth, maxDepth, getFragment, }) {
1355
1577
  }
1356
1578
  }
1357
1579
  }
1580
+ function countDepth(node, parentDepth, getFragmentReference) {
1581
+ let depth = parentDepth;
1582
+ if ('selectionSet' in node && node.selectionSet) {
1583
+ for (let child of node.selectionSet.selections) {
1584
+ depth = Math.max(depth, countDepth(child, parentDepth + 1, getFragmentReference));
1585
+ }
1586
+ }
1587
+ if (node.kind == Kind.FRAGMENT_SPREAD) {
1588
+ const fragment = getFragmentReference(node.name.value);
1589
+ if (fragment) {
1590
+ depth = Math.max(depth, countDepth(fragment, parentDepth + 1, getFragmentReference));
1591
+ }
1592
+ }
1593
+ return depth;
1594
+ }
1358
1595
 
1359
1596
  function transformDocumentWithApollo(doc, { keepClientFields }) {
1360
1597
  return visit(doc, {
1361
1598
  Field(node) {
1362
- return keepClientFields
1363
- ? removeDirectives(node, ['client'])
1364
- : removeFieldIfDirectives(node, ['client']);
1599
+ return keepClientFields ? removeDirectives(node, ['client']) : removeFieldIfDirectives(node, ['client']);
1365
1600
  },
1366
1601
  });
1367
1602
  }
@@ -1371,6 +1606,68 @@ function transformSchemaWithApollo(schema) {
1371
1606
  `));
1372
1607
  }
1373
1608
 
1609
+ function validateAliasCount({ source, doc, maxAliasCount, fragmentGraph, }) {
1610
+ const getFragmentByFragmentName = (fragmentName) => fragmentGraph.getNodeData(fragmentName);
1611
+ for (const definition of doc.definitions) {
1612
+ if (definition.kind !== Kind.OPERATION_DEFINITION) {
1613
+ continue;
1614
+ }
1615
+ const aliasCount = countAliases(definition, getFragmentByFragmentName);
1616
+ if (aliasCount > maxAliasCount) {
1617
+ return new GraphQLError(`Too many aliases (${aliasCount}). Maximum allowed is ${maxAliasCount}`, [definition], source, definition.loc && definition.loc.start ? [definition.loc.start] : undefined);
1618
+ }
1619
+ }
1620
+ }
1621
+ function countAliases(node, getFragmentByName) {
1622
+ let aliases = 0;
1623
+ if ('alias' in node && node.alias) {
1624
+ ++aliases;
1625
+ }
1626
+ if ('selectionSet' in node && node.selectionSet) {
1627
+ for (let child of node.selectionSet.selections) {
1628
+ aliases += countAliases(child, getFragmentByName);
1629
+ }
1630
+ }
1631
+ else if (node.kind === Kind.FRAGMENT_SPREAD) {
1632
+ const fragmentNode = getFragmentByName(node.name.value);
1633
+ if (fragmentNode) {
1634
+ aliases += countAliases(fragmentNode, getFragmentByName);
1635
+ }
1636
+ }
1637
+ return aliases;
1638
+ }
1639
+
1640
+ function validateDirectiveCount({ source, doc, maxDirectiveCount, fragmentGraph, }) {
1641
+ const getFragmentByFragmentName = (fragmentName) => fragmentGraph.getNodeData(fragmentName);
1642
+ for (const definition of doc.definitions) {
1643
+ if (definition.kind !== Kind.OPERATION_DEFINITION) {
1644
+ continue;
1645
+ }
1646
+ const directiveCount = countDirectives(definition, getFragmentByFragmentName);
1647
+ if (directiveCount > maxDirectiveCount) {
1648
+ return new GraphQLError(`Too many directives (${directiveCount}). Maximum allowed is ${maxDirectiveCount}`, [definition], source, definition.loc && definition.loc.start ? [definition.loc.start] : undefined);
1649
+ }
1650
+ }
1651
+ }
1652
+ function countDirectives(node, getFragmentByName) {
1653
+ let directives = 0;
1654
+ if (node.directives) {
1655
+ directives += node.directives.length;
1656
+ }
1657
+ if ('selectionSet' in node && node.selectionSet) {
1658
+ for (let child of node.selectionSet.selections) {
1659
+ directives += countDirectives(child, getFragmentByName);
1660
+ }
1661
+ }
1662
+ if (node.kind == Kind.FRAGMENT_SPREAD) {
1663
+ const fragment = getFragmentByName(node.name.value);
1664
+ if (fragment) {
1665
+ directives += countDirectives(fragment, getFragmentByName);
1666
+ }
1667
+ }
1668
+ return directives;
1669
+ }
1670
+
1374
1671
  function validate(schema, sources, options) {
1375
1672
  const config = Object.assign({ strictDeprecated: true, strictFragments: true, keepClientFields: false, apollo: false }, options);
1376
1673
  const invalidDocuments = [];
@@ -1400,7 +1697,7 @@ function validate(schema, sources, options) {
1400
1697
  .filter(doc => doc.hasOperations)
1401
1698
  .forEach(doc => {
1402
1699
  const docWithOperations = {
1403
- kind: 'Document',
1700
+ kind: Kind.DOCUMENT,
1404
1701
  definitions: doc.operations.map(d => d.node),
1405
1702
  };
1406
1703
  const extractedFragments = (extractFragments(print(docWithOperations)) || [])
@@ -1411,12 +1708,10 @@ function validate(schema, sources, options) {
1411
1708
  // remove duplicates
1412
1709
  .filter((def, i, all) => all.findIndex(item => item.name.value === def.name.value) === i);
1413
1710
  const merged = {
1414
- kind: 'Document',
1711
+ kind: Kind.DOCUMENT,
1415
1712
  definitions: [...docWithOperations.definitions, ...extractedFragments],
1416
1713
  };
1417
- const transformedSchema = config.apollo
1418
- ? transformSchemaWithApollo(schema)
1419
- : schema;
1714
+ let transformedSchema = config.apollo ? transformSchemaWithApollo(schema) : schema;
1420
1715
  const transformedDoc = config.apollo
1421
1716
  ? transformDocumentWithApollo(merged, {
1422
1717
  keepClientFields: config.keepClientFields,
@@ -1434,12 +1729,30 @@ function validate(schema, sources, options) {
1434
1729
  errors.push(depthError);
1435
1730
  }
1436
1731
  }
1437
- const deprecated = config.strictDeprecated
1438
- ? findDeprecatedUsages(transformedSchema, parse(doc.source.body))
1439
- : [];
1440
- const duplicatedFragments = config.strictFragments
1441
- ? findDuplicatedFragments(fragmentNames)
1442
- : [];
1732
+ if (config.maxAliasCount) {
1733
+ const aliasError = validateAliasCount({
1734
+ source: doc.source,
1735
+ doc: transformedDoc,
1736
+ maxAliasCount: config.maxAliasCount,
1737
+ fragmentGraph: graph,
1738
+ });
1739
+ if (aliasError) {
1740
+ errors.push(aliasError);
1741
+ }
1742
+ }
1743
+ if (config.maxDirectiveCount) {
1744
+ const directiveError = validateDirectiveCount({
1745
+ source: doc.source,
1746
+ doc: transformedDoc,
1747
+ maxDirectiveCount: config.maxDirectiveCount,
1748
+ fragmentGraph: graph,
1749
+ });
1750
+ if (directiveError) {
1751
+ errors.push(directiveError);
1752
+ }
1753
+ }
1754
+ const deprecated = config.strictDeprecated ? findDeprecatedUsages(transformedSchema, transformedDoc) : [];
1755
+ const duplicatedFragments = config.strictFragments ? findDuplicatedFragments(fragmentNames) : [];
1443
1756
  if (sumLengths(errors, duplicatedFragments, deprecated) > 0) {
1444
1757
  invalidDocuments.push({
1445
1758
  source: doc.source,
@@ -1462,10 +1775,7 @@ function findDuplicatedFragments(fragmentNames) {
1462
1775
  function resolveFragment(fragment, graph) {
1463
1776
  return graph
1464
1777
  .dependenciesOf(fragment.name.value)
1465
- .reduce((list, current) => [
1466
- ...list,
1467
- ...resolveFragment(graph.getNodeData(current), graph),
1468
- ], [fragment]);
1778
+ .reduce((list, current) => [...list, ...resolveFragment(graph.getNodeData(current), graph)], [fragment]);
1469
1779
  }
1470
1780
  function extractFragments(document) {
1471
1781
  return (document.match(/[\.]{3}[a-z0-9\_]+\b/gi) || []).map(name => name.replace('...', ''));
@@ -1474,70 +1784,6 @@ function sumLengths(...arrays) {
1474
1784
  return arrays.reduce((sum, { length }) => sum + length, 0);
1475
1785
  }
1476
1786
 
1477
- function compareTwoStrings(str1, str2) {
1478
- if (!str1.length && !str2.length)
1479
- return 1;
1480
- if (!str1.length || !str2.length)
1481
- return 0;
1482
- if (str1.toUpperCase() === str2.toUpperCase())
1483
- return 1;
1484
- if (str1.length === 1 && str2.length === 1)
1485
- return 0;
1486
- const pairs1 = wordLetterPairs(str1);
1487
- const pairs2 = wordLetterPairs(str2);
1488
- const union = pairs1.length + pairs2.length;
1489
- let intersection = 0;
1490
- pairs1.forEach(pair1 => {
1491
- for (let i = 0, pair2; (pair2 = pairs2[i]); i++) {
1492
- if (pair1 !== pair2)
1493
- continue;
1494
- intersection++;
1495
- pairs2.splice(i, 1);
1496
- break;
1497
- }
1498
- });
1499
- return (intersection * 2) / union;
1500
- }
1501
- function findBestMatch(mainString, targetStrings) {
1502
- if (!areArgsValid(mainString, targetStrings))
1503
- throw new Error('Bad arguments: First argument should be a string, second should be an array of strings');
1504
- const ratings = targetStrings.map(target => ({
1505
- target,
1506
- rating: compareTwoStrings(mainString, target.value),
1507
- }));
1508
- const bestMatch = Array.from(ratings).sort((a, b) => b.rating - a.rating)[0];
1509
- return { ratings, bestMatch };
1510
- }
1511
- function flattenDeep(arr) {
1512
- return Array.isArray(arr)
1513
- ? arr.reduce((a, b) => a.concat(flattenDeep(b)), [])
1514
- : [arr];
1515
- }
1516
- function areArgsValid(mainString, targetStrings) {
1517
- if (typeof mainString !== 'string')
1518
- return false;
1519
- if (!Array.isArray(targetStrings))
1520
- return false;
1521
- if (!targetStrings.length)
1522
- return false;
1523
- if (targetStrings.find(s => typeof s.value !== 'string'))
1524
- return false;
1525
- return true;
1526
- }
1527
- function letterPairs(str) {
1528
- const pairs = [];
1529
- for (let i = 0, max = str.length - 1; i < max; i++)
1530
- pairs[i] = str.substring(i, i + 2);
1531
- return pairs;
1532
- }
1533
- function wordLetterPairs(str) {
1534
- const pairs = str
1535
- .toUpperCase()
1536
- .split(' ')
1537
- .map(letterPairs);
1538
- return flattenDeep(pairs);
1539
- }
1540
-
1541
1787
  function similar(schema, typeName, threshold = 0.4) {
1542
1788
  const typeMap = schema.getTypeMap();
1543
1789
  const targets = Object.keys(schema.getTypeMap())
@@ -1547,14 +1793,13 @@ function similar(schema, typeName, threshold = 0.4) {
1547
1793
  value: stripType(typeMap[name]),
1548
1794
  }));
1549
1795
  const results = {};
1550
- if (typeof typeName !== 'undefined' &&
1551
- !targets.some(t => t.typeId === typeName)) {
1796
+ if (typeof typeName !== 'undefined' && !targets.some(t => t.typeId === typeName)) {
1552
1797
  throw new Error(`Type '${typeName}' doesn't exist`);
1553
1798
  }
1554
1799
  (typeName ? [{ typeId: typeName, value: '' }] : targets).forEach(source => {
1555
1800
  const sourceType = schema.getType(source.typeId);
1556
- const matchWith = targets.filter(target => schema.getType(target.typeId).astNode.kind ===
1557
- sourceType.astNode.kind && target.typeId !== source.typeId);
1801
+ const matchWith = targets.filter(target => schema.getType(target.typeId).astNode.kind === sourceType.astNode.kind &&
1802
+ target.typeId !== source.typeId);
1558
1803
  if (matchWith.length > 0) {
1559
1804
  const found = similarTo(sourceType, matchWith, threshold);
1560
1805
  if (found) {
@@ -1608,10 +1853,24 @@ function coverage(schema, sources) {
1608
1853
  fieldDef.name &&
1609
1854
  fieldDef.name !== '__typename' &&
1610
1855
  fieldDef.name !== '__schema') {
1611
- const locations = coverage.types[parent.name].children[fieldDef.name].locations[source.name];
1612
- coverage.types[parent.name].hits++;
1613
- coverage.types[parent.name].children[fieldDef.name].locations[source.name] = [node.loc].concat(locations || []);
1614
- coverage.types[parent.name].children[fieldDef.name].hits++;
1856
+ const sourceName = source.name;
1857
+ const typeCoverage = coverage.types[parent.name];
1858
+ const fieldCoverage = typeCoverage.children[fieldDef.name];
1859
+ const locations = fieldCoverage.locations[sourceName];
1860
+ typeCoverage.hits++;
1861
+ fieldCoverage.hits++;
1862
+ if (node.loc) {
1863
+ fieldCoverage.locations[sourceName] = [node.loc, ...(locations || [])];
1864
+ }
1865
+ if (node.arguments) {
1866
+ for (const argNode of node.arguments) {
1867
+ const argCoverage = fieldCoverage.children[argNode.name.value];
1868
+ argCoverage.hits++;
1869
+ if (argNode.loc) {
1870
+ argCoverage.locations[sourceName] = [argNode.loc, ...(argCoverage.locations[sourceName] || [])];
1871
+ }
1872
+ }
1873
+ }
1615
1874
  }
1616
1875
  },
1617
1876
  });
@@ -1630,7 +1889,14 @@ function coverage(schema, sources) {
1630
1889
  typeCoverage.children[field.name] = {
1631
1890
  hits: 0,
1632
1891
  locations: {},
1892
+ children: {},
1633
1893
  };
1894
+ for (const arg of field.args) {
1895
+ typeCoverage.children[field.name].children[arg.name] = {
1896
+ hits: 0,
1897
+ locations: {},
1898
+ };
1899
+ }
1634
1900
  }
1635
1901
  coverage.types[type.name] = typeCoverage;
1636
1902
  }
@@ -1649,5 +1915,4 @@ function coverage(schema, sources) {
1649
1915
  return coverage;
1650
1916
  }
1651
1917
 
1652
- export { ChangeType, CriticalityLevel, DiffRule, coverage, diff, getTypePrefix, similar, validate };
1653
- //# sourceMappingURL=index.esm.js.map
1918
+ export { ChangeType, CriticalityLevel, DiffRule, countAliases, countDepth, countDirectives, coverage, diff, getTypePrefix, similar, validate };