@contello/client 1.0.0 → 1.0.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/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var command = process.argv[2];
|
|
5
5
|
switch (command) {
|
|
6
6
|
case "generate":
|
|
7
|
-
await import("./generate-
|
|
7
|
+
await import("./generate-QAYD35FG.js");
|
|
8
8
|
break;
|
|
9
9
|
default:
|
|
10
10
|
console.error(command ? `unknown command: ${command}` : "usage: contello-client <command>");
|
|
@@ -556,6 +556,7 @@ function generateSchemaTypes(schema) {
|
|
|
556
556
|
lines.push("");
|
|
557
557
|
}
|
|
558
558
|
const modelNames = /* @__PURE__ */ new Map();
|
|
559
|
+
const entityModelNames = /* @__PURE__ */ new Map();
|
|
559
560
|
for (const unionName of ["ContelloEntity", "ContelloComponent"]) {
|
|
560
561
|
const union = typeMap[unionName];
|
|
561
562
|
if (union && isUnionType(union)) {
|
|
@@ -563,6 +564,9 @@ function generateSchemaTypes(schema) {
|
|
|
563
564
|
const model = deriveModelName(member.name);
|
|
564
565
|
if (model) {
|
|
565
566
|
modelNames.set(member.name, model);
|
|
567
|
+
if (unionName === "ContelloEntity") {
|
|
568
|
+
entityModelNames.set(member.name, model);
|
|
569
|
+
}
|
|
566
570
|
}
|
|
567
571
|
}
|
|
568
572
|
}
|
|
@@ -594,13 +598,11 @@ function generateSchemaTypes(schema) {
|
|
|
594
598
|
if (unions.length > 0) {
|
|
595
599
|
lines.push("");
|
|
596
600
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const typeNames = contelloEntityUnion.getTypes().map((t) => t.name);
|
|
600
|
-
const modelNames2 = typeNames.map((n) => n.replace(/Entity$/, "")).map((n) => n.charAt(0).toLowerCase() + n.slice(1));
|
|
601
|
+
if (entityModelNames.size > 0) {
|
|
602
|
+
const sorted = [...entityModelNames.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
601
603
|
lines.push("export const models = {");
|
|
602
|
-
for (
|
|
603
|
-
lines.push(` ${
|
|
604
|
+
for (const [typeName, model] of sorted) {
|
|
605
|
+
lines.push(` ${model}: '${typeName}',`);
|
|
604
606
|
}
|
|
605
607
|
lines.push("} as const;");
|
|
606
608
|
lines.push("");
|
|
@@ -657,6 +659,19 @@ function transformSelectionSet(schema, selectionSet, parentTypeName, fragments,
|
|
|
657
659
|
const parentFields = parentType.getFields();
|
|
658
660
|
const newSelections = [];
|
|
659
661
|
let changed = false;
|
|
662
|
+
function recurse(node, typeName) {
|
|
663
|
+
if (!node.selectionSet) {
|
|
664
|
+
newSelections.push(node);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const transformed = transformSelectionSet(schema, node.selectionSet, typeName, fragments, refsOnly);
|
|
668
|
+
if (transformed !== node.selectionSet) {
|
|
669
|
+
changed = true;
|
|
670
|
+
newSelections.push({ ...node, selectionSet: transformed });
|
|
671
|
+
} else {
|
|
672
|
+
newSelections.push(node);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
660
675
|
for (const selection of selectionSet.selections) {
|
|
661
676
|
if (selection.kind === Kind3.FIELD) {
|
|
662
677
|
const fieldName = selection.name.value;
|
|
@@ -673,49 +688,28 @@ function transformSelectionSet(schema, selectionSet, parentTypeName, fragments,
|
|
|
673
688
|
continue;
|
|
674
689
|
}
|
|
675
690
|
changed = true;
|
|
676
|
-
|
|
677
|
-
...selection,
|
|
678
|
-
selectionSet: FLAT_REF_SELECTIONS
|
|
679
|
-
};
|
|
680
|
-
newSelections.push(flatRefField);
|
|
691
|
+
newSelections.push({ ...selection, selectionSet: FLAT_REF_SELECTIONS });
|
|
681
692
|
if (!refsOnly) {
|
|
682
|
-
|
|
693
|
+
newSelections.push({
|
|
683
694
|
kind: Kind3.FIELD,
|
|
684
695
|
name: { kind: Kind3.NAME, value: flatFieldName },
|
|
685
696
|
selectionSet: addFlatRefSelections(selection.selectionSet)
|
|
686
|
-
};
|
|
687
|
-
newSelections.push(flatSiblingField);
|
|
688
|
-
}
|
|
689
|
-
} else if (selection.selectionSet && namedTypeName) {
|
|
690
|
-
const transformed = transformSelectionSet(schema, selection.selectionSet, namedTypeName, fragments, refsOnly);
|
|
691
|
-
if (transformed !== selection.selectionSet) {
|
|
692
|
-
changed = true;
|
|
693
|
-
newSelections.push({ ...selection, selectionSet: transformed });
|
|
694
|
-
} else {
|
|
695
|
-
newSelections.push(selection);
|
|
697
|
+
});
|
|
696
698
|
}
|
|
699
|
+
} else if (namedTypeName) {
|
|
700
|
+
recurse(selection, namedTypeName);
|
|
697
701
|
} else {
|
|
698
702
|
newSelections.push(selection);
|
|
699
703
|
}
|
|
700
704
|
} else if (selection.kind === Kind3.INLINE_FRAGMENT) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
const transformed = transformSelectionSet(schema, selection.selectionSet, typeName, fragments, refsOnly);
|
|
706
|
-
if (transformed !== selection.selectionSet) {
|
|
707
|
-
changed = true;
|
|
708
|
-
newSelections.push({ ...selection, selectionSet: transformed });
|
|
709
|
-
} else {
|
|
710
|
-
newSelections.push(selection);
|
|
711
|
-
}
|
|
712
|
-
} else {
|
|
713
|
-
newSelections.push(selection);
|
|
714
|
-
}
|
|
705
|
+
const typeName = selection.typeCondition?.name.value;
|
|
706
|
+
const type = typeName ? schema.getType(typeName) : void 0;
|
|
707
|
+
if (typeName && type && isCompositeType2(type) && isObjectType3(type)) {
|
|
708
|
+
recurse(selection, typeName);
|
|
715
709
|
} else {
|
|
716
710
|
newSelections.push(selection);
|
|
717
711
|
}
|
|
718
|
-
} else
|
|
712
|
+
} else {
|
|
719
713
|
newSelections.push(selection);
|
|
720
714
|
}
|
|
721
715
|
}
|