@constructive-io/graphql-codegen 2.19.0 → 2.20.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/README.md +1818 -113
- package/__tests__/codegen/input-types-generator.test.d.ts +1 -0
- package/__tests__/codegen/input-types-generator.test.js +635 -0
- package/cli/codegen/barrel.d.ts +27 -0
- package/cli/codegen/barrel.js +163 -0
- package/cli/codegen/client.d.ts +4 -0
- package/cli/codegen/client.js +170 -0
- package/cli/codegen/custom-mutations.d.ts +38 -0
- package/cli/codegen/custom-mutations.js +149 -0
- package/cli/codegen/custom-queries.d.ts +38 -0
- package/cli/codegen/custom-queries.js +358 -0
- package/cli/codegen/filters.d.ts +27 -0
- package/cli/codegen/filters.js +357 -0
- package/cli/codegen/gql-ast.d.ts +41 -0
- package/cli/codegen/gql-ast.js +329 -0
- package/cli/codegen/index.d.ts +71 -0
- package/cli/codegen/index.js +147 -0
- package/cli/codegen/mutations.d.ts +30 -0
- package/cli/codegen/mutations.js +410 -0
- package/cli/codegen/orm/barrel.d.ts +18 -0
- package/cli/codegen/orm/barrel.js +48 -0
- package/cli/codegen/orm/client-generator.d.ts +45 -0
- package/cli/codegen/orm/client-generator.js +646 -0
- package/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
- package/cli/codegen/orm/custom-ops-generator.js +350 -0
- package/cli/codegen/orm/index.d.ts +38 -0
- package/cli/codegen/orm/index.js +88 -0
- package/cli/codegen/orm/input-types-generator.d.ts +21 -0
- package/cli/codegen/orm/input-types-generator.js +705 -0
- package/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
- package/cli/codegen/orm/input-types-generator.test.js +75 -0
- package/cli/codegen/orm/model-generator.d.ts +32 -0
- package/cli/codegen/orm/model-generator.js +264 -0
- package/cli/codegen/orm/query-builder.d.ts +161 -0
- package/cli/codegen/orm/query-builder.js +366 -0
- package/cli/codegen/orm/select-types.d.ts +169 -0
- package/cli/codegen/orm/select-types.js +16 -0
- package/cli/codegen/orm/select-types.test.d.ts +11 -0
- package/cli/codegen/orm/select-types.test.js +22 -0
- package/cli/codegen/queries.d.ts +25 -0
- package/cli/codegen/queries.js +438 -0
- package/cli/codegen/scalars.d.ts +12 -0
- package/cli/codegen/scalars.js +71 -0
- package/cli/codegen/schema-gql-ast.d.ts +51 -0
- package/cli/codegen/schema-gql-ast.js +385 -0
- package/cli/codegen/ts-ast.d.ts +122 -0
- package/cli/codegen/ts-ast.js +280 -0
- package/cli/codegen/type-resolver.d.ts +96 -0
- package/cli/codegen/type-resolver.js +246 -0
- package/cli/codegen/types.d.ts +12 -0
- package/cli/codegen/types.js +69 -0
- package/cli/codegen/utils.d.ts +163 -0
- package/cli/codegen/utils.js +326 -0
- package/cli/commands/generate-orm.d.ts +37 -0
- package/cli/commands/generate-orm.js +195 -0
- package/cli/commands/generate.d.ts +39 -0
- package/cli/commands/generate.js +299 -0
- package/cli/commands/index.d.ts +7 -0
- package/cli/commands/index.js +12 -0
- package/cli/commands/init.d.ts +35 -0
- package/cli/commands/init.js +176 -0
- package/cli/index.d.ts +4 -0
- package/cli/index.js +291 -0
- package/cli/introspect/fetch-meta.d.ts +31 -0
- package/cli/introspect/fetch-meta.js +108 -0
- package/cli/introspect/fetch-schema.d.ts +21 -0
- package/cli/introspect/fetch-schema.js +86 -0
- package/cli/introspect/index.d.ts +8 -0
- package/cli/introspect/index.js +16 -0
- package/cli/introspect/meta-query.d.ts +111 -0
- package/cli/introspect/meta-query.js +191 -0
- package/cli/introspect/schema-query.d.ts +20 -0
- package/cli/introspect/schema-query.js +123 -0
- package/cli/introspect/transform-schema.d.ts +74 -0
- package/cli/introspect/transform-schema.js +269 -0
- package/cli/introspect/transform-schema.test.d.ts +1 -0
- package/cli/introspect/transform-schema.test.js +67 -0
- package/cli/introspect/transform.d.ts +21 -0
- package/cli/introspect/transform.js +216 -0
- package/cli/watch/cache.d.ts +45 -0
- package/cli/watch/cache.js +111 -0
- package/cli/watch/debounce.d.ts +19 -0
- package/cli/watch/debounce.js +89 -0
- package/cli/watch/hash.d.ts +17 -0
- package/cli/watch/hash.js +48 -0
- package/cli/watch/index.d.ts +10 -0
- package/cli/watch/index.js +22 -0
- package/cli/watch/orchestrator.d.ts +63 -0
- package/cli/watch/orchestrator.js +228 -0
- package/cli/watch/poller.d.ts +65 -0
- package/cli/watch/poller.js +203 -0
- package/cli/watch/types.d.ts +67 -0
- package/cli/watch/types.js +5 -0
- package/client/error.d.ts +95 -0
- package/client/error.js +255 -0
- package/client/execute.d.ts +57 -0
- package/client/execute.js +124 -0
- package/client/index.d.ts +6 -0
- package/client/index.js +18 -0
- package/client/typed-document.d.ts +31 -0
- package/client/typed-document.js +44 -0
- package/core/ast.d.ts +10 -0
- package/core/ast.js +593 -0
- package/core/custom-ast.d.ts +35 -0
- package/core/custom-ast.js +204 -0
- package/core/index.d.ts +8 -0
- package/core/index.js +33 -0
- package/core/meta-object/convert.d.ts +65 -0
- package/core/meta-object/convert.js +63 -0
- package/core/meta-object/format.json +93 -0
- package/core/meta-object/index.d.ts +2 -0
- package/core/meta-object/index.js +18 -0
- package/core/meta-object/validate.d.ts +9 -0
- package/core/meta-object/validate.js +34 -0
- package/core/query-builder.d.ts +46 -0
- package/core/query-builder.js +412 -0
- package/core/types.d.ts +139 -0
- package/core/types.js +28 -0
- package/esm/__tests__/codegen/input-types-generator.test.d.ts +1 -0
- package/esm/__tests__/codegen/input-types-generator.test.js +633 -0
- package/esm/cli/codegen/barrel.d.ts +27 -0
- package/esm/cli/codegen/barrel.js +156 -0
- package/esm/cli/codegen/client.d.ts +4 -0
- package/esm/cli/codegen/client.js +167 -0
- package/esm/cli/codegen/custom-mutations.d.ts +38 -0
- package/esm/cli/codegen/custom-mutations.js +145 -0
- package/esm/cli/codegen/custom-queries.d.ts +38 -0
- package/esm/cli/codegen/custom-queries.js +354 -0
- package/esm/cli/codegen/filters.d.ts +27 -0
- package/esm/cli/codegen/filters.js +351 -0
- package/esm/cli/codegen/gql-ast.d.ts +41 -0
- package/esm/cli/codegen/gql-ast.js +288 -0
- package/esm/cli/codegen/index.d.ts +71 -0
- package/esm/cli/codegen/index.js +124 -0
- package/esm/cli/codegen/mutations.d.ts +30 -0
- package/esm/cli/codegen/mutations.js +404 -0
- package/esm/cli/codegen/orm/barrel.d.ts +18 -0
- package/esm/cli/codegen/orm/barrel.js +44 -0
- package/esm/cli/codegen/orm/client-generator.d.ts +45 -0
- package/esm/cli/codegen/orm/client-generator.js +640 -0
- package/esm/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
- package/esm/cli/codegen/orm/custom-ops-generator.js +346 -0
- package/esm/cli/codegen/orm/index.d.ts +38 -0
- package/esm/cli/codegen/orm/index.js +75 -0
- package/esm/cli/codegen/orm/input-types-generator.d.ts +21 -0
- package/esm/cli/codegen/orm/input-types-generator.js +700 -0
- package/esm/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
- package/esm/cli/codegen/orm/input-types-generator.test.js +73 -0
- package/esm/cli/codegen/orm/model-generator.d.ts +32 -0
- package/esm/cli/codegen/orm/model-generator.js +260 -0
- package/esm/cli/codegen/orm/query-builder.d.ts +161 -0
- package/esm/cli/codegen/orm/query-builder.js +353 -0
- package/esm/cli/codegen/orm/select-types.d.ts +169 -0
- package/esm/cli/codegen/orm/select-types.js +15 -0
- package/esm/cli/codegen/orm/select-types.test.d.ts +11 -0
- package/esm/cli/codegen/orm/select-types.test.js +21 -0
- package/esm/cli/codegen/queries.d.ts +25 -0
- package/esm/cli/codegen/queries.js +433 -0
- package/esm/cli/codegen/scalars.d.ts +12 -0
- package/esm/cli/codegen/scalars.js +66 -0
- package/esm/cli/codegen/schema-gql-ast.d.ts +51 -0
- package/esm/cli/codegen/schema-gql-ast.js +343 -0
- package/esm/cli/codegen/ts-ast.d.ts +122 -0
- package/esm/cli/codegen/ts-ast.js +260 -0
- package/esm/cli/codegen/type-resolver.d.ts +96 -0
- package/esm/cli/codegen/type-resolver.js +224 -0
- package/esm/cli/codegen/types.d.ts +12 -0
- package/esm/cli/codegen/types.js +65 -0
- package/esm/cli/codegen/utils.d.ts +163 -0
- package/esm/cli/codegen/utils.js +288 -0
- package/esm/cli/commands/generate-orm.d.ts +37 -0
- package/esm/cli/commands/generate-orm.js +192 -0
- package/esm/cli/commands/generate.d.ts +39 -0
- package/esm/cli/commands/generate.js +262 -0
- package/esm/cli/commands/index.d.ts +7 -0
- package/esm/cli/commands/index.js +5 -0
- package/esm/cli/commands/init.d.ts +35 -0
- package/esm/cli/commands/init.js +138 -0
- package/esm/cli/index.d.ts +4 -0
- package/esm/cli/index.js +256 -0
- package/esm/cli/introspect/fetch-meta.d.ts +31 -0
- package/esm/cli/introspect/fetch-meta.js +104 -0
- package/esm/cli/introspect/fetch-schema.d.ts +21 -0
- package/esm/cli/introspect/fetch-schema.js +83 -0
- package/esm/cli/introspect/index.d.ts +8 -0
- package/esm/cli/introspect/index.js +6 -0
- package/esm/cli/introspect/meta-query.d.ts +111 -0
- package/esm/cli/introspect/meta-query.js +188 -0
- package/esm/cli/introspect/schema-query.d.ts +20 -0
- package/esm/cli/introspect/schema-query.js +120 -0
- package/esm/cli/introspect/transform-schema.d.ts +74 -0
- package/esm/cli/introspect/transform-schema.js +259 -0
- package/esm/cli/introspect/transform-schema.test.d.ts +1 -0
- package/esm/cli/introspect/transform-schema.test.js +65 -0
- package/esm/cli/introspect/transform.d.ts +21 -0
- package/esm/cli/introspect/transform.js +210 -0
- package/esm/cli/watch/cache.d.ts +45 -0
- package/esm/cli/watch/cache.js +73 -0
- package/esm/cli/watch/debounce.d.ts +19 -0
- package/esm/cli/watch/debounce.js +85 -0
- package/esm/cli/watch/hash.d.ts +17 -0
- package/esm/cli/watch/hash.js +43 -0
- package/esm/cli/watch/index.d.ts +10 -0
- package/esm/cli/watch/index.js +8 -0
- package/esm/cli/watch/orchestrator.d.ts +63 -0
- package/esm/cli/watch/orchestrator.js +223 -0
- package/esm/cli/watch/poller.d.ts +65 -0
- package/esm/cli/watch/poller.js +198 -0
- package/esm/cli/watch/types.d.ts +67 -0
- package/esm/cli/watch/types.js +4 -0
- package/esm/client/error.d.ts +95 -0
- package/esm/client/error.js +249 -0
- package/esm/client/execute.d.ts +57 -0
- package/esm/client/execute.js +120 -0
- package/esm/client/index.d.ts +6 -0
- package/esm/client/index.js +6 -0
- package/esm/client/typed-document.d.ts +31 -0
- package/esm/client/typed-document.js +40 -0
- package/esm/core/ast.d.ts +10 -0
- package/esm/core/ast.js +549 -0
- package/esm/core/custom-ast.d.ts +35 -0
- package/esm/core/custom-ast.js +161 -0
- package/esm/core/index.d.ts +8 -0
- package/esm/core/index.js +12 -0
- package/esm/core/meta-object/convert.d.ts +65 -0
- package/esm/core/meta-object/convert.js +60 -0
- package/esm/core/meta-object/format.json +93 -0
- package/esm/core/meta-object/index.d.ts +2 -0
- package/esm/core/meta-object/index.js +2 -0
- package/esm/core/meta-object/validate.d.ts +9 -0
- package/esm/core/meta-object/validate.js +28 -0
- package/esm/core/query-builder.d.ts +46 -0
- package/esm/core/query-builder.js +375 -0
- package/esm/core/types.d.ts +139 -0
- package/esm/core/types.js +24 -0
- package/esm/generators/field-selector.d.ts +30 -0
- package/esm/generators/field-selector.js +355 -0
- package/esm/generators/index.d.ts +6 -0
- package/esm/generators/index.js +9 -0
- package/esm/generators/mutations.d.ts +31 -0
- package/esm/generators/mutations.js +197 -0
- package/esm/generators/select.d.ts +50 -0
- package/esm/generators/select.js +636 -0
- package/esm/index.d.ts +12 -0
- package/esm/index.js +17 -3
- package/esm/react/index.d.ts +5 -0
- package/esm/react/index.js +6 -0
- package/esm/types/config.d.ts +199 -0
- package/esm/types/config.js +106 -0
- package/esm/types/index.d.ts +9 -0
- package/esm/types/index.js +4 -0
- package/esm/types/introspection.d.ts +121 -0
- package/esm/types/introspection.js +54 -0
- package/esm/types/mutation.d.ts +45 -0
- package/esm/types/mutation.js +4 -0
- package/esm/types/query.d.ts +82 -0
- package/esm/types/query.js +4 -0
- package/esm/types/schema.d.ts +253 -0
- package/esm/types/schema.js +5 -0
- package/esm/types/selection.d.ts +43 -0
- package/esm/types/selection.js +4 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.js +4 -0
- package/generators/field-selector.d.ts +30 -0
- package/generators/field-selector.js +361 -0
- package/generators/index.d.ts +6 -0
- package/generators/index.js +27 -0
- package/generators/mutations.d.ts +31 -0
- package/generators/mutations.js +235 -0
- package/generators/select.d.ts +50 -0
- package/generators/select.js +679 -0
- package/index.d.ts +12 -3
- package/index.js +19 -3
- package/package.json +59 -38
- package/react/index.d.ts +5 -0
- package/react/index.js +9 -0
- package/types/config.d.ts +199 -0
- package/types/config.js +111 -0
- package/types/index.d.ts +9 -0
- package/types/index.js +10 -0
- package/types/introspection.d.ts +121 -0
- package/types/introspection.js +62 -0
- package/types/mutation.d.ts +45 -0
- package/types/mutation.js +5 -0
- package/types/query.d.ts +82 -0
- package/types/query.js +5 -0
- package/types/schema.d.ts +253 -0
- package/types/schema.js +6 -0
- package/types/selection.d.ts +43 -0
- package/types/selection.js +5 -0
- package/utils/index.d.ts +4 -0
- package/utils/index.js +7 -0
- package/codegen.d.ts +0 -13
- package/codegen.js +0 -293
- package/esm/codegen.js +0 -253
- package/esm/gql.js +0 -939
- package/esm/options.js +0 -27
- package/gql.d.ts +0 -188
- package/gql.js +0 -992
- package/options.d.ts +0 -45
- package/options.js +0 -31
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToSelectionOptions = convertToSelectionOptions;
|
|
4
|
+
exports.isRelationalField = isRelationalField;
|
|
5
|
+
exports.getAvailableRelations = getAvailableRelations;
|
|
6
|
+
exports.validateFieldSelection = validateFieldSelection;
|
|
7
|
+
/**
|
|
8
|
+
* Convert simplified field selection to QueryBuilder SelectionOptions
|
|
9
|
+
*/
|
|
10
|
+
function convertToSelectionOptions(table, allTables, selection) {
|
|
11
|
+
if (!selection) {
|
|
12
|
+
return convertPresetToSelection(table, 'display');
|
|
13
|
+
}
|
|
14
|
+
if (typeof selection === 'string') {
|
|
15
|
+
return convertPresetToSelection(table, selection);
|
|
16
|
+
}
|
|
17
|
+
return convertCustomSelectionToOptions(table, allTables, selection);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert preset to selection options
|
|
21
|
+
*/
|
|
22
|
+
function convertPresetToSelection(table, preset) {
|
|
23
|
+
const options = {};
|
|
24
|
+
switch (preset) {
|
|
25
|
+
case 'minimal': {
|
|
26
|
+
// Just id and first display field
|
|
27
|
+
const minimalFields = getMinimalFields(table);
|
|
28
|
+
minimalFields.forEach((field) => {
|
|
29
|
+
options[field] = true;
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'display': {
|
|
34
|
+
// Common display fields
|
|
35
|
+
const displayFields = getDisplayFields(table);
|
|
36
|
+
displayFields.forEach((field) => {
|
|
37
|
+
options[field] = true;
|
|
38
|
+
});
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'all': {
|
|
42
|
+
// All non-relational fields (includes complex fields like JSON, geometry, etc.)
|
|
43
|
+
const allFields = getNonRelationalFields(table);
|
|
44
|
+
allFields.forEach((field) => {
|
|
45
|
+
options[field] = true;
|
|
46
|
+
});
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'full':
|
|
50
|
+
// All fields including basic relations
|
|
51
|
+
table.fields.forEach((field) => {
|
|
52
|
+
options[field.name] = true;
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
default: {
|
|
56
|
+
// Default to display
|
|
57
|
+
const defaultFields = getDisplayFields(table);
|
|
58
|
+
defaultFields.forEach((field) => {
|
|
59
|
+
options[field] = true;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return options;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Convert custom selection to options
|
|
67
|
+
*/
|
|
68
|
+
function convertCustomSelectionToOptions(table, allTables, selection) {
|
|
69
|
+
const options = {};
|
|
70
|
+
// Start with selected fields or all non-relational fields (including complex types)
|
|
71
|
+
let fieldsToInclude;
|
|
72
|
+
if (selection.select) {
|
|
73
|
+
fieldsToInclude = selection.select;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
fieldsToInclude = getNonRelationalFields(table);
|
|
77
|
+
}
|
|
78
|
+
// Add basic fields
|
|
79
|
+
fieldsToInclude.forEach((field) => {
|
|
80
|
+
if (table.fields.some((f) => f.name === field)) {
|
|
81
|
+
options[field] = true;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// Handle includeRelations (simple API for relation fields)
|
|
85
|
+
if (selection.includeRelations) {
|
|
86
|
+
selection.includeRelations.forEach((relationField) => {
|
|
87
|
+
if (isRelationalField(relationField, table)) {
|
|
88
|
+
// Include with dynamically determined scalar fields from the related table
|
|
89
|
+
options[relationField] = {
|
|
90
|
+
select: getRelatedTableScalarFields(relationField, table, allTables),
|
|
91
|
+
variables: {},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Handle includes (relations) - more detailed API
|
|
97
|
+
if (selection.include) {
|
|
98
|
+
Object.entries(selection.include).forEach(([relationField, relationSelection]) => {
|
|
99
|
+
if (isRelationalField(relationField, table)) {
|
|
100
|
+
if (relationSelection === true) {
|
|
101
|
+
// Include with dynamically determined scalar fields from the related table
|
|
102
|
+
options[relationField] = {
|
|
103
|
+
select: getRelatedTableScalarFields(relationField, table, allTables),
|
|
104
|
+
variables: {},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
else if (Array.isArray(relationSelection)) {
|
|
108
|
+
// Include with specific fields
|
|
109
|
+
const selectObj = {};
|
|
110
|
+
relationSelection.forEach((field) => {
|
|
111
|
+
selectObj[field] = true;
|
|
112
|
+
});
|
|
113
|
+
options[relationField] = {
|
|
114
|
+
select: selectObj,
|
|
115
|
+
variables: {},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// Handle excludes
|
|
122
|
+
if (selection.exclude) {
|
|
123
|
+
selection.exclude.forEach((field) => {
|
|
124
|
+
delete options[field];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return options;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get minimal fields - completely schema-driven, no hardcoded assumptions
|
|
131
|
+
*/
|
|
132
|
+
function getMinimalFields(table) {
|
|
133
|
+
// Get all non-relational fields from the actual schema
|
|
134
|
+
const nonRelationalFields = getNonRelationalFields(table);
|
|
135
|
+
// Return the first few fields from the schema (typically includes primary key and basic fields)
|
|
136
|
+
// This is completely dynamic based on what the schema actually provides
|
|
137
|
+
return nonRelationalFields.slice(0, 3); // Limit to first 3 fields for minimal selection
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get display fields - completely schema-driven, no hardcoded field names
|
|
141
|
+
*/
|
|
142
|
+
function getDisplayFields(table) {
|
|
143
|
+
// Get all non-relational fields from the actual schema
|
|
144
|
+
const nonRelationalFields = getNonRelationalFields(table);
|
|
145
|
+
// Return a reasonable subset for display purposes (first half of available fields)
|
|
146
|
+
// This is completely dynamic based on what the schema actually provides
|
|
147
|
+
const maxDisplayFields = Math.max(5, Math.floor(nonRelationalFields.length / 2));
|
|
148
|
+
return nonRelationalFields.slice(0, maxDisplayFields);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get all non-relational fields (includes both scalar and complex fields)
|
|
152
|
+
* Complex fields like JSON, geometry, images should be included by default
|
|
153
|
+
*/
|
|
154
|
+
function getNonRelationalFields(table) {
|
|
155
|
+
return table.fields
|
|
156
|
+
.filter((field) => !isRelationalField(field.name, table))
|
|
157
|
+
.map((field) => field.name);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if a field is relational using table metadata
|
|
161
|
+
*/
|
|
162
|
+
function isRelationalField(fieldName, table) {
|
|
163
|
+
const { belongsTo, hasOne, hasMany, manyToMany } = table.relations;
|
|
164
|
+
return (belongsTo.some((rel) => rel.fieldName === fieldName) ||
|
|
165
|
+
hasOne.some((rel) => rel.fieldName === fieldName) ||
|
|
166
|
+
hasMany.some((rel) => rel.fieldName === fieldName) ||
|
|
167
|
+
manyToMany.some((rel) => rel.fieldName === fieldName));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get scalar fields for a related table to include in relation queries
|
|
171
|
+
* Uses only the _meta query data - no hardcoded field names or assumptions
|
|
172
|
+
*/
|
|
173
|
+
function getRelatedTableScalarFields(relationField, table, allTables) {
|
|
174
|
+
// Find the related table name
|
|
175
|
+
let referencedTableName;
|
|
176
|
+
// Check belongsTo relations
|
|
177
|
+
const belongsToRel = table.relations.belongsTo.find((rel) => rel.fieldName === relationField);
|
|
178
|
+
if (belongsToRel) {
|
|
179
|
+
referencedTableName = belongsToRel.referencesTable;
|
|
180
|
+
}
|
|
181
|
+
// Check hasOne relations
|
|
182
|
+
if (!referencedTableName) {
|
|
183
|
+
const hasOneRel = table.relations.hasOne.find((rel) => rel.fieldName === relationField);
|
|
184
|
+
if (hasOneRel) {
|
|
185
|
+
referencedTableName = hasOneRel.referencedByTable;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Check hasMany relations
|
|
189
|
+
if (!referencedTableName) {
|
|
190
|
+
const hasManyRel = table.relations.hasMany.find((rel) => rel.fieldName === relationField);
|
|
191
|
+
if (hasManyRel) {
|
|
192
|
+
referencedTableName = hasManyRel.referencedByTable;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Check manyToMany relations
|
|
196
|
+
if (!referencedTableName) {
|
|
197
|
+
const manyToManyRel = table.relations.manyToMany.find((rel) => rel.fieldName === relationField);
|
|
198
|
+
if (manyToManyRel) {
|
|
199
|
+
referencedTableName = manyToManyRel.rightTable;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (!referencedTableName) {
|
|
203
|
+
// No related table found - return empty selection
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
// Find the related table in allTables
|
|
207
|
+
const relatedTable = allTables.find((t) => t.name === referencedTableName);
|
|
208
|
+
if (!relatedTable) {
|
|
209
|
+
// Related table not found in schema - return empty selection
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
// Get ALL scalar fields from the related table (non-relational fields)
|
|
213
|
+
// This is completely dynamic based on the actual schema
|
|
214
|
+
const scalarFields = relatedTable.fields
|
|
215
|
+
.filter((field) => !isRelationalField(field.name, relatedTable))
|
|
216
|
+
.map((field) => field.name);
|
|
217
|
+
// Perf guardrail: select a small, display-oriented subset.
|
|
218
|
+
const MAX_RELATED_FIELDS = 8;
|
|
219
|
+
const preferred = [
|
|
220
|
+
'displayName',
|
|
221
|
+
'fullName',
|
|
222
|
+
'preferredName',
|
|
223
|
+
'nickname',
|
|
224
|
+
'firstName',
|
|
225
|
+
'lastName',
|
|
226
|
+
'username',
|
|
227
|
+
'email',
|
|
228
|
+
'name',
|
|
229
|
+
'title',
|
|
230
|
+
'label',
|
|
231
|
+
'slug',
|
|
232
|
+
'code',
|
|
233
|
+
'createdAt',
|
|
234
|
+
'updatedAt',
|
|
235
|
+
];
|
|
236
|
+
const included = [];
|
|
237
|
+
const push = (fieldName) => {
|
|
238
|
+
if (!fieldName)
|
|
239
|
+
return;
|
|
240
|
+
if (!scalarFields.includes(fieldName))
|
|
241
|
+
return;
|
|
242
|
+
if (included.includes(fieldName))
|
|
243
|
+
return;
|
|
244
|
+
if (included.length >= MAX_RELATED_FIELDS)
|
|
245
|
+
return;
|
|
246
|
+
included.push(fieldName);
|
|
247
|
+
};
|
|
248
|
+
// Always try to include stable identifiers first.
|
|
249
|
+
push('id');
|
|
250
|
+
push('nodeId');
|
|
251
|
+
for (const fieldName of preferred)
|
|
252
|
+
push(fieldName);
|
|
253
|
+
for (const fieldName of scalarFields)
|
|
254
|
+
push(fieldName);
|
|
255
|
+
const selection = {};
|
|
256
|
+
for (const fieldName of included)
|
|
257
|
+
selection[fieldName] = true;
|
|
258
|
+
return selection;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Get all available relation fields from a table
|
|
262
|
+
*/
|
|
263
|
+
function getAvailableRelations(table) {
|
|
264
|
+
const relations = [];
|
|
265
|
+
// Add belongsTo relations
|
|
266
|
+
table.relations.belongsTo.forEach((rel) => {
|
|
267
|
+
if (rel.fieldName) {
|
|
268
|
+
relations.push({
|
|
269
|
+
fieldName: rel.fieldName,
|
|
270
|
+
type: 'belongsTo',
|
|
271
|
+
referencedTable: rel.referencesTable || undefined,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
// Add hasOne relations
|
|
276
|
+
table.relations.hasOne.forEach((rel) => {
|
|
277
|
+
if (rel.fieldName) {
|
|
278
|
+
relations.push({
|
|
279
|
+
fieldName: rel.fieldName,
|
|
280
|
+
type: 'hasOne',
|
|
281
|
+
referencedTable: rel.referencedByTable || undefined,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
// Add hasMany relations
|
|
286
|
+
table.relations.hasMany.forEach((rel) => {
|
|
287
|
+
if (rel.fieldName) {
|
|
288
|
+
relations.push({
|
|
289
|
+
fieldName: rel.fieldName,
|
|
290
|
+
type: 'hasMany',
|
|
291
|
+
referencedTable: rel.referencedByTable || undefined,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
// Add manyToMany relations
|
|
296
|
+
table.relations.manyToMany.forEach((rel) => {
|
|
297
|
+
if (rel.fieldName) {
|
|
298
|
+
relations.push({
|
|
299
|
+
fieldName: rel.fieldName,
|
|
300
|
+
type: 'manyToMany',
|
|
301
|
+
referencedTable: rel.rightTable || undefined,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
return relations;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Validate field selection against table schema
|
|
309
|
+
*/
|
|
310
|
+
function validateFieldSelection(selection, table) {
|
|
311
|
+
const errors = [];
|
|
312
|
+
if (typeof selection === 'string') {
|
|
313
|
+
// Presets are always valid
|
|
314
|
+
return { isValid: true, errors: [] };
|
|
315
|
+
}
|
|
316
|
+
const tableFieldNames = table.fields.map((f) => f.name);
|
|
317
|
+
// Validate select fields
|
|
318
|
+
if (selection.select) {
|
|
319
|
+
selection.select.forEach((field) => {
|
|
320
|
+
if (!tableFieldNames.includes(field)) {
|
|
321
|
+
errors.push(`Field '${field}' does not exist in table '${table.name}'`);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
// Validate includeRelations fields
|
|
326
|
+
if (selection.includeRelations) {
|
|
327
|
+
selection.includeRelations.forEach((field) => {
|
|
328
|
+
if (!isRelationalField(field, table)) {
|
|
329
|
+
errors.push(`Field '${field}' is not a relational field in table '${table.name}'`);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// Validate include fields
|
|
334
|
+
if (selection.include) {
|
|
335
|
+
Object.keys(selection.include).forEach((field) => {
|
|
336
|
+
if (!isRelationalField(field, table)) {
|
|
337
|
+
errors.push(`Field '${field}' is not a relational field in table '${table.name}'`);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
// Validate exclude fields
|
|
342
|
+
if (selection.exclude) {
|
|
343
|
+
selection.exclude.forEach((field) => {
|
|
344
|
+
if (!tableFieldNames.includes(field)) {
|
|
345
|
+
errors.push(`Exclude field '${field}' does not exist in table '${table.name}'`);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
// Validate maxDepth
|
|
350
|
+
if (selection.maxDepth !== undefined) {
|
|
351
|
+
if (typeof selection.maxDepth !== 'number' ||
|
|
352
|
+
selection.maxDepth < 0 ||
|
|
353
|
+
selection.maxDepth > 5) {
|
|
354
|
+
errors.push('maxDepth must be a number between 0 and 5');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
isValid: errors.length === 0,
|
|
359
|
+
errors,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query and mutation generator exports
|
|
3
|
+
*/
|
|
4
|
+
export { convertToSelectionOptions, isRelationalField, getAvailableRelations, validateFieldSelection, } from './field-selector';
|
|
5
|
+
export { buildSelect, buildFindOne, buildCount, toCamelCasePlural, toOrderByTypeName, cleanTableToMetaObject, generateIntrospectionSchema, createASTQueryBuilder, } from './select';
|
|
6
|
+
export { buildPostGraphileCreate, buildPostGraphileUpdate, buildPostGraphileDelete, } from './mutations';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query and mutation generator exports
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildPostGraphileDelete = exports.buildPostGraphileUpdate = exports.buildPostGraphileCreate = exports.createASTQueryBuilder = exports.generateIntrospectionSchema = exports.cleanTableToMetaObject = exports.toOrderByTypeName = exports.toCamelCasePlural = exports.buildCount = exports.buildFindOne = exports.buildSelect = exports.validateFieldSelection = exports.getAvailableRelations = exports.isRelationalField = exports.convertToSelectionOptions = void 0;
|
|
7
|
+
// Field selector utilities
|
|
8
|
+
var field_selector_1 = require("./field-selector");
|
|
9
|
+
Object.defineProperty(exports, "convertToSelectionOptions", { enumerable: true, get: function () { return field_selector_1.convertToSelectionOptions; } });
|
|
10
|
+
Object.defineProperty(exports, "isRelationalField", { enumerable: true, get: function () { return field_selector_1.isRelationalField; } });
|
|
11
|
+
Object.defineProperty(exports, "getAvailableRelations", { enumerable: true, get: function () { return field_selector_1.getAvailableRelations; } });
|
|
12
|
+
Object.defineProperty(exports, "validateFieldSelection", { enumerable: true, get: function () { return field_selector_1.validateFieldSelection; } });
|
|
13
|
+
// Query generators
|
|
14
|
+
var select_1 = require("./select");
|
|
15
|
+
Object.defineProperty(exports, "buildSelect", { enumerable: true, get: function () { return select_1.buildSelect; } });
|
|
16
|
+
Object.defineProperty(exports, "buildFindOne", { enumerable: true, get: function () { return select_1.buildFindOne; } });
|
|
17
|
+
Object.defineProperty(exports, "buildCount", { enumerable: true, get: function () { return select_1.buildCount; } });
|
|
18
|
+
Object.defineProperty(exports, "toCamelCasePlural", { enumerable: true, get: function () { return select_1.toCamelCasePlural; } });
|
|
19
|
+
Object.defineProperty(exports, "toOrderByTypeName", { enumerable: true, get: function () { return select_1.toOrderByTypeName; } });
|
|
20
|
+
Object.defineProperty(exports, "cleanTableToMetaObject", { enumerable: true, get: function () { return select_1.cleanTableToMetaObject; } });
|
|
21
|
+
Object.defineProperty(exports, "generateIntrospectionSchema", { enumerable: true, get: function () { return select_1.generateIntrospectionSchema; } });
|
|
22
|
+
Object.defineProperty(exports, "createASTQueryBuilder", { enumerable: true, get: function () { return select_1.createASTQueryBuilder; } });
|
|
23
|
+
// Mutation generators
|
|
24
|
+
var mutations_1 = require("./mutations");
|
|
25
|
+
Object.defineProperty(exports, "buildPostGraphileCreate", { enumerable: true, get: function () { return mutations_1.buildPostGraphileCreate; } });
|
|
26
|
+
Object.defineProperty(exports, "buildPostGraphileUpdate", { enumerable: true, get: function () { return mutations_1.buildPostGraphileUpdate; } });
|
|
27
|
+
Object.defineProperty(exports, "buildPostGraphileDelete", { enumerable: true, get: function () { return mutations_1.buildPostGraphileDelete; } });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TypedDocumentString } from '../client/typed-document';
|
|
2
|
+
import type { CleanTable } from '../types/schema';
|
|
3
|
+
import type { MutationOptions } from '../types/mutation';
|
|
4
|
+
/**
|
|
5
|
+
* Build PostGraphile-style CREATE mutation
|
|
6
|
+
* PostGraphile expects: mutation { createTableName(input: { tableName: TableNameInput! }) { tableName { ... } } }
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildPostGraphileCreate(table: CleanTable, _allTables: CleanTable[], _options?: MutationOptions): TypedDocumentString<Record<string, unknown>, {
|
|
9
|
+
input: {
|
|
10
|
+
[key: string]: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Build PostGraphile-style UPDATE mutation
|
|
15
|
+
* PostGraphile expects: mutation { updateTableName(input: { id: UUID!, patch: TableNamePatch! }) { tableName { ... } } }
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildPostGraphileUpdate(table: CleanTable, _allTables: CleanTable[], _options?: MutationOptions): TypedDocumentString<Record<string, unknown>, {
|
|
18
|
+
input: {
|
|
19
|
+
id: string | number;
|
|
20
|
+
patch: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Build PostGraphile-style DELETE mutation
|
|
25
|
+
* PostGraphile expects: mutation { deleteTableName(input: { id: UUID! }) { clientMutationId } }
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildPostGraphileDelete(table: CleanTable, _allTables: CleanTable[], _options?: MutationOptions): TypedDocumentString<Record<string, unknown>, {
|
|
28
|
+
input: {
|
|
29
|
+
id: string | number;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.buildPostGraphileCreate = buildPostGraphileCreate;
|
|
37
|
+
exports.buildPostGraphileUpdate = buildPostGraphileUpdate;
|
|
38
|
+
exports.buildPostGraphileDelete = buildPostGraphileDelete;
|
|
39
|
+
/**
|
|
40
|
+
* Mutation generators for CREATE, UPDATE, and DELETE operations
|
|
41
|
+
* Uses AST-based approach for PostGraphile-compatible mutations
|
|
42
|
+
*/
|
|
43
|
+
const t = __importStar(require("gql-ast"));
|
|
44
|
+
const graphql_1 = require("graphql");
|
|
45
|
+
const inflection = __importStar(require("inflection"));
|
|
46
|
+
const typed_document_1 = require("../client/typed-document");
|
|
47
|
+
const custom_ast_1 = require("../core/custom-ast");
|
|
48
|
+
const field_selector_1 = require("./field-selector");
|
|
49
|
+
/**
|
|
50
|
+
* Generate field selections for PostGraphile mutations using custom AST logic
|
|
51
|
+
* This handles both scalar fields and complex types that require subfield selections
|
|
52
|
+
*/
|
|
53
|
+
function generateFieldSelections(table) {
|
|
54
|
+
return table.fields
|
|
55
|
+
.filter((field) => !(0, field_selector_1.isRelationalField)(field.name, table)) // Exclude relational fields
|
|
56
|
+
.map((field) => {
|
|
57
|
+
if ((0, custom_ast_1.requiresSubfieldSelection)(field)) {
|
|
58
|
+
// Use custom AST generation for complex types
|
|
59
|
+
return (0, custom_ast_1.getCustomAstForCleanField)(field);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Use simple field selection for scalar types
|
|
63
|
+
return t.field({ name: field.name });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build PostGraphile-style CREATE mutation
|
|
69
|
+
* PostGraphile expects: mutation { createTableName(input: { tableName: TableNameInput! }) { tableName { ... } } }
|
|
70
|
+
*/
|
|
71
|
+
function buildPostGraphileCreate(table, _allTables, _options = {}) {
|
|
72
|
+
const mutationName = `create${table.name}`;
|
|
73
|
+
const singularName = inflection.camelize(table.name, true);
|
|
74
|
+
// Create the variable definition for $input
|
|
75
|
+
const variableDefinitions = [
|
|
76
|
+
t.variableDefinition({
|
|
77
|
+
variable: t.variable({ name: 'input' }),
|
|
78
|
+
type: t.nonNullType({
|
|
79
|
+
type: t.namedType({ type: `Create${table.name}Input` }),
|
|
80
|
+
}),
|
|
81
|
+
}),
|
|
82
|
+
];
|
|
83
|
+
// Create the mutation arguments
|
|
84
|
+
const mutationArgs = [
|
|
85
|
+
t.argument({
|
|
86
|
+
name: 'input',
|
|
87
|
+
value: t.variable({ name: 'input' }),
|
|
88
|
+
}),
|
|
89
|
+
];
|
|
90
|
+
// Get the field selections for the return value using custom AST logic
|
|
91
|
+
const fieldSelections = generateFieldSelections(table);
|
|
92
|
+
// Build the mutation AST
|
|
93
|
+
const ast = t.document({
|
|
94
|
+
definitions: [
|
|
95
|
+
t.operationDefinition({
|
|
96
|
+
operation: 'mutation',
|
|
97
|
+
name: `${mutationName}Mutation`,
|
|
98
|
+
variableDefinitions,
|
|
99
|
+
selectionSet: t.selectionSet({
|
|
100
|
+
selections: [
|
|
101
|
+
t.field({
|
|
102
|
+
name: mutationName,
|
|
103
|
+
args: mutationArgs,
|
|
104
|
+
selectionSet: t.selectionSet({
|
|
105
|
+
selections: [
|
|
106
|
+
t.field({
|
|
107
|
+
name: singularName,
|
|
108
|
+
selectionSet: t.selectionSet({
|
|
109
|
+
selections: fieldSelections,
|
|
110
|
+
}),
|
|
111
|
+
}),
|
|
112
|
+
],
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
115
|
+
],
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
// Print the AST to get the query string
|
|
121
|
+
const queryString = (0, graphql_1.print)(ast);
|
|
122
|
+
return new typed_document_1.TypedDocumentString(queryString, {
|
|
123
|
+
__ast: ast,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Build PostGraphile-style UPDATE mutation
|
|
128
|
+
* PostGraphile expects: mutation { updateTableName(input: { id: UUID!, patch: TableNamePatch! }) { tableName { ... } } }
|
|
129
|
+
*/
|
|
130
|
+
function buildPostGraphileUpdate(table, _allTables, _options = {}) {
|
|
131
|
+
const mutationName = `update${table.name}`;
|
|
132
|
+
const singularName = inflection.camelize(table.name, true);
|
|
133
|
+
// Create the variable definition for $input
|
|
134
|
+
const variableDefinitions = [
|
|
135
|
+
t.variableDefinition({
|
|
136
|
+
variable: t.variable({ name: 'input' }),
|
|
137
|
+
type: t.nonNullType({
|
|
138
|
+
type: t.namedType({ type: `Update${table.name}Input` }),
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
];
|
|
142
|
+
// Create the mutation arguments
|
|
143
|
+
const mutationArgs = [
|
|
144
|
+
t.argument({
|
|
145
|
+
name: 'input',
|
|
146
|
+
value: t.variable({ name: 'input' }),
|
|
147
|
+
}),
|
|
148
|
+
];
|
|
149
|
+
// Get the field selections for the return value using custom AST logic
|
|
150
|
+
const fieldSelections = generateFieldSelections(table);
|
|
151
|
+
// Build the mutation AST
|
|
152
|
+
const ast = t.document({
|
|
153
|
+
definitions: [
|
|
154
|
+
t.operationDefinition({
|
|
155
|
+
operation: 'mutation',
|
|
156
|
+
name: `${mutationName}Mutation`,
|
|
157
|
+
variableDefinitions,
|
|
158
|
+
selectionSet: t.selectionSet({
|
|
159
|
+
selections: [
|
|
160
|
+
t.field({
|
|
161
|
+
name: mutationName,
|
|
162
|
+
args: mutationArgs,
|
|
163
|
+
selectionSet: t.selectionSet({
|
|
164
|
+
selections: [
|
|
165
|
+
t.field({
|
|
166
|
+
name: singularName,
|
|
167
|
+
selectionSet: t.selectionSet({
|
|
168
|
+
selections: fieldSelections,
|
|
169
|
+
}),
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
}),
|
|
173
|
+
}),
|
|
174
|
+
],
|
|
175
|
+
}),
|
|
176
|
+
}),
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
// Print the AST to get the query string
|
|
180
|
+
const queryString = (0, graphql_1.print)(ast);
|
|
181
|
+
return new typed_document_1.TypedDocumentString(queryString, {
|
|
182
|
+
__ast: ast,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Build PostGraphile-style DELETE mutation
|
|
187
|
+
* PostGraphile expects: mutation { deleteTableName(input: { id: UUID! }) { clientMutationId } }
|
|
188
|
+
*/
|
|
189
|
+
function buildPostGraphileDelete(table, _allTables, _options = {}) {
|
|
190
|
+
const mutationName = `delete${table.name}`;
|
|
191
|
+
// Create the variable definition for $input
|
|
192
|
+
const variableDefinitions = [
|
|
193
|
+
t.variableDefinition({
|
|
194
|
+
variable: t.variable({ name: 'input' }),
|
|
195
|
+
type: t.nonNullType({
|
|
196
|
+
type: t.namedType({ type: `Delete${table.name}Input` }),
|
|
197
|
+
}),
|
|
198
|
+
}),
|
|
199
|
+
];
|
|
200
|
+
// Create the mutation arguments
|
|
201
|
+
const mutationArgs = [
|
|
202
|
+
t.argument({
|
|
203
|
+
name: 'input',
|
|
204
|
+
value: t.variable({ name: 'input' }),
|
|
205
|
+
}),
|
|
206
|
+
];
|
|
207
|
+
// PostGraphile delete mutations typically return clientMutationId
|
|
208
|
+
const fieldSelections = [t.field({ name: 'clientMutationId' })];
|
|
209
|
+
// Build the mutation AST
|
|
210
|
+
const ast = t.document({
|
|
211
|
+
definitions: [
|
|
212
|
+
t.operationDefinition({
|
|
213
|
+
operation: 'mutation',
|
|
214
|
+
name: `${mutationName}Mutation`,
|
|
215
|
+
variableDefinitions,
|
|
216
|
+
selectionSet: t.selectionSet({
|
|
217
|
+
selections: [
|
|
218
|
+
t.field({
|
|
219
|
+
name: mutationName,
|
|
220
|
+
args: mutationArgs,
|
|
221
|
+
selectionSet: t.selectionSet({
|
|
222
|
+
selections: fieldSelections,
|
|
223
|
+
}),
|
|
224
|
+
}),
|
|
225
|
+
],
|
|
226
|
+
}),
|
|
227
|
+
}),
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
// Print the AST to get the query string
|
|
231
|
+
const queryString = (0, graphql_1.print)(ast);
|
|
232
|
+
return new typed_document_1.TypedDocumentString(queryString, {
|
|
233
|
+
__ast: ast,
|
|
234
|
+
});
|
|
235
|
+
}
|