@graphql-inspector/core 8.0.0 → 8.0.1

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.
@@ -34,11 +34,8 @@ function validate(schema, sources, options) {
34
34
  }
35
35
  }
36
36
  for (const fragment of fragments) {
37
- const depends = extractFragments((0, graphql_1.print)(fragment.node));
38
- if (depends) {
39
- for (const name of depends) {
40
- graph.addDependency(fragment.node.name.value, name);
41
- }
37
+ for (const name of extractFragments(fragment.node)) {
38
+ graph.addDependency(fragment.node.name.value, name);
42
39
  }
43
40
  }
44
41
  for (const doc of documents
@@ -48,7 +45,7 @@ function validate(schema, sources, options) {
48
45
  kind: graphql_1.Kind.DOCUMENT,
49
46
  definitions: doc.operations.map(d => d.node),
50
47
  };
51
- const extractedFragments = (extractFragments((0, graphql_1.print)(docWithOperations)) || [])
48
+ const extractedFragments = extractFragments(docWithOperations)
52
49
  // resolve all nested fragments
53
50
  .map(fragmentName => resolveFragment(graph.getNodeData(fragmentName), graph))
54
51
  // flatten arrays
@@ -157,7 +154,13 @@ function resolveFragment(fragment, graph) {
157
154
  .reduce((list, current) => [...list, ...resolveFragment(graph.getNodeData(current), graph)], [fragment]);
158
155
  }
159
156
  function extractFragments(document) {
160
- return (document.match(/[.]{3}[a-z0-9_]+\b/gi) || []).map(name => name.replace('...', ''));
157
+ const fragmentNames = [];
158
+ (0, graphql_1.visit)(document, {
159
+ FragmentSpread(node) {
160
+ fragmentNames.push(node.name.value);
161
+ },
162
+ });
163
+ return fragmentNames;
161
164
  }
162
165
  function sumLengths(...arrays) {
163
166
  return arrays.reduce((sum, { length }) => sum + length, 0);
@@ -1,5 +1,5 @@
1
1
  import { DepGraph } from 'dependency-graph';
2
- import { GraphQLError, Kind, print, validate as validateDocument, } from 'graphql';
2
+ import { GraphQLError, Kind, print, validate as validateDocument, visit, } from 'graphql';
3
3
  import { readDocument } from '../ast/document.js';
4
4
  import { transformDocumentWithApollo, transformSchemaWithApollo } from '../utils/apollo.js';
5
5
  import { findDeprecatedUsages } from '../utils/graphql.js';
@@ -31,11 +31,8 @@ export function validate(schema, sources, options) {
31
31
  }
32
32
  }
33
33
  for (const fragment of fragments) {
34
- const depends = extractFragments(print(fragment.node));
35
- if (depends) {
36
- for (const name of depends) {
37
- graph.addDependency(fragment.node.name.value, name);
38
- }
34
+ for (const name of extractFragments(fragment.node)) {
35
+ graph.addDependency(fragment.node.name.value, name);
39
36
  }
40
37
  }
41
38
  for (const doc of documents
@@ -45,7 +42,7 @@ export function validate(schema, sources, options) {
45
42
  kind: Kind.DOCUMENT,
46
43
  definitions: doc.operations.map(d => d.node),
47
44
  };
48
- const extractedFragments = (extractFragments(print(docWithOperations)) || [])
45
+ const extractedFragments = extractFragments(docWithOperations)
49
46
  // resolve all nested fragments
50
47
  .map(fragmentName => resolveFragment(graph.getNodeData(fragmentName), graph))
51
48
  // flatten arrays
@@ -154,7 +151,13 @@ function resolveFragment(fragment, graph) {
154
151
  .reduce((list, current) => [...list, ...resolveFragment(graph.getNodeData(current), graph)], [fragment]);
155
152
  }
156
153
  function extractFragments(document) {
157
- return (document.match(/[.]{3}[a-z0-9_]+\b/gi) || []).map(name => name.replace('...', ''));
154
+ const fragmentNames = [];
155
+ visit(document, {
156
+ FragmentSpread(node) {
157
+ fragmentNames.push(node.name.value);
158
+ },
159
+ });
160
+ return fragmentNames;
158
161
  }
159
162
  function sumLengths(...arrays) {
160
163
  return arrays.reduce((sum, { length }) => sum + length, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-inspector/core",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "graphql-hive/graphql-inspector",
16
+ "url": "https://github.com/graphql-hive/graphql-inspector",
17
17
  "directory": "packages/core"
18
18
  },
19
19
  "keywords": [