@graphql-inspector/core 4.1.0 → 4.1.1-alpha-20230418154415-aa03cdf5

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.
@@ -13,7 +13,7 @@ function readDocument(source) {
13
13
  const documentNode = (0, graphql_1.parse)(source.body);
14
14
  const filepath = source.name;
15
15
  const definitions = documentNode.definitions || [];
16
- definitions.forEach((node) => {
16
+ for (const node of definitions) {
17
17
  if (isOperation(node)) {
18
18
  result.operations.push({
19
19
  node,
@@ -26,7 +26,7 @@ function readDocument(source) {
26
26
  source: filepath,
27
27
  });
28
28
  }
29
- });
29
+ }
30
30
  result.hasFragments = result.fragments.length > 0;
31
31
  result.hasOperations = result.operations.length > 0;
32
32
  return result;
@@ -86,22 +86,22 @@ function coverage(schema, sources) {
86
86
  }
87
87
  }
88
88
  const documents = coverage.sources.map(document_js_1.readDocument);
89
- documents.forEach((doc, i) => {
89
+ for (const [i, doc] of documents.entries()) {
90
90
  const source = coverage.sources[i];
91
- doc.operations.forEach(op => {
91
+ for (const op of doc.operations) {
92
92
  (0, graphql_1.visit)(op.node, (0, graphql_1.visitWithTypeInfo)(typeInfo, visitor(source)));
93
- });
94
- doc.fragments.forEach(fr => {
93
+ }
94
+ for (const fr of doc.fragments) {
95
95
  (0, graphql_1.visit)(fr.node, (0, graphql_1.visitWithTypeInfo)(typeInfo, visitor(source)));
96
- });
97
- });
96
+ }
97
+ }
98
98
  for (const key in coverage.types) {
99
99
  const me = coverage.types[key];
100
100
  processStats(me);
101
101
  coverage.stats.numTypes++;
102
102
  if (me.fieldsCountCovered > 0)
103
103
  coverage.stats.numTypesCovered++;
104
- if (me.fieldsCount == me.fieldsCountCovered)
104
+ if (me.fieldsCount === me.fieldsCountCovered)
105
105
  coverage.stats.numTypesCoveredFully++;
106
106
  coverage.stats.numFields += me.fieldsCount;
107
107
  coverage.stats.numFiledsCovered += me.fieldsCountCovered;
@@ -12,9 +12,11 @@ function changesInDirective(oldDirective, newDirective, addChange) {
12
12
  removed: (0, compare_js_1.diffArrays)(oldDirective.locations, newDirective.locations),
13
13
  };
14
14
  // locations added
15
- locations.added.forEach(location => addChange((0, directive_js_1.directiveLocationAdded)(newDirective, location)));
15
+ for (const location of locations.added)
16
+ addChange((0, directive_js_1.directiveLocationAdded)(newDirective, location));
16
17
  // locations removed
17
- locations.removed.forEach(location => addChange((0, directive_js_1.directiveLocationRemoved)(oldDirective, location)));
18
+ for (const location of locations.removed)
19
+ addChange((0, directive_js_1.directiveLocationRemoved)(oldDirective, location));
18
20
  (0, compare_js_1.compareLists)(oldDirective.args, newDirective.args, {
19
21
  onAdded(arg) {
20
22
  addChange((0, directive_js_1.directiveArgumentAdded)(newDirective, arg));
@@ -9,7 +9,7 @@ const considerUsage = ({ changes, config }) => tslib_1.__awaiter(void 0, void 0,
9
9
  throw new Error(`considerUsage rule is missing config`);
10
10
  }
11
11
  const collectedBreakingField = [];
12
- changes.forEach(change => {
12
+ for (const change of changes) {
13
13
  if (change.criticality.level === change_js_1.CriticalityLevel.Breaking && change.path) {
14
14
  const [typeName, fieldName, argumentName] = (0, path_js_1.parsePath)(change.path);
15
15
  collectedBreakingField.push({
@@ -18,7 +18,7 @@ const considerUsage = ({ changes, config }) => tslib_1.__awaiter(void 0, void 0,
18
18
  argument: argumentName,
19
19
  });
20
20
  }
21
- });
21
+ }
22
22
  // True if safe to break, false otherwise
23
23
  const usageList = yield config.checkUsage(collectedBreakingField);
24
24
  // turns an array of booleans into an array of `Type.Field` strings
@@ -16,7 +16,7 @@ function similar(schema, typeName, threshold = 0.4) {
16
16
  if (typeof typeName !== 'undefined' && !targets.some(t => t.typeId === typeName)) {
17
17
  throw new Error(`Type '${typeName}' doesn't exist`);
18
18
  }
19
- (typeName ? [{ typeId: typeName, value: '' }] : targets).forEach(source => {
19
+ for (const source of typeName ? [{ typeId: typeName, value: '' }] : targets) {
20
20
  const sourceType = schema.getType(source.typeId);
21
21
  const matchWith = targets.filter(target => schema.getType(target.typeId).astNode.kind === sourceType.astNode.kind &&
22
22
  target.typeId !== source.typeId);
@@ -26,7 +26,7 @@ function similar(schema, typeName, threshold = 0.4) {
26
26
  results[source.typeId] = found;
27
27
  }
28
28
  }
29
- });
29
+ }
30
30
  return results;
31
31
  }
32
32
  exports.similar = similar;
@@ -73,13 +73,19 @@ function compareLists(oldList, newList, callbacks) {
73
73
  }
74
74
  if (callbacks) {
75
75
  if (callbacks.onAdded) {
76
- added.forEach(callbacks.onAdded);
76
+ for (const item of added) {
77
+ callbacks.onAdded(item);
78
+ }
77
79
  }
78
80
  if (callbacks.onRemoved) {
79
- removed.forEach(callbacks.onRemoved);
81
+ for (const item of removed) {
82
+ callbacks.onRemoved(item);
83
+ }
80
84
  }
81
85
  if (callbacks.onMutual) {
82
- mutual.forEach(callbacks.onMutual);
86
+ for (const item of mutual) {
87
+ callbacks.onMutual(item);
88
+ }
83
89
  }
84
90
  }
85
91
  return {
@@ -16,7 +16,7 @@ function compareTwoStrings(str1, str2) {
16
16
  const pairs2 = wordLetterPairs(str2);
17
17
  const union = pairs1.length + pairs2.length;
18
18
  let intersection = 0;
19
- pairs1.forEach(pair1 => {
19
+ for (const pair1 of pairs1) {
20
20
  for (let i = 0, pair2; (pair2 = pairs2[i]); i++) {
21
21
  if (pair1 !== pair2)
22
22
  continue;
@@ -24,7 +24,7 @@ function compareTwoStrings(str1, str2) {
24
24
  pairs2.splice(i, 1);
25
25
  break;
26
26
  }
27
- });
27
+ }
28
28
  return (intersection * 2) / union;
29
29
  }
30
30
  function findBestMatch(mainString, targetStrings) {
@@ -26,7 +26,7 @@ function calculateOperationComplexity(node, config, getFragmentByName, depth = 0
26
26
  calculateOperationComplexity(child, config, getFragmentByName, depth + 1);
27
27
  }
28
28
  }
29
- if (node.kind == graphql_1.Kind.FRAGMENT_SPREAD) {
29
+ if (node.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
30
30
  const fragment = getFragmentByName(node.name.value);
31
31
  if (fragment) {
32
32
  cost +=
@@ -26,7 +26,7 @@ function countDirectives(node, getFragmentByName) {
26
26
  directives += countDirectives(child, getFragmentByName);
27
27
  }
28
28
  }
29
- if (node.kind == graphql_1.Kind.FRAGMENT_SPREAD) {
29
+ if (node.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
30
30
  const fragment = getFragmentByName(node.name.value);
31
31
  if (fragment) {
32
32
  directives += countDirectives(fragment, getFragmentByName);
@@ -19,25 +19,24 @@ function validate(schema, sources, options) {
19
19
  const fragments = [];
20
20
  const fragmentNames = [];
21
21
  const graph = new dependency_graph_1.DepGraph({ circular: true });
22
- documents.forEach(doc => {
23
- doc.fragments.forEach(fragment => {
22
+ for (const doc of documents) {
23
+ for (const fragment of doc.fragments) {
24
24
  fragmentNames.push(fragment.node.name.value);
25
25
  fragments.push(fragment);
26
26
  graph.addNode(fragment.node.name.value, fragment.node);
27
- });
28
- });
29
- fragments.forEach(fragment => {
27
+ }
28
+ }
29
+ for (const fragment of fragments) {
30
30
  const depends = extractFragments((0, graphql_1.print)(fragment.node));
31
31
  if (depends) {
32
- depends.forEach(name => {
32
+ for (const name of depends) {
33
33
  graph.addDependency(fragment.node.name.value, name);
34
- });
34
+ }
35
35
  }
36
- });
37
- documents
36
+ }
37
+ for (const doc of documents
38
38
  // since we include fragments, validate only operations
39
- .filter(doc => doc.hasOperations)
40
- .forEach(doc => {
39
+ .filter(doc => doc.hasOperations)) {
41
40
  const docWithOperations = {
42
41
  kind: graphql_1.Kind.DOCUMENT,
43
42
  definitions: doc.operations.map(d => d.node),
@@ -117,7 +116,7 @@ function validate(schema, sources, options) {
117
116
  deprecated,
118
117
  });
119
118
  }
120
- });
119
+ }
121
120
  return invalidDocuments;
122
121
  }
123
122
  exports.validate = validate;
@@ -92,7 +92,7 @@ function countDepth(node, parentDepth, getFragmentReference) {
92
92
  depth = Math.max(depth, countDepth(child, parentDepth + 1, getFragmentReference));
93
93
  }
94
94
  }
95
- if (node.kind == graphql_1.Kind.FRAGMENT_SPREAD) {
95
+ if (node.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
96
96
  const fragment = getFragmentReference(node.name.value);
97
97
  if (fragment) {
98
98
  depth = Math.max(depth, countDepth(fragment, parentDepth + 1, getFragmentReference));
@@ -10,7 +10,7 @@ export function readDocument(source) {
10
10
  const documentNode = parse(source.body);
11
11
  const filepath = source.name;
12
12
  const definitions = documentNode.definitions || [];
13
- definitions.forEach((node) => {
13
+ for (const node of definitions) {
14
14
  if (isOperation(node)) {
15
15
  result.operations.push({
16
16
  node,
@@ -23,7 +23,7 @@ export function readDocument(source) {
23
23
  source: filepath,
24
24
  });
25
25
  }
26
- });
26
+ }
27
27
  result.hasFragments = result.fragments.length > 0;
28
28
  result.hasOperations = result.operations.length > 0;
29
29
  return result;
@@ -83,22 +83,22 @@ export function coverage(schema, sources) {
83
83
  }
84
84
  }
85
85
  const documents = coverage.sources.map(readDocument);
86
- documents.forEach((doc, i) => {
86
+ for (const [i, doc] of documents.entries()) {
87
87
  const source = coverage.sources[i];
88
- doc.operations.forEach(op => {
88
+ for (const op of doc.operations) {
89
89
  visit(op.node, visitWithTypeInfo(typeInfo, visitor(source)));
90
- });
91
- doc.fragments.forEach(fr => {
90
+ }
91
+ for (const fr of doc.fragments) {
92
92
  visit(fr.node, visitWithTypeInfo(typeInfo, visitor(source)));
93
- });
94
- });
93
+ }
94
+ }
95
95
  for (const key in coverage.types) {
96
96
  const me = coverage.types[key];
97
97
  processStats(me);
98
98
  coverage.stats.numTypes++;
99
99
  if (me.fieldsCountCovered > 0)
100
100
  coverage.stats.numTypesCovered++;
101
- if (me.fieldsCount == me.fieldsCountCovered)
101
+ if (me.fieldsCount === me.fieldsCountCovered)
102
102
  coverage.stats.numTypesCoveredFully++;
103
103
  coverage.stats.numFields += me.fieldsCount;
104
104
  coverage.stats.numFiledsCovered += me.fieldsCountCovered;
@@ -9,9 +9,11 @@ export function changesInDirective(oldDirective, newDirective, addChange) {
9
9
  removed: diffArrays(oldDirective.locations, newDirective.locations),
10
10
  };
11
11
  // locations added
12
- locations.added.forEach(location => addChange(directiveLocationAdded(newDirective, location)));
12
+ for (const location of locations.added)
13
+ addChange(directiveLocationAdded(newDirective, location));
13
14
  // locations removed
14
- locations.removed.forEach(location => addChange(directiveLocationRemoved(oldDirective, location)));
15
+ for (const location of locations.removed)
16
+ addChange(directiveLocationRemoved(oldDirective, location));
15
17
  compareLists(oldDirective.args, newDirective.args, {
16
18
  onAdded(arg) {
17
19
  addChange(directiveArgumentAdded(newDirective, arg));
@@ -6,7 +6,7 @@ export const considerUsage = ({ changes, config }) => __awaiter(void 0, void 0,
6
6
  throw new Error(`considerUsage rule is missing config`);
7
7
  }
8
8
  const collectedBreakingField = [];
9
- changes.forEach(change => {
9
+ for (const change of changes) {
10
10
  if (change.criticality.level === CriticalityLevel.Breaking && change.path) {
11
11
  const [typeName, fieldName, argumentName] = parsePath(change.path);
12
12
  collectedBreakingField.push({
@@ -15,7 +15,7 @@ export const considerUsage = ({ changes, config }) => __awaiter(void 0, void 0,
15
15
  argument: argumentName,
16
16
  });
17
17
  }
18
- });
18
+ }
19
19
  // True if safe to break, false otherwise
20
20
  const usageList = yield config.checkUsage(collectedBreakingField);
21
21
  // turns an array of booleans into an array of `Type.Field` strings
@@ -13,7 +13,7 @@ export function similar(schema, typeName, threshold = 0.4) {
13
13
  if (typeof typeName !== 'undefined' && !targets.some(t => t.typeId === typeName)) {
14
14
  throw new Error(`Type '${typeName}' doesn't exist`);
15
15
  }
16
- (typeName ? [{ typeId: typeName, value: '' }] : targets).forEach(source => {
16
+ for (const source of typeName ? [{ typeId: typeName, value: '' }] : targets) {
17
17
  const sourceType = schema.getType(source.typeId);
18
18
  const matchWith = targets.filter(target => schema.getType(target.typeId).astNode.kind === sourceType.astNode.kind &&
19
19
  target.typeId !== source.typeId);
@@ -23,7 +23,7 @@ export function similar(schema, typeName, threshold = 0.4) {
23
23
  results[source.typeId] = found;
24
24
  }
25
25
  }
26
- });
26
+ }
27
27
  return results;
28
28
  }
29
29
  function similarTo(type, targets, threshold) {
@@ -65,13 +65,19 @@ export function compareLists(oldList, newList, callbacks) {
65
65
  }
66
66
  if (callbacks) {
67
67
  if (callbacks.onAdded) {
68
- added.forEach(callbacks.onAdded);
68
+ for (const item of added) {
69
+ callbacks.onAdded(item);
70
+ }
69
71
  }
70
72
  if (callbacks.onRemoved) {
71
- removed.forEach(callbacks.onRemoved);
73
+ for (const item of removed) {
74
+ callbacks.onRemoved(item);
75
+ }
72
76
  }
73
77
  if (callbacks.onMutual) {
74
- mutual.forEach(callbacks.onMutual);
78
+ for (const item of mutual) {
79
+ callbacks.onMutual(item);
80
+ }
75
81
  }
76
82
  }
77
83
  return {
@@ -12,7 +12,7 @@ function compareTwoStrings(str1, str2) {
12
12
  const pairs2 = wordLetterPairs(str2);
13
13
  const union = pairs1.length + pairs2.length;
14
14
  let intersection = 0;
15
- pairs1.forEach(pair1 => {
15
+ for (const pair1 of pairs1) {
16
16
  for (let i = 0, pair2; (pair2 = pairs2[i]); i++) {
17
17
  if (pair1 !== pair2)
18
18
  continue;
@@ -20,7 +20,7 @@ function compareTwoStrings(str1, str2) {
20
20
  pairs2.splice(i, 1);
21
21
  break;
22
22
  }
23
- });
23
+ }
24
24
  return (intersection * 2) / union;
25
25
  }
26
26
  export function findBestMatch(mainString, targetStrings) {
@@ -22,7 +22,7 @@ export function calculateOperationComplexity(node, config, getFragmentByName, de
22
22
  calculateOperationComplexity(child, config, getFragmentByName, depth + 1);
23
23
  }
24
24
  }
25
- if (node.kind == Kind.FRAGMENT_SPREAD) {
25
+ if (node.kind === Kind.FRAGMENT_SPREAD) {
26
26
  const fragment = getFragmentByName(node.name.value);
27
27
  if (fragment) {
28
28
  cost +=
@@ -22,7 +22,7 @@ export function countDirectives(node, getFragmentByName) {
22
22
  directives += countDirectives(child, getFragmentByName);
23
23
  }
24
24
  }
25
- if (node.kind == Kind.FRAGMENT_SPREAD) {
25
+ if (node.kind === Kind.FRAGMENT_SPREAD) {
26
26
  const fragment = getFragmentByName(node.name.value);
27
27
  if (fragment) {
28
28
  directives += countDirectives(fragment, getFragmentByName);
@@ -16,25 +16,24 @@ export function validate(schema, sources, options) {
16
16
  const fragments = [];
17
17
  const fragmentNames = [];
18
18
  const graph = new DepGraph({ circular: true });
19
- documents.forEach(doc => {
20
- doc.fragments.forEach(fragment => {
19
+ for (const doc of documents) {
20
+ for (const fragment of doc.fragments) {
21
21
  fragmentNames.push(fragment.node.name.value);
22
22
  fragments.push(fragment);
23
23
  graph.addNode(fragment.node.name.value, fragment.node);
24
- });
25
- });
26
- fragments.forEach(fragment => {
24
+ }
25
+ }
26
+ for (const fragment of fragments) {
27
27
  const depends = extractFragments(print(fragment.node));
28
28
  if (depends) {
29
- depends.forEach(name => {
29
+ for (const name of depends) {
30
30
  graph.addDependency(fragment.node.name.value, name);
31
- });
31
+ }
32
32
  }
33
- });
34
- documents
33
+ }
34
+ for (const doc of documents
35
35
  // since we include fragments, validate only operations
36
- .filter(doc => doc.hasOperations)
37
- .forEach(doc => {
36
+ .filter(doc => doc.hasOperations)) {
38
37
  const docWithOperations = {
39
38
  kind: Kind.DOCUMENT,
40
39
  definitions: doc.operations.map(d => d.node),
@@ -114,7 +113,7 @@ export function validate(schema, sources, options) {
114
113
  deprecated,
115
114
  });
116
115
  }
117
- });
116
+ }
118
117
  return invalidDocuments;
119
118
  }
120
119
  function findDuplicatedFragments(fragmentNames) {
@@ -87,7 +87,7 @@ export function countDepth(node, parentDepth, getFragmentReference) {
87
87
  depth = Math.max(depth, countDepth(child, parentDepth + 1, getFragmentReference));
88
88
  }
89
89
  }
90
- if (node.kind == Kind.FRAGMENT_SPREAD) {
90
+ if (node.kind === Kind.FRAGMENT_SPREAD) {
91
91
  const fragment = getFragmentReference(node.name.value);
92
92
  if (fragment) {
93
93
  depth = Math.max(depth, countDepth(fragment, parentDepth + 1, getFragmentReference));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-inspector/core",
3
- "version": "4.1.0",
3
+ "version": "4.1.1-alpha-20230418154415-aa03cdf5",
4
4
  "description": "Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -9,7 +9,7 @@
9
9
  "dependencies": {
10
10
  "dependency-graph": "0.11.0",
11
11
  "object-inspect": "1.12.3",
12
- "tslib": "^2.0.0"
12
+ "tslib": "2.5.0"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",