graphql-data-generator 0.3.0-alpha.12 → 0.3.0-alpha.13
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.
- package/esm/init.js +12 -4
- package/package.json +1 -1
- package/script/init.js +12 -4
package/esm/init.js
CHANGED
|
@@ -8,9 +8,17 @@ import { toObject } from "./util.js";
|
|
|
8
8
|
import { dirname } from "node:path";
|
|
9
9
|
globalThis.require ??= createRequire(dntShim.Deno.cwd());
|
|
10
10
|
const files = {};
|
|
11
|
-
const loadFile = (path) =>
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const loadFile = (path) => {
|
|
12
|
+
if (files[path])
|
|
13
|
+
return files[path];
|
|
14
|
+
const raw = files[path] = readFileSync(path, "utf-8");
|
|
15
|
+
const imports = Array.from(raw.matchAll(/#import "(.*)"/gm), ([, importPath]) => loadFile(require.resolve(importPath, {
|
|
16
|
+
paths: [dirname(path), dntShim.Deno.cwd()],
|
|
17
|
+
})));
|
|
18
|
+
if (!imports.length)
|
|
19
|
+
return raw;
|
|
20
|
+
return [raw, ...imports].join("\n\n");
|
|
21
|
+
};
|
|
14
22
|
const getOperationContentMap = {};
|
|
15
23
|
const getOperationContent = (path, operationName) => {
|
|
16
24
|
const existing = getOperationContentMap[path];
|
|
@@ -26,7 +34,7 @@ const getOperationContent = (path, operationName) => {
|
|
|
26
34
|
const document = parse(s);
|
|
27
35
|
const firstOp = document.definitions.find((d) => d.kind === Kind.OPERATION_DEFINITION);
|
|
28
36
|
if (!firstOp)
|
|
29
|
-
throw new Error(`
|
|
37
|
+
throw new Error(`Could not find an operation in ${path}`);
|
|
30
38
|
return [firstOp.name?.value, document];
|
|
31
39
|
}));
|
|
32
40
|
}
|
package/package.json
CHANGED
package/script/init.js
CHANGED
|
@@ -34,9 +34,17 @@ const util_js_1 = require("./util.js");
|
|
|
34
34
|
const node_path_1 = require("node:path");
|
|
35
35
|
globalThis.require ??= (0, node_module_1.createRequire)(dntShim.Deno.cwd());
|
|
36
36
|
const files = {};
|
|
37
|
-
const loadFile = (path) =>
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const loadFile = (path) => {
|
|
38
|
+
if (files[path])
|
|
39
|
+
return files[path];
|
|
40
|
+
const raw = files[path] = (0, node_fs_1.readFileSync)(path, "utf-8");
|
|
41
|
+
const imports = Array.from(raw.matchAll(/#import "(.*)"/gm), ([, importPath]) => loadFile(require.resolve(importPath, {
|
|
42
|
+
paths: [(0, node_path_1.dirname)(path), dntShim.Deno.cwd()],
|
|
43
|
+
})));
|
|
44
|
+
if (!imports.length)
|
|
45
|
+
return raw;
|
|
46
|
+
return [raw, ...imports].join("\n\n");
|
|
47
|
+
};
|
|
40
48
|
const getOperationContentMap = {};
|
|
41
49
|
const getOperationContent = (path, operationName) => {
|
|
42
50
|
const existing = getOperationContentMap[path];
|
|
@@ -52,7 +60,7 @@ const getOperationContent = (path, operationName) => {
|
|
|
52
60
|
const document = (0, graphql_1.parse)(s);
|
|
53
61
|
const firstOp = document.definitions.find((d) => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
|
|
54
62
|
if (!firstOp)
|
|
55
|
-
throw new Error(`
|
|
63
|
+
throw new Error(`Could not find an operation in ${path}`);
|
|
56
64
|
return [firstOp.name?.value, document];
|
|
57
65
|
}));
|
|
58
66
|
}
|