graphql-data-generator 0.4.0-alpha.8 → 0.4.0-alpha.9

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.
Files changed (3) hide show
  1. package/esm/init.js +20 -10
  2. package/package.json +1 -1
  3. package/script/init.js +20 -10
package/esm/init.js CHANGED
@@ -27,19 +27,29 @@ const getOperationContent = (path, operationName) => {
27
27
  return existing;
28
28
  return getOperationContentMap[path][operationName];
29
29
  }
30
- const fileContent = loadFile(path);
31
30
  try {
32
- const sources = gqlPluckFromCodeStringSync(path, fileContent);
33
- getOperationContentMap[path] = Object.fromEntries(sources.map((s) => {
34
- const document = parse(s);
35
- const firstOp = document.definitions.find((d) => d.kind === Kind.OPERATION_DEFINITION);
36
- if (!firstOp)
37
- throw new Error(`Could not find an operation in ${path}`);
38
- return [firstOp.name?.value, document];
39
- }));
31
+ // First try loading via require, depending on GQL loaders
32
+ const doc = require(require.resolve(path, { paths: [dntShim.Deno.cwd()] }));
33
+ if (doc && typeof doc === "object" && "kind" in doc && doc.kind === "Document") {
34
+ getOperationContentMap[path] = doc;
35
+ }
40
36
  }
41
37
  catch {
42
- getOperationContentMap[path] = parse(fileContent);
38
+ // Otherwise load it manually
39
+ const fileContent = loadFile(path);
40
+ try {
41
+ const sources = gqlPluckFromCodeStringSync(path, fileContent);
42
+ getOperationContentMap[path] = Object.fromEntries(sources.map((s) => {
43
+ const document = parse(s);
44
+ const firstOp = document.definitions.find((d) => d.kind === Kind.OPERATION_DEFINITION);
45
+ if (!firstOp)
46
+ throw new Error(`Could not find an operation in ${path}`);
47
+ return [firstOp.name?.value, document];
48
+ }));
49
+ }
50
+ catch {
51
+ getOperationContentMap[path] = parse(fileContent);
52
+ }
43
53
  }
44
54
  return getOperationContent(path, operationName);
45
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-data-generator",
3
- "version": "0.4.0-alpha.8",
3
+ "version": "0.4.0-alpha.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voces/graphql-data-generator.git"
package/script/init.js CHANGED
@@ -53,19 +53,29 @@ const getOperationContent = (path, operationName) => {
53
53
  return existing;
54
54
  return getOperationContentMap[path][operationName];
55
55
  }
56
- const fileContent = loadFile(path);
57
56
  try {
58
- const sources = (0, graphql_tag_pluck_1.gqlPluckFromCodeStringSync)(path, fileContent);
59
- getOperationContentMap[path] = Object.fromEntries(sources.map((s) => {
60
- const document = (0, graphql_1.parse)(s);
61
- const firstOp = document.definitions.find((d) => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
62
- if (!firstOp)
63
- throw new Error(`Could not find an operation in ${path}`);
64
- return [firstOp.name?.value, document];
65
- }));
57
+ // First try loading via require, depending on GQL loaders
58
+ const doc = require(require.resolve(path, { paths: [dntShim.Deno.cwd()] }));
59
+ if (doc && typeof doc === "object" && "kind" in doc && doc.kind === "Document") {
60
+ getOperationContentMap[path] = doc;
61
+ }
66
62
  }
67
63
  catch {
68
- getOperationContentMap[path] = (0, graphql_1.parse)(fileContent);
64
+ // Otherwise load it manually
65
+ const fileContent = loadFile(path);
66
+ try {
67
+ const sources = (0, graphql_tag_pluck_1.gqlPluckFromCodeStringSync)(path, fileContent);
68
+ getOperationContentMap[path] = Object.fromEntries(sources.map((s) => {
69
+ const document = (0, graphql_1.parse)(s);
70
+ const firstOp = document.definitions.find((d) => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
71
+ if (!firstOp)
72
+ throw new Error(`Could not find an operation in ${path}`);
73
+ return [firstOp.name?.value, document];
74
+ }));
75
+ }
76
+ catch {
77
+ getOperationContentMap[path] = (0, graphql_1.parse)(fileContent);
78
+ }
69
79
  }
70
80
  return getOperationContent(path, operationName);
71
81
  };