graphql-data-generator 0.1.0 → 0.1.2
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 +26 -5
- package/package.json +1 -1
package/esm/codegen.js
CHANGED
|
@@ -341,8 +341,6 @@ export const codegen = (schema, files, { useEnums = true, scalars = {}, includeT
|
|
|
341
341
|
case "ScalarTypeDefinition":
|
|
342
342
|
references[definition.name.value] = [definition, false];
|
|
343
343
|
break;
|
|
344
|
-
default:
|
|
345
|
-
throw new Error(`Unhandled definition type '${definition.kind}'`);
|
|
346
344
|
}
|
|
347
345
|
}
|
|
348
346
|
const roots = { query, mutation, subscription };
|
|
@@ -397,9 +395,32 @@ export const codegen = (schema, files, { useEnums = true, scalars = {}, includeT
|
|
|
397
395
|
if (type.kind !== "Name") {
|
|
398
396
|
throw new Error(`Could not find type for variable '${v.variable.name.value}'`);
|
|
399
397
|
}
|
|
400
|
-
if (handledInputs.has(type.value))
|
|
398
|
+
if (handledInputs.has(type.value) || !inputs[type.value])
|
|
401
399
|
return;
|
|
402
|
-
|
|
400
|
+
const stack = [type.value];
|
|
401
|
+
while (stack.length) {
|
|
402
|
+
const current = stack.pop();
|
|
403
|
+
const def = inputs[current]?.[0];
|
|
404
|
+
if (!def) {
|
|
405
|
+
throw new Error(`Could not find nested input '${current}'`);
|
|
406
|
+
}
|
|
407
|
+
const subFieldTypes = def.fields?.map((f) => {
|
|
408
|
+
let type = f.type;
|
|
409
|
+
while (type.kind !== Kind.NAMED_TYPE) {
|
|
410
|
+
if (type.kind === Kind.NON_NULL_TYPE)
|
|
411
|
+
type = type.type;
|
|
412
|
+
if (type.kind === Kind.LIST_TYPE)
|
|
413
|
+
type = type.type;
|
|
414
|
+
}
|
|
415
|
+
return type.name.value;
|
|
416
|
+
}).filter((t) => inputs[t]) ?? [];
|
|
417
|
+
if (subFieldTypes.some((t) => !handledInputs.has(t))) {
|
|
418
|
+
stack.push(current);
|
|
419
|
+
stack.push(...subFieldTypes);
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
handledInputs.add(current);
|
|
423
|
+
}
|
|
403
424
|
// return `type ${type.value} = ${serializeType(inputType)};`;
|
|
404
425
|
}).filter(Boolean)),
|
|
405
426
|
`export type ${operationNames[name].types} = {
|
|
@@ -448,7 +469,7 @@ ${usedTypes.map(([name]) => ` ${name}: ${name};`).join("\n")}
|
|
|
448
469
|
}
|
|
449
470
|
if (useEnums) {
|
|
450
471
|
return `enum ${r.name.value} {
|
|
451
|
-
${r.values?.map((r) => r.name.value).join(",\n ")}
|
|
472
|
+
${r.values?.map((r) => r.name.value).join(",\n ")},
|
|
452
473
|
}`;
|
|
453
474
|
}
|
|
454
475
|
else {
|