graphql-data-generator 0.4.0 → 0.4.1-alpha.1
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/proxy.js +9 -12
- package/package.json +1 -1
- package/script/proxy.js +9 -12
package/esm/proxy.js
CHANGED
|
@@ -163,10 +163,8 @@ const resolveValue = (definitions, scalars, type, ctx) => {
|
|
|
163
163
|
const value = typeof scalar === "function" ? scalar(ctx.hostType) : scalar;
|
|
164
164
|
return value;
|
|
165
165
|
}
|
|
166
|
-
if (fieldTypeDefinitions.length === 1 &&
|
|
167
|
-
|
|
168
|
-
fieldTypeDefinitions[0].kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
169
|
-
fieldTypeDefinitions[0].kind === Kind.INPUT_OBJECT_TYPE_DEFINITION)) {
|
|
166
|
+
if (fieldTypeDefinitions.length === 1 && "name" in fieldTypeDefinitions[0] &&
|
|
167
|
+
fieldTypeDefinitions[0].name) {
|
|
170
168
|
return _proxy(definitions, scalars, ctx.path ? `${ctx.path}.${ctx.prop}` : fieldTypeDefinitions[0].name.value, [], { selectionSet: ctx.selectionSet, nonNull: true });
|
|
171
169
|
}
|
|
172
170
|
throw new Error(`Unhandled default kind ${fieldTypeDefinitions.map((d) => d.kind)}`);
|
|
@@ -426,14 +424,12 @@ export const _proxy = (definitions, scalars, path, patches, { prev, resolvedType
|
|
|
426
424
|
input: definition.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
427
425
|
});
|
|
428
426
|
};
|
|
429
|
-
const keys =
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
: definition.fields?.map((f) => f.name.value) ?? []),
|
|
436
|
-
];
|
|
427
|
+
const keys = selectionSet
|
|
428
|
+
? selectionSetToKeys(definitions, selectionSet, definition.name.value)
|
|
429
|
+
: definition.fields?.map((f) => f.name.value) ?? [];
|
|
430
|
+
if (definition.kind === Kind.OBJECT_TYPE_DEFINITION &&
|
|
431
|
+
!keys.includes("__typename"))
|
|
432
|
+
keys.unshift("__typename");
|
|
437
433
|
return new Proxy({}, {
|
|
438
434
|
get: getProp,
|
|
439
435
|
set: (target, prop, value) => {
|
|
@@ -460,6 +456,7 @@ export const _proxy = (definitions, scalars, path, patches, { prev, resolvedType
|
|
|
460
456
|
return _proxy(definitions, scalars, concreteType.name.value, patches, {
|
|
461
457
|
prev,
|
|
462
458
|
selectionSet,
|
|
459
|
+
nonNull: true,
|
|
463
460
|
});
|
|
464
461
|
}
|
|
465
462
|
case Kind.OPERATION_DEFINITION: {
|
package/package.json
CHANGED
package/script/proxy.js
CHANGED
|
@@ -167,10 +167,8 @@ const resolveValue = (definitions, scalars, type, ctx) => {
|
|
|
167
167
|
const value = typeof scalar === "function" ? scalar(ctx.hostType) : scalar;
|
|
168
168
|
return value;
|
|
169
169
|
}
|
|
170
|
-
if (fieldTypeDefinitions.length === 1 &&
|
|
171
|
-
|
|
172
|
-
fieldTypeDefinitions[0].kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION ||
|
|
173
|
-
fieldTypeDefinitions[0].kind === graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION)) {
|
|
170
|
+
if (fieldTypeDefinitions.length === 1 && "name" in fieldTypeDefinitions[0] &&
|
|
171
|
+
fieldTypeDefinitions[0].name) {
|
|
174
172
|
return (0, exports._proxy)(definitions, scalars, ctx.path ? `${ctx.path}.${ctx.prop}` : fieldTypeDefinitions[0].name.value, [], { selectionSet: ctx.selectionSet, nonNull: true });
|
|
175
173
|
}
|
|
176
174
|
throw new Error(`Unhandled default kind ${fieldTypeDefinitions.map((d) => d.kind)}`);
|
|
@@ -430,14 +428,12 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
430
428
|
input: definition.kind === graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
431
429
|
});
|
|
432
430
|
};
|
|
433
|
-
const keys =
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
: definition.fields?.map((f) => f.name.value) ?? []),
|
|
440
|
-
];
|
|
431
|
+
const keys = selectionSet
|
|
432
|
+
? selectionSetToKeys(definitions, selectionSet, definition.name.value)
|
|
433
|
+
: definition.fields?.map((f) => f.name.value) ?? [];
|
|
434
|
+
if (definition.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION &&
|
|
435
|
+
!keys.includes("__typename"))
|
|
436
|
+
keys.unshift("__typename");
|
|
441
437
|
return new Proxy({}, {
|
|
442
438
|
get: getProp,
|
|
443
439
|
set: (target, prop, value) => {
|
|
@@ -464,6 +460,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
464
460
|
return (0, exports._proxy)(definitions, scalars, concreteType.name.value, patches, {
|
|
465
461
|
prev,
|
|
466
462
|
selectionSet,
|
|
463
|
+
nonNull: true,
|
|
467
464
|
});
|
|
468
465
|
}
|
|
469
466
|
case graphql_1.Kind.OPERATION_DEFINITION: {
|