graphql-data-generator 0.4.6-alpha.4 → 0.4.7-alpha.0
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 +33 -1
- package/package.json +1 -1
- package/script/codegen.js +33 -1
package/esm/codegen.js
CHANGED
|
@@ -5,6 +5,38 @@ import { join, relative } from "node:path";
|
|
|
5
5
|
import { raise } from "./util.js";
|
|
6
6
|
import process from "node:process";
|
|
7
7
|
import { convertFactory, } from "@graphql-codegen/visitor-plugin-common";
|
|
8
|
+
const mergeSerializable = (existing, incoming) => {
|
|
9
|
+
if (!existing)
|
|
10
|
+
return incoming;
|
|
11
|
+
if (existing.kind === "Object" && incoming.kind === "Object") {
|
|
12
|
+
const merged = { ...existing.value };
|
|
13
|
+
for (const [k, v] of Object.entries(incoming.value)) {
|
|
14
|
+
merged[k] = mergeSerializable(merged[k], v);
|
|
15
|
+
}
|
|
16
|
+
const typenameDesc = Object.getOwnPropertyDescriptor(existing.value, "__typename") ??
|
|
17
|
+
Object.getOwnPropertyDescriptor(incoming.value, "__typename");
|
|
18
|
+
if (typenameDesc)
|
|
19
|
+
Object.defineProperty(merged, "__typename", typenameDesc);
|
|
20
|
+
return {
|
|
21
|
+
kind: "Object",
|
|
22
|
+
value: merged,
|
|
23
|
+
conditionals: [
|
|
24
|
+
...(existing.conditionals ?? []),
|
|
25
|
+
...(incoming.conditionals ?? []),
|
|
26
|
+
],
|
|
27
|
+
nonExhaustive: existing.nonExhaustive ?? incoming.nonExhaustive,
|
|
28
|
+
optional: existing.optional && incoming.optional,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (existing.kind === "List" && incoming.kind === "List") {
|
|
32
|
+
return {
|
|
33
|
+
kind: "List",
|
|
34
|
+
value: mergeSerializable(existing.value, incoming.value),
|
|
35
|
+
optional: existing.optional && incoming.optional,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return incoming;
|
|
39
|
+
};
|
|
8
40
|
const getType = ({ type, ...props }) => {
|
|
9
41
|
if (type.kind === "NamedType") {
|
|
10
42
|
if (props.selections) {
|
|
@@ -40,7 +72,7 @@ const getType = ({ type, ...props }) => {
|
|
|
40
72
|
},
|
|
41
73
|
});
|
|
42
74
|
}
|
|
43
|
-
union[group][name] = value;
|
|
75
|
+
union[group][name] = mergeSerializable(union[group][name], value);
|
|
44
76
|
const def = props.definitions[actualTypeName];
|
|
45
77
|
// Use originalName for tracking field usage when field is aliased
|
|
46
78
|
const fieldNameForTracking = originalName ?? name;
|
package/package.json
CHANGED
package/script/codegen.js
CHANGED
|
@@ -11,6 +11,38 @@ const node_path_1 = require("node:path");
|
|
|
11
11
|
const util_js_1 = require("./util.js");
|
|
12
12
|
const node_process_1 = __importDefault(require("node:process"));
|
|
13
13
|
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
14
|
+
const mergeSerializable = (existing, incoming) => {
|
|
15
|
+
if (!existing)
|
|
16
|
+
return incoming;
|
|
17
|
+
if (existing.kind === "Object" && incoming.kind === "Object") {
|
|
18
|
+
const merged = { ...existing.value };
|
|
19
|
+
for (const [k, v] of Object.entries(incoming.value)) {
|
|
20
|
+
merged[k] = mergeSerializable(merged[k], v);
|
|
21
|
+
}
|
|
22
|
+
const typenameDesc = Object.getOwnPropertyDescriptor(existing.value, "__typename") ??
|
|
23
|
+
Object.getOwnPropertyDescriptor(incoming.value, "__typename");
|
|
24
|
+
if (typenameDesc)
|
|
25
|
+
Object.defineProperty(merged, "__typename", typenameDesc);
|
|
26
|
+
return {
|
|
27
|
+
kind: "Object",
|
|
28
|
+
value: merged,
|
|
29
|
+
conditionals: [
|
|
30
|
+
...(existing.conditionals ?? []),
|
|
31
|
+
...(incoming.conditionals ?? []),
|
|
32
|
+
],
|
|
33
|
+
nonExhaustive: existing.nonExhaustive ?? incoming.nonExhaustive,
|
|
34
|
+
optional: existing.optional && incoming.optional,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (existing.kind === "List" && incoming.kind === "List") {
|
|
38
|
+
return {
|
|
39
|
+
kind: "List",
|
|
40
|
+
value: mergeSerializable(existing.value, incoming.value),
|
|
41
|
+
optional: existing.optional && incoming.optional,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return incoming;
|
|
45
|
+
};
|
|
14
46
|
const getType = ({ type, ...props }) => {
|
|
15
47
|
if (type.kind === "NamedType") {
|
|
16
48
|
if (props.selections) {
|
|
@@ -46,7 +78,7 @@ const getType = ({ type, ...props }) => {
|
|
|
46
78
|
},
|
|
47
79
|
});
|
|
48
80
|
}
|
|
49
|
-
union[group][name] = value;
|
|
81
|
+
union[group][name] = mergeSerializable(union[group][name], value);
|
|
50
82
|
const def = props.definitions[actualTypeName];
|
|
51
83
|
// Use originalName for tracking field usage when field is aliased
|
|
52
84
|
const fieldNameForTracking = originalName ?? name;
|