graphql-data-generator 0.2.3 → 0.2.4
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/codegen.js +3 -1
- package/esm/plugin.cjs +2 -1
- package/esm/util.js +22 -8
- package/package.json +2 -2
package/esm/codegen.js
CHANGED
|
@@ -555,7 +555,9 @@ ${usedTypes.map(([name]) => ` ${name}: ${rename(name)};`).join("\n")}
|
|
|
555
555
|
}
|
|
556
556
|
else if (enums.startsWith("import:") &&
|
|
557
557
|
usedReferences.some((r) => r.kind === Kind.ENUM_TYPE_DEFINITION)) {
|
|
558
|
-
serializedTypes.unshift(`import {
|
|
558
|
+
serializedTypes.unshift(`import {
|
|
559
|
+
${usedReferences.filter((r) => r.kind === Kind.ENUM_TYPE_DEFINITION).map((r) => r.name.value).join(",\n ")},
|
|
560
|
+
} from "${enums.slice(7)}";`);
|
|
559
561
|
}
|
|
560
562
|
return serializedTypes.join("\n\n") + "\n";
|
|
561
563
|
};
|
package/esm/plugin.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
module.exports = {
|
|
3
3
|
async plugin(schema, documents, config) {
|
|
4
4
|
const { codegen } = await import("./codegen.js");
|
|
5
|
-
|
|
5
|
+
const { formatCode } = await import("./util.js");
|
|
6
|
+
return (config.banner ?? "") + await formatCode(codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config }));
|
|
6
7
|
},
|
|
7
8
|
};
|
package/esm/util.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
2
|
export const raise = (error) => {
|
|
3
3
|
if (typeof error === "string") {
|
|
4
4
|
const err = new Error(error);
|
|
@@ -10,14 +10,28 @@ export const raise = (error) => {
|
|
|
10
10
|
export const formatCode = async (input) => {
|
|
11
11
|
try {
|
|
12
12
|
return await new Promise((resolve, reject) => {
|
|
13
|
-
const process =
|
|
14
|
-
|
|
15
|
-
return reject(error);
|
|
16
|
-
if (stderr)
|
|
17
|
-
return reject(new Error(stderr));
|
|
18
|
-
resolve(stdout);
|
|
13
|
+
const process = spawn("deno", ["fmt", "-"], {
|
|
14
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
19
15
|
});
|
|
20
|
-
|
|
16
|
+
let output = "";
|
|
17
|
+
let errorOutput = "";
|
|
18
|
+
process.stdout.on("data", (data) => {
|
|
19
|
+
output += data.toString();
|
|
20
|
+
});
|
|
21
|
+
process.stderr.on("data", (data) => {
|
|
22
|
+
errorOutput += data.toString();
|
|
23
|
+
});
|
|
24
|
+
process.on("close", (code) => {
|
|
25
|
+
if (code !== 0 || errorOutput) {
|
|
26
|
+
reject(new Error(errorOutput || `Process exited with code ${code}`));
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
resolve(output);
|
|
30
|
+
});
|
|
31
|
+
process.on("error", (error) => {
|
|
32
|
+
reject(error);
|
|
33
|
+
});
|
|
34
|
+
process.stdin.write(input);
|
|
21
35
|
process.stdin?.end();
|
|
22
36
|
});
|
|
23
37
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-data-generator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
|
-
"url": "git+https://github.com/
|
|
6
|
+
"url": "git+https://github.com/voces/graphql-data-generator.git"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"bugs": {
|