@constructive-io/graphql-codegen 4.47.15 → 4.48.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.
|
@@ -518,24 +518,22 @@ function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName,
|
|
|
518
518
|
function buildGetHandler(table, targetName, typeRegistry) {
|
|
519
519
|
const { singularName } = (0, utils_1.getTableNames)(table);
|
|
520
520
|
const pkFields = (0, utils_1.getPrimaryKeyInfo)(table);
|
|
521
|
-
const pk = pkFields[0];
|
|
522
521
|
const selectObj = buildSelectObject(table, typeRegistry);
|
|
523
|
-
const
|
|
522
|
+
const promptQuestions = pkFields.map((pkField) => t.objectExpression([
|
|
524
523
|
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
|
|
525
|
-
t.objectProperty(t.identifier('name'), t.stringLiteral(
|
|
526
|
-
t.objectProperty(t.identifier('message'), t.stringLiteral(
|
|
524
|
+
t.objectProperty(t.identifier('name'), t.stringLiteral(pkField.name)),
|
|
525
|
+
t.objectProperty(t.identifier('message'), t.stringLiteral(pkField.name)),
|
|
527
526
|
t.objectProperty(t.identifier('required'), t.booleanLiteral(true)),
|
|
528
|
-
]);
|
|
529
|
-
const pkTsType = pk.gqlType === 'Int' || pk.gqlType === 'BigInt'
|
|
530
|
-
? t.tsNumberKeyword()
|
|
531
|
-
: t.tsStringKeyword();
|
|
527
|
+
]));
|
|
532
528
|
const ormArgs = t.objectExpression([
|
|
533
|
-
t.objectProperty(t.identifier(
|
|
529
|
+
...pkFields.map((pkField) => t.objectProperty(t.identifier(pkField.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pkField.name)), pkField.gqlType === 'Int' || pkField.gqlType === 'BigInt'
|
|
530
|
+
? t.tsNumberKeyword()
|
|
531
|
+
: t.tsStringKeyword()))),
|
|
534
532
|
t.objectProperty(t.identifier('select'), selectObj),
|
|
535
533
|
]);
|
|
536
534
|
const tryBody = [
|
|
537
535
|
t.variableDeclaration('const', [
|
|
538
|
-
t.variableDeclarator(t.identifier('answers'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [t.identifier('argv'), t.arrayExpression(
|
|
536
|
+
t.variableDeclarator(t.identifier('answers'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [t.identifier('argv'), t.arrayExpression(promptQuestions)]))),
|
|
539
537
|
]),
|
|
540
538
|
buildGetClientStatement(targetName),
|
|
541
539
|
t.variableDeclaration('const', [
|
|
@@ -573,9 +571,23 @@ function getFieldsWithDefaults(table, typeRegistry) {
|
|
|
573
571
|
return fieldsWithDefaults;
|
|
574
572
|
}
|
|
575
573
|
function buildMutationHandler(table, operation, vectorFieldNames, targetName, typeRegistry, ormTypes) {
|
|
576
|
-
const { singularName } = (0, utils_1.getTableNames)(table);
|
|
574
|
+
const { singularName, typeName } = (0, utils_1.getTableNames)(table);
|
|
577
575
|
const pkFields = (0, utils_1.getPrimaryKeyInfo)(table);
|
|
578
|
-
const
|
|
576
|
+
const pkFieldNames = new Set(pkFields.map((p) => p.name));
|
|
577
|
+
// Discover extra required fields on mutation input types beyond the PK.
|
|
578
|
+
// For partitioned tables, PostGraphile adds the partition key (e.g. createdAt,
|
|
579
|
+
// databaseId) as a required field on the update/delete input types.
|
|
580
|
+
// These must be included in the CLI where clause to match the ORM's type.
|
|
581
|
+
const patchFieldName = table.query?.patchFieldName ?? (0, utils_1.lcFirst)(typeName) + 'Patch';
|
|
582
|
+
const updateExtraKeys = operation === 'update'
|
|
583
|
+
? (0, utils_1.getExtraInputKeys)((0, utils_1.getUpdateInputTypeName)(table), pkFieldNames, patchFieldName, typeRegistry)
|
|
584
|
+
: [];
|
|
585
|
+
const deleteExtraKeys = operation === 'delete'
|
|
586
|
+
? (0, utils_1.getExtraInputKeys)((0, utils_1.getDeleteInputTypeName)(table), pkFieldNames, null, typeRegistry)
|
|
587
|
+
: [];
|
|
588
|
+
const extraKeys = operation === 'update' ? updateExtraKeys : deleteExtraKeys;
|
|
589
|
+
// All fields that go in the where clause (PK fields + extra keys)
|
|
590
|
+
const allWhereFieldNames = new Set([...pkFieldNames, ...extraKeys.map((ek) => ek.name)]);
|
|
579
591
|
// Get the set of writable field names from the type registry
|
|
580
592
|
// This filters out computed fields (e.g. searchTsvRank, hashUuid) that exist
|
|
581
593
|
// on the entity type but not on the create/update input type.
|
|
@@ -583,7 +595,7 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
583
595
|
// Get fields that have defaults from introspection (for create operations)
|
|
584
596
|
const fieldsWithDefaults = getFieldsWithDefaults(table, typeRegistry);
|
|
585
597
|
// For create: include fields that are in the create input type.
|
|
586
|
-
// For update/delete: always exclude
|
|
598
|
+
// For update/delete: always exclude ALL where-clause fields (PK + extra keys).
|
|
587
599
|
// The ORM input-types generator always excludes these fields from create inputs
|
|
588
600
|
// (see EXCLUDED_MUTATION_FIELDS in input-types-generator.ts). We must match this
|
|
589
601
|
// to avoid generating data properties that don't exist on the ORM create type.
|
|
@@ -591,21 +603,33 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
591
603
|
// since they are user-provided natural keys that DO appear in the create input.
|
|
592
604
|
const ORM_EXCLUDED_FIELDS = ['id', 'createdAt', 'updatedAt', 'nodeId'];
|
|
593
605
|
const editableFields = (0, utils_1.getScalarFields)(table).filter((f) =>
|
|
594
|
-
// For update/delete: always exclude
|
|
606
|
+
// For update/delete: always exclude ALL where-clause fields (PK + extra keys)
|
|
595
607
|
// For create: exclude PK only if it's in the ORM exclusion list (e.g. 'id')
|
|
596
|
-
(f.name
|
|
597
|
-
// Always exclude ORM-excluded fields (except
|
|
598
|
-
(f.name
|
|
608
|
+
(!allWhereFieldNames.has(f.name) || (operation === 'create' && !ORM_EXCLUDED_FIELDS.includes(f.name))) &&
|
|
609
|
+
// Always exclude ORM-excluded fields (except where-clause fields handled above)
|
|
610
|
+
(allWhereFieldNames.has(f.name) || !ORM_EXCLUDED_FIELDS.includes(f.name)) &&
|
|
599
611
|
// If we have type registry info, only include fields that exist in the input type
|
|
600
612
|
(writableFields === null || writableFields.has(f.name)));
|
|
601
613
|
const questions = [];
|
|
602
614
|
if (operation === 'update' || operation === 'delete') {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
615
|
+
// Prompt for all PK fields
|
|
616
|
+
for (const pkField of pkFields) {
|
|
617
|
+
questions.push(t.objectExpression([
|
|
618
|
+
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
|
|
619
|
+
t.objectProperty(t.identifier('name'), t.stringLiteral(pkField.name)),
|
|
620
|
+
t.objectProperty(t.identifier('message'), t.stringLiteral(pkField.name)),
|
|
621
|
+
t.objectProperty(t.identifier('required'), t.booleanLiteral(true)),
|
|
622
|
+
]));
|
|
623
|
+
}
|
|
624
|
+
// Prompt for extra key fields (e.g. partition keys like createdAt, databaseId)
|
|
625
|
+
for (const ek of extraKeys) {
|
|
626
|
+
questions.push(t.objectExpression([
|
|
627
|
+
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
|
|
628
|
+
t.objectProperty(t.identifier('name'), t.stringLiteral(ek.name)),
|
|
629
|
+
t.objectProperty(t.identifier('message'), t.stringLiteral(ek.name)),
|
|
630
|
+
t.objectProperty(t.identifier('required'), t.booleanLiteral(true)),
|
|
631
|
+
]));
|
|
632
|
+
}
|
|
609
633
|
}
|
|
610
634
|
if (operation !== 'delete') {
|
|
611
635
|
for (const field of editableFields) {
|
|
@@ -629,9 +653,7 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
629
653
|
}
|
|
630
654
|
}
|
|
631
655
|
const selectObj = operation === 'delete'
|
|
632
|
-
? t.objectExpression(
|
|
633
|
-
t.objectProperty(t.identifier(pk.name), t.booleanLiteral(true)),
|
|
634
|
-
])
|
|
656
|
+
? t.objectExpression(pkFields.map((pkField) => t.objectProperty(t.identifier(pkField.name), t.booleanLiteral(true))))
|
|
635
657
|
: buildSelectObject(table, typeRegistry);
|
|
636
658
|
let ormArgs;
|
|
637
659
|
// Build data properties without individual type assertions.
|
|
@@ -641,6 +663,14 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
641
663
|
// This handles scalars, enums (string literal unions like ObjectCategory),
|
|
642
664
|
// and array fields uniformly without needing to import each type.
|
|
643
665
|
const buildDataProps = () => editableFields.map((f) => t.objectProperty(t.identifier(f.name), t.memberExpression(t.identifier('cleanedData'), t.identifier(f.name))));
|
|
666
|
+
const buildWhereProps = () => [
|
|
667
|
+
...pkFields.map((pkField) => t.objectProperty(t.identifier(pkField.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pkField.name)), pkField.gqlType === 'Int' || pkField.gqlType === 'BigInt'
|
|
668
|
+
? t.tsNumberKeyword()
|
|
669
|
+
: t.tsStringKeyword()))),
|
|
670
|
+
...extraKeys.map((ek) => t.objectProperty(t.identifier(ek.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(ek.name)), ek.tsType === 'number'
|
|
671
|
+
? t.tsNumberKeyword()
|
|
672
|
+
: t.tsStringKeyword()))),
|
|
673
|
+
];
|
|
644
674
|
if (operation === 'create') {
|
|
645
675
|
ormArgs = t.objectExpression([
|
|
646
676
|
t.objectProperty(t.identifier('data'), t.objectExpression(buildDataProps())),
|
|
@@ -649,22 +679,14 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
649
679
|
}
|
|
650
680
|
else if (operation === 'update') {
|
|
651
681
|
ormArgs = t.objectExpression([
|
|
652
|
-
t.objectProperty(t.identifier('where'), t.objectExpression(
|
|
653
|
-
t.objectProperty(t.identifier(pk.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pk.name)), pk.gqlType === 'Int' || pk.gqlType === 'BigInt'
|
|
654
|
-
? t.tsNumberKeyword()
|
|
655
|
-
: t.tsStringKeyword())),
|
|
656
|
-
])),
|
|
682
|
+
t.objectProperty(t.identifier('where'), t.objectExpression(buildWhereProps())),
|
|
657
683
|
t.objectProperty(t.identifier('data'), t.objectExpression(buildDataProps())),
|
|
658
684
|
t.objectProperty(t.identifier('select'), selectObj),
|
|
659
685
|
]);
|
|
660
686
|
}
|
|
661
687
|
else {
|
|
662
688
|
ormArgs = t.objectExpression([
|
|
663
|
-
t.objectProperty(t.identifier('where'), t.objectExpression(
|
|
664
|
-
t.objectProperty(t.identifier(pk.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pk.name)), pk.gqlType === 'Int' || pk.gqlType === 'BigInt'
|
|
665
|
-
? t.tsNumberKeyword()
|
|
666
|
-
: t.tsStringKeyword())),
|
|
667
|
-
])),
|
|
689
|
+
t.objectProperty(t.identifier('where'), t.objectExpression(buildWhereProps())),
|
|
668
690
|
t.objectProperty(t.identifier('select'), selectObj),
|
|
669
691
|
]);
|
|
670
692
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { toKebabCase } from 'inflekt';
|
|
3
3
|
import { generateCode } from '../babel-ast';
|
|
4
|
-
import { getGeneratedFileHeader, getPrimaryKeyInfo, getScalarFields, getSelectableScalarFields, getTableNames, getWritableFieldNames, resolveInnerInputType, ucFirst, lcFirst, toPascalCase, getCreateInputTypeName, getPatchTypeName, getFilterTypeName, getOrderByTypeName, } from '../utils';
|
|
4
|
+
import { getGeneratedFileHeader, getPrimaryKeyInfo, getScalarFields, getSelectableScalarFields, getTableNames, getWritableFieldNames, resolveInnerInputType, ucFirst, lcFirst, toPascalCase, getCreateInputTypeName, getPatchTypeName, getFilterTypeName, getOrderByTypeName, getExtraInputKeys, getUpdateInputTypeName, getDeleteInputTypeName, } from '../utils';
|
|
5
5
|
import { categorizeSpecialFields } from '../docs-utils';
|
|
6
6
|
function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
|
|
7
7
|
const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
|
|
@@ -481,24 +481,22 @@ function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName,
|
|
|
481
481
|
function buildGetHandler(table, targetName, typeRegistry) {
|
|
482
482
|
const { singularName } = getTableNames(table);
|
|
483
483
|
const pkFields = getPrimaryKeyInfo(table);
|
|
484
|
-
const pk = pkFields[0];
|
|
485
484
|
const selectObj = buildSelectObject(table, typeRegistry);
|
|
486
|
-
const
|
|
485
|
+
const promptQuestions = pkFields.map((pkField) => t.objectExpression([
|
|
487
486
|
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
|
|
488
|
-
t.objectProperty(t.identifier('name'), t.stringLiteral(
|
|
489
|
-
t.objectProperty(t.identifier('message'), t.stringLiteral(
|
|
487
|
+
t.objectProperty(t.identifier('name'), t.stringLiteral(pkField.name)),
|
|
488
|
+
t.objectProperty(t.identifier('message'), t.stringLiteral(pkField.name)),
|
|
490
489
|
t.objectProperty(t.identifier('required'), t.booleanLiteral(true)),
|
|
491
|
-
]);
|
|
492
|
-
const pkTsType = pk.gqlType === 'Int' || pk.gqlType === 'BigInt'
|
|
493
|
-
? t.tsNumberKeyword()
|
|
494
|
-
: t.tsStringKeyword();
|
|
490
|
+
]));
|
|
495
491
|
const ormArgs = t.objectExpression([
|
|
496
|
-
t.objectProperty(t.identifier(
|
|
492
|
+
...pkFields.map((pkField) => t.objectProperty(t.identifier(pkField.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pkField.name)), pkField.gqlType === 'Int' || pkField.gqlType === 'BigInt'
|
|
493
|
+
? t.tsNumberKeyword()
|
|
494
|
+
: t.tsStringKeyword()))),
|
|
497
495
|
t.objectProperty(t.identifier('select'), selectObj),
|
|
498
496
|
]);
|
|
499
497
|
const tryBody = [
|
|
500
498
|
t.variableDeclaration('const', [
|
|
501
|
-
t.variableDeclarator(t.identifier('answers'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [t.identifier('argv'), t.arrayExpression(
|
|
499
|
+
t.variableDeclarator(t.identifier('answers'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [t.identifier('argv'), t.arrayExpression(promptQuestions)]))),
|
|
502
500
|
]),
|
|
503
501
|
buildGetClientStatement(targetName),
|
|
504
502
|
t.variableDeclaration('const', [
|
|
@@ -536,9 +534,23 @@ export function getFieldsWithDefaults(table, typeRegistry) {
|
|
|
536
534
|
return fieldsWithDefaults;
|
|
537
535
|
}
|
|
538
536
|
function buildMutationHandler(table, operation, vectorFieldNames, targetName, typeRegistry, ormTypes) {
|
|
539
|
-
const { singularName } = getTableNames(table);
|
|
537
|
+
const { singularName, typeName } = getTableNames(table);
|
|
540
538
|
const pkFields = getPrimaryKeyInfo(table);
|
|
541
|
-
const
|
|
539
|
+
const pkFieldNames = new Set(pkFields.map((p) => p.name));
|
|
540
|
+
// Discover extra required fields on mutation input types beyond the PK.
|
|
541
|
+
// For partitioned tables, PostGraphile adds the partition key (e.g. createdAt,
|
|
542
|
+
// databaseId) as a required field on the update/delete input types.
|
|
543
|
+
// These must be included in the CLI where clause to match the ORM's type.
|
|
544
|
+
const patchFieldName = table.query?.patchFieldName ?? lcFirst(typeName) + 'Patch';
|
|
545
|
+
const updateExtraKeys = operation === 'update'
|
|
546
|
+
? getExtraInputKeys(getUpdateInputTypeName(table), pkFieldNames, patchFieldName, typeRegistry)
|
|
547
|
+
: [];
|
|
548
|
+
const deleteExtraKeys = operation === 'delete'
|
|
549
|
+
? getExtraInputKeys(getDeleteInputTypeName(table), pkFieldNames, null, typeRegistry)
|
|
550
|
+
: [];
|
|
551
|
+
const extraKeys = operation === 'update' ? updateExtraKeys : deleteExtraKeys;
|
|
552
|
+
// All fields that go in the where clause (PK fields + extra keys)
|
|
553
|
+
const allWhereFieldNames = new Set([...pkFieldNames, ...extraKeys.map((ek) => ek.name)]);
|
|
542
554
|
// Get the set of writable field names from the type registry
|
|
543
555
|
// This filters out computed fields (e.g. searchTsvRank, hashUuid) that exist
|
|
544
556
|
// on the entity type but not on the create/update input type.
|
|
@@ -546,7 +558,7 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
546
558
|
// Get fields that have defaults from introspection (for create operations)
|
|
547
559
|
const fieldsWithDefaults = getFieldsWithDefaults(table, typeRegistry);
|
|
548
560
|
// For create: include fields that are in the create input type.
|
|
549
|
-
// For update/delete: always exclude
|
|
561
|
+
// For update/delete: always exclude ALL where-clause fields (PK + extra keys).
|
|
550
562
|
// The ORM input-types generator always excludes these fields from create inputs
|
|
551
563
|
// (see EXCLUDED_MUTATION_FIELDS in input-types-generator.ts). We must match this
|
|
552
564
|
// to avoid generating data properties that don't exist on the ORM create type.
|
|
@@ -554,21 +566,33 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
554
566
|
// since they are user-provided natural keys that DO appear in the create input.
|
|
555
567
|
const ORM_EXCLUDED_FIELDS = ['id', 'createdAt', 'updatedAt', 'nodeId'];
|
|
556
568
|
const editableFields = getScalarFields(table).filter((f) =>
|
|
557
|
-
// For update/delete: always exclude
|
|
569
|
+
// For update/delete: always exclude ALL where-clause fields (PK + extra keys)
|
|
558
570
|
// For create: exclude PK only if it's in the ORM exclusion list (e.g. 'id')
|
|
559
|
-
(f.name
|
|
560
|
-
// Always exclude ORM-excluded fields (except
|
|
561
|
-
(f.name
|
|
571
|
+
(!allWhereFieldNames.has(f.name) || (operation === 'create' && !ORM_EXCLUDED_FIELDS.includes(f.name))) &&
|
|
572
|
+
// Always exclude ORM-excluded fields (except where-clause fields handled above)
|
|
573
|
+
(allWhereFieldNames.has(f.name) || !ORM_EXCLUDED_FIELDS.includes(f.name)) &&
|
|
562
574
|
// If we have type registry info, only include fields that exist in the input type
|
|
563
575
|
(writableFields === null || writableFields.has(f.name)));
|
|
564
576
|
const questions = [];
|
|
565
577
|
if (operation === 'update' || operation === 'delete') {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
578
|
+
// Prompt for all PK fields
|
|
579
|
+
for (const pkField of pkFields) {
|
|
580
|
+
questions.push(t.objectExpression([
|
|
581
|
+
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
|
|
582
|
+
t.objectProperty(t.identifier('name'), t.stringLiteral(pkField.name)),
|
|
583
|
+
t.objectProperty(t.identifier('message'), t.stringLiteral(pkField.name)),
|
|
584
|
+
t.objectProperty(t.identifier('required'), t.booleanLiteral(true)),
|
|
585
|
+
]));
|
|
586
|
+
}
|
|
587
|
+
// Prompt for extra key fields (e.g. partition keys like createdAt, databaseId)
|
|
588
|
+
for (const ek of extraKeys) {
|
|
589
|
+
questions.push(t.objectExpression([
|
|
590
|
+
t.objectProperty(t.identifier('type'), t.stringLiteral('text')),
|
|
591
|
+
t.objectProperty(t.identifier('name'), t.stringLiteral(ek.name)),
|
|
592
|
+
t.objectProperty(t.identifier('message'), t.stringLiteral(ek.name)),
|
|
593
|
+
t.objectProperty(t.identifier('required'), t.booleanLiteral(true)),
|
|
594
|
+
]));
|
|
595
|
+
}
|
|
572
596
|
}
|
|
573
597
|
if (operation !== 'delete') {
|
|
574
598
|
for (const field of editableFields) {
|
|
@@ -592,9 +616,7 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
592
616
|
}
|
|
593
617
|
}
|
|
594
618
|
const selectObj = operation === 'delete'
|
|
595
|
-
? t.objectExpression(
|
|
596
|
-
t.objectProperty(t.identifier(pk.name), t.booleanLiteral(true)),
|
|
597
|
-
])
|
|
619
|
+
? t.objectExpression(pkFields.map((pkField) => t.objectProperty(t.identifier(pkField.name), t.booleanLiteral(true))))
|
|
598
620
|
: buildSelectObject(table, typeRegistry);
|
|
599
621
|
let ormArgs;
|
|
600
622
|
// Build data properties without individual type assertions.
|
|
@@ -604,6 +626,14 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
604
626
|
// This handles scalars, enums (string literal unions like ObjectCategory),
|
|
605
627
|
// and array fields uniformly without needing to import each type.
|
|
606
628
|
const buildDataProps = () => editableFields.map((f) => t.objectProperty(t.identifier(f.name), t.memberExpression(t.identifier('cleanedData'), t.identifier(f.name))));
|
|
629
|
+
const buildWhereProps = () => [
|
|
630
|
+
...pkFields.map((pkField) => t.objectProperty(t.identifier(pkField.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pkField.name)), pkField.gqlType === 'Int' || pkField.gqlType === 'BigInt'
|
|
631
|
+
? t.tsNumberKeyword()
|
|
632
|
+
: t.tsStringKeyword()))),
|
|
633
|
+
...extraKeys.map((ek) => t.objectProperty(t.identifier(ek.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(ek.name)), ek.tsType === 'number'
|
|
634
|
+
? t.tsNumberKeyword()
|
|
635
|
+
: t.tsStringKeyword()))),
|
|
636
|
+
];
|
|
607
637
|
if (operation === 'create') {
|
|
608
638
|
ormArgs = t.objectExpression([
|
|
609
639
|
t.objectProperty(t.identifier('data'), t.objectExpression(buildDataProps())),
|
|
@@ -612,22 +642,14 @@ function buildMutationHandler(table, operation, vectorFieldNames, targetName, ty
|
|
|
612
642
|
}
|
|
613
643
|
else if (operation === 'update') {
|
|
614
644
|
ormArgs = t.objectExpression([
|
|
615
|
-
t.objectProperty(t.identifier('where'), t.objectExpression(
|
|
616
|
-
t.objectProperty(t.identifier(pk.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pk.name)), pk.gqlType === 'Int' || pk.gqlType === 'BigInt'
|
|
617
|
-
? t.tsNumberKeyword()
|
|
618
|
-
: t.tsStringKeyword())),
|
|
619
|
-
])),
|
|
645
|
+
t.objectProperty(t.identifier('where'), t.objectExpression(buildWhereProps())),
|
|
620
646
|
t.objectProperty(t.identifier('data'), t.objectExpression(buildDataProps())),
|
|
621
647
|
t.objectProperty(t.identifier('select'), selectObj),
|
|
622
648
|
]);
|
|
623
649
|
}
|
|
624
650
|
else {
|
|
625
651
|
ormArgs = t.objectExpression([
|
|
626
|
-
t.objectProperty(t.identifier('where'), t.objectExpression(
|
|
627
|
-
t.objectProperty(t.identifier(pk.name), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(pk.name)), pk.gqlType === 'Int' || pk.gqlType === 'BigInt'
|
|
628
|
-
? t.tsNumberKeyword()
|
|
629
|
-
: t.tsStringKeyword())),
|
|
630
|
-
])),
|
|
652
|
+
t.objectProperty(t.identifier('where'), t.objectExpression(buildWhereProps())),
|
|
631
653
|
t.objectProperty(t.identifier('select'), selectObj),
|
|
632
654
|
]);
|
|
633
655
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-codegen",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.48.0",
|
|
4
4
|
"description": "GraphQL SDK generator for Constructive databases with React Query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@0no-co/graphql.web": "^1.1.2",
|
|
57
57
|
"@babel/generator": "^7.29.1",
|
|
58
58
|
"@babel/types": "^7.29.0",
|
|
59
|
-
"@constructive-io/graphql-query": "^3.
|
|
59
|
+
"@constructive-io/graphql-query": "^3.28.0",
|
|
60
60
|
"@constructive-io/graphql-types": "^3.12.1",
|
|
61
61
|
"@inquirerer/utils": "^3.3.7",
|
|
62
62
|
"@pgpmjs/core": "^6.24.1",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"deepmerge": "^4.3.1",
|
|
65
65
|
"find-and-require-package-json": "^0.9.1",
|
|
66
66
|
"gql-ast": "^3.11.0",
|
|
67
|
-
"graphile-schema": "^1.
|
|
67
|
+
"graphile-schema": "^1.23.0",
|
|
68
68
|
"graphql": "16.13.0",
|
|
69
69
|
"inflekt": "^0.7.1",
|
|
70
70
|
"inquirerer": "^4.8.1",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"tsx": "^4.21.0",
|
|
101
101
|
"typescript": "^5.9.3"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "03d9e7ed4808d1d957b495a33980022172494340"
|
|
104
104
|
}
|