@graphcommerce/graphql-codegen-near-operation-file 2.103.14 → 2.103.15

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.
@@ -36,7 +36,7 @@ function buildFragmentRegistry(_a, _b, schemaObject) {
36
36
  fragmentImports.push({
37
37
  name: baseVisitor.convertName(name, {
38
38
  useTypesPrefix: true,
39
- suffix: "_" + typeName + "_" + fragmentSuffix,
39
+ suffix: "_".concat(typeName, "_").concat(fragmentSuffix),
40
40
  }),
41
41
  kind: 'type',
42
42
  });
@@ -53,7 +53,7 @@ function buildFragmentRegistry(_a, _b, schemaObject) {
53
53
  var fragment = fragments_1[_i];
54
54
  var schemaType = schemaObject.getType(fragment.typeCondition.name.value);
55
55
  if (!schemaType) {
56
- throw new Error("Fragment \"" + fragment.name.value + "\" is set on non-existing type \"" + fragment.typeCondition.name.value + "\"!");
56
+ throw new Error("Fragment \"".concat(fragment.name.value, "\" is set on non-existing type \"").concat(fragment.typeCondition.name.value, "\"!"));
57
57
  }
58
58
  var possibleTypes = (0, visitor_plugin_common_1.getPossibleTypes)(schemaObject, schemaType);
59
59
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -74,7 +74,7 @@ function buildFragmentRegistry(_a, _b, schemaObject) {
74
74
  return prev;
75
75
  }, {});
76
76
  if (duplicateFragmentNames.length) {
77
- throw new Error("Multiple fragments with the name(s) \"" + duplicateFragmentNames.join(', ') + "\" were found.");
77
+ throw new Error("Multiple fragments with the name(s) \"".concat(duplicateFragmentNames.join(', '), "\" were found."));
78
78
  }
79
79
  return registry;
80
80
  }
package/dist/index.js CHANGED
@@ -44,11 +44,11 @@ Object.defineProperty(exports, "resolveDocumentImports", { enumerable: true, get
44
44
  var utils_1 = require("./utils");
45
45
  function isFragment(documentFile) {
46
46
  var name = false;
47
+ if (!documentFile.document)
48
+ return name;
47
49
  (0, graphql_1.visit)(documentFile.document, {
48
- enter: {
49
- FragmentDefinition: function () {
50
- name = true;
51
- },
50
+ FragmentDefinition: function () {
51
+ name = true;
52
52
  },
53
53
  });
54
54
  return name;
@@ -42,8 +42,8 @@ function hasInjectDirective(document) {
42
42
  }
43
43
  function throwInjectError(conf, message) {
44
44
  var _a, _b, _c;
45
- var val = (_a = conf.into) === null || _a === void 0 ? void 0 : _a.map(function (v) { return "\"" + v + "\""; });
46
- throw Error(message + "\n fragment " + ((_b = conf.fragment) === null || _b === void 0 ? void 0 : _b.name.value) + " on " + ((_c = conf.fragment) === null || _c === void 0 ? void 0 : _c.typeCondition.name.value) + " @inject(into: [" + val + "]) { ... }");
45
+ var val = (_a = conf.into) === null || _a === void 0 ? void 0 : _a.map(function (v) { return "\"".concat(v, "\""); });
46
+ throw Error("".concat(message, "\n fragment ").concat((_b = conf.fragment) === null || _b === void 0 ? void 0 : _b.name.value, " on ").concat((_c = conf.fragment) === null || _c === void 0 ? void 0 : _c.typeCondition.name.value, " @inject(into: [").concat(val, "]) { ... }"));
47
47
  }
48
48
  function assertValidInject(injectVal) {
49
49
  var into = injectVal.into, fragment = injectVal.fragment;
@@ -97,8 +97,8 @@ function injectInjectable(injectables, injector) {
97
97
  if (frag.name.value === target) {
98
98
  found = true;
99
99
  var spread = {
100
- kind: 'FragmentSpread',
101
- name: { kind: 'Name', value: fragment.name.value },
100
+ kind: graphql_1.Kind.FRAGMENT_SPREAD,
101
+ name: { kind: graphql_1.Kind.NAME, value: fragment.name.value },
102
102
  };
103
103
  frag.selectionSet.selections = __spreadArray(__spreadArray([], frag.selectionSet.selections, true), [spread], false);
104
104
  }
@@ -106,7 +106,7 @@ function injectInjectable(injectables, injector) {
106
106
  });
107
107
  });
108
108
  if (!found)
109
- throwInjectError(injectVal, "fragment " + target + " @injectable { ... } can not be found or isn't injectable");
109
+ throwInjectError(injectVal, "fragment ".concat(target, " @injectable { ... } can not be found or isn't injectable"));
110
110
  });
111
111
  }
112
112
  function injectInjectables(documentFiles) {
@@ -38,11 +38,11 @@ var fragment_resolver_1 = __importStar(require("./fragment-resolver"));
38
38
  var utils_1 = require("./utils");
39
39
  function getFragmentName(documentFile) {
40
40
  var name;
41
+ if (!documentFile.document)
42
+ return name;
41
43
  (0, graphql_1.visit)(documentFile.document, {
42
- enter: {
43
- FragmentDefinition: function (node) {
44
- name = node.name.value;
45
- },
44
+ FragmentDefinition: function (node) {
45
+ name = node.name.value;
46
46
  },
47
47
  });
48
48
  return name;
@@ -120,7 +120,7 @@ function resolveDocumentImports(presetOptions, schemaObject, importResolverOptio
120
120
  }
121
121
  catch (e) {
122
122
  if (e instanceof Error) {
123
- throw new plugin_helpers_1.DetailedError("Unable to validate GraphQL document!", "File " + documentFile.location + " caused error: " + (e.message || e.toString()), documentFile.location);
123
+ throw new plugin_helpers_1.DetailedError("Unable to validate GraphQL document!", "File ".concat(documentFile.location, " caused error: ").concat(e.message || e.toString()), documentFile.location);
124
124
  }
125
125
  else {
126
126
  throw e;
package/dist/utils.js CHANGED
@@ -24,26 +24,22 @@ function extractExternalFragmentsInUse(documentNode, fragmentNameToFile, result,
24
24
  var ignoreList = new Set();
25
25
  // First, take all fragments definition from the current file, and mark them as ignored
26
26
  (0, graphql_1.visit)(documentNode, {
27
- enter: {
28
- FragmentDefinition: function (node) {
29
- ignoreList.add(node.name.value);
30
- },
27
+ FragmentDefinition: function (node) {
28
+ ignoreList.add(node.name.value);
31
29
  },
32
30
  });
33
31
  // Then, look for all used fragments in this document
34
32
  (0, graphql_1.visit)(documentNode, {
35
- enter: {
36
- FragmentSpread: function (node) {
37
- if (!ignoreList.has(node.name.value)) {
38
- if (result[node.name.value] === undefined ||
39
- (result[node.name.value] !== undefined && level < result[node.name.value])) {
40
- result[node.name.value] = level;
41
- if (fragmentNameToFile[node.name.value]) {
42
- extractExternalFragmentsInUse(fragmentNameToFile[node.name.value].node, fragmentNameToFile, result, level + 1);
43
- }
33
+ FragmentSpread: function (node) {
34
+ if (!ignoreList.has(node.name.value)) {
35
+ if (result[node.name.value] === undefined ||
36
+ (result[node.name.value] !== undefined && level < result[node.name.value])) {
37
+ result[node.name.value] = level;
38
+ if (fragmentNameToFile[node.name.value]) {
39
+ extractExternalFragmentsInUse(fragmentNameToFile[node.name.value].node, fragmentNameToFile, result, level + 1);
44
40
  }
45
41
  }
46
- },
42
+ }
47
43
  },
48
44
  });
49
45
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/graphql-codegen-near-operation-file",
3
- "version": "2.103.14",
3
+ "version": "2.103.15",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -27,18 +27,18 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@graphcommerce/browserslist-config-pwa": "^3.0.2",
30
- "@graphcommerce/eslint-config-pwa": "^3.1.6",
30
+ "@graphcommerce/eslint-config-pwa": "^3.1.7",
31
31
  "@graphcommerce/prettier-config-pwa": "^3.0.4",
32
32
  "@graphcommerce/typescript-config-pwa": "^3.1.1",
33
- "@playwright/test": "^1.16.2"
33
+ "@playwright/test": "^1.17.1"
34
34
  },
35
35
  "dependencies": {
36
36
  "@graphql-codegen/add": "^3.1.0",
37
- "@graphql-codegen/plugin-helpers": "^2.3.0",
38
- "@graphql-codegen/visitor-plugin-common": "^2.5.0",
37
+ "@graphql-codegen/plugin-helpers": "^2.3.1",
38
+ "@graphql-codegen/visitor-plugin-common": "^2.5.1",
39
39
  "@types/parse-filepath": "^1.0.0",
40
- "graphql": "^15.6.1",
40
+ "graphql": "^16.1.0",
41
41
  "parse-filepath": "^1.0.2"
42
42
  },
43
- "gitHead": "8f156415c7f5a963e363f0d6d18fe5d6bbd5dba2"
43
+ "gitHead": "d1e17a76798279be4ceb3429238e1e736061899b"
44
44
  }
package/src/index.ts CHANGED
@@ -145,12 +145,11 @@ export type FragmentNameToFile = {
145
145
 
146
146
  function isFragment(documentFile: Types.DocumentFile) {
147
147
  let name = false
148
+ if (!documentFile.document) return name
148
149
 
149
- visit(documentFile.document!, {
150
- enter: {
151
- FragmentDefinition: () => {
152
- name = true
153
- },
150
+ visit(documentFile.document, {
151
+ FragmentDefinition: () => {
152
+ name = true
154
153
  },
155
154
  })
156
155
  return name
package/src/injectable.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable react/destructuring-assignment */
2
2
  import { Types } from '@graphql-codegen/plugin-helpers'
3
- import { visit, DocumentNode, FragmentSpreadNode, FragmentDefinitionNode } from 'graphql'
3
+ import { visit, DocumentNode, FragmentSpreadNode, FragmentDefinitionNode, Kind } from 'graphql'
4
4
 
5
5
  function isFragment(document: DocumentNode) {
6
6
  let is = false
@@ -95,8 +95,8 @@ function injectInjectable(injectables: DocumentNode[], injector: DocumentNode) {
95
95
  found = true
96
96
 
97
97
  const spread: FragmentSpreadNode = {
98
- kind: 'FragmentSpread',
99
- name: { kind: 'Name', value: fragment.name.value },
98
+ kind: Kind.FRAGMENT_SPREAD,
99
+ name: { kind: Kind.NAME, value: fragment.name.value },
100
100
  }
101
101
  frag.selectionSet.selections = [...frag.selectionSet.selections, spread]
102
102
  }
@@ -10,7 +10,7 @@ import {
10
10
  LoadedFragment,
11
11
  } from '@graphql-codegen/visitor-plugin-common'
12
12
  import { Source } from '@graphql-tools/utils'
13
- import { FragmentDefinitionNode, GraphQLSchema, visit } from 'graphql'
13
+ import { DocumentNode, FragmentDefinitionNode, GraphQLSchema, visit } from 'graphql'
14
14
  import buildFragmentResolver, { buildFragmentRegistry } from './fragment-resolver'
15
15
  import { extractExternalFragmentsInUse } from './utils'
16
16
 
@@ -45,13 +45,14 @@ interface ResolveDocumentImportResult {
45
45
 
46
46
  function getFragmentName(documentFile: Types.DocumentFile) {
47
47
  let name: string | undefined
48
- visit(documentFile.document!, {
49
- enter: {
50
- FragmentDefinition: (node: FragmentDefinitionNode) => {
51
- name = node.name.value
52
- },
48
+ if (!documentFile.document) return name
49
+
50
+ visit<DocumentNode>(documentFile.document, {
51
+ FragmentDefinition(node) {
52
+ name = node.name.value
53
53
  },
54
54
  })
55
+
55
56
  return name
56
57
  }
57
58
 
package/src/utils.ts CHANGED
@@ -25,35 +25,31 @@ export function extractExternalFragmentsInUse(
25
25
 
26
26
  // First, take all fragments definition from the current file, and mark them as ignored
27
27
  visit(documentNode, {
28
- enter: {
29
- FragmentDefinition: (node: FragmentDefinitionNode) => {
30
- ignoreList.add(node.name.value)
31
- },
28
+ FragmentDefinition: (node: FragmentDefinitionNode) => {
29
+ ignoreList.add(node.name.value)
32
30
  },
33
31
  })
34
32
 
35
33
  // Then, look for all used fragments in this document
36
34
  visit(documentNode, {
37
- enter: {
38
- FragmentSpread: (node: FragmentSpreadNode) => {
39
- if (!ignoreList.has(node.name.value)) {
40
- if (
41
- result[node.name.value] === undefined ||
42
- (result[node.name.value] !== undefined && level < result[node.name.value])
43
- ) {
44
- result[node.name.value] = level
45
-
46
- if (fragmentNameToFile[node.name.value]) {
47
- extractExternalFragmentsInUse(
48
- fragmentNameToFile[node.name.value].node,
49
- fragmentNameToFile,
50
- result,
51
- level + 1,
52
- )
53
- }
35
+ FragmentSpread: (node: FragmentSpreadNode) => {
36
+ if (!ignoreList.has(node.name.value)) {
37
+ if (
38
+ result[node.name.value] === undefined ||
39
+ (result[node.name.value] !== undefined && level < result[node.name.value])
40
+ ) {
41
+ result[node.name.value] = level
42
+
43
+ if (fragmentNameToFile[node.name.value]) {
44
+ extractExternalFragmentsInUse(
45
+ fragmentNameToFile[node.name.value].node,
46
+ fragmentNameToFile,
47
+ result,
48
+ level + 1,
49
+ )
54
50
  }
55
51
  }
56
- },
52
+ }
57
53
  },
58
54
  })
59
55