@constructive-io/graphql-codegen 4.6.1 → 4.7.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/client/error.d.ts +2 -93
- package/client/error.js +9 -273
- package/client/execute.d.ts +2 -55
- package/client/execute.js +5 -120
- package/client/typed-document.d.ts +2 -29
- package/client/typed-document.js +3 -39
- package/core/ast.d.ts +8 -10
- package/core/ast.js +17 -592
- package/core/custom-ast.d.ts +5 -33
- package/core/custom-ast.js +16 -203
- package/core/introspect/infer-tables.d.ts +2 -40
- package/core/introspect/infer-tables.js +4 -696
- package/core/introspect/schema-query.d.ts +3 -18
- package/core/introspect/schema-query.js +3 -118
- package/core/introspect/transform-schema.d.ts +2 -84
- package/core/introspect/transform-schema.js +14 -279
- package/core/introspect/transform.d.ts +2 -18
- package/core/introspect/transform.js +6 -39
- package/core/meta-object/convert.d.ts +2 -63
- package/core/meta-object/convert.js +4 -59
- package/core/meta-object/validate.d.ts +2 -7
- package/core/meta-object/validate.js +4 -30
- package/core/query-builder.d.ts +7 -46
- package/core/query-builder.js +8 -408
- package/core/types.d.ts +9 -139
- package/core/types.js +12 -26
- package/esm/client/error.d.ts +2 -93
- package/esm/client/error.js +2 -269
- package/esm/client/execute.d.ts +2 -55
- package/esm/client/execute.js +2 -118
- package/esm/client/typed-document.d.ts +2 -29
- package/esm/client/typed-document.js +2 -38
- package/esm/core/ast.d.ts +8 -10
- package/esm/core/ast.js +8 -550
- package/esm/core/custom-ast.d.ts +5 -33
- package/esm/core/custom-ast.js +5 -160
- package/esm/core/introspect/infer-tables.d.ts +2 -40
- package/esm/core/introspect/infer-tables.js +2 -695
- package/esm/core/introspect/schema-query.d.ts +3 -18
- package/esm/core/introspect/schema-query.js +2 -118
- package/esm/core/introspect/transform-schema.d.ts +2 -84
- package/esm/core/introspect/transform-schema.js +2 -269
- package/esm/core/introspect/transform.d.ts +2 -18
- package/esm/core/introspect/transform.js +2 -36
- package/esm/core/meta-object/convert.d.ts +2 -63
- package/esm/core/meta-object/convert.js +2 -58
- package/esm/core/meta-object/validate.d.ts +2 -7
- package/esm/core/meta-object/validate.js +2 -26
- package/esm/core/query-builder.d.ts +7 -46
- package/esm/core/query-builder.js +5 -373
- package/esm/core/types.d.ts +9 -139
- package/esm/core/types.js +9 -24
- package/esm/generators/field-selector.d.ts +5 -28
- package/esm/generators/field-selector.js +5 -379
- package/esm/generators/mutations.d.ts +5 -28
- package/esm/generators/mutations.js +5 -198
- package/esm/generators/naming-helpers.d.ts +3 -45
- package/esm/generators/naming-helpers.js +3 -151
- package/esm/generators/select.d.ts +6 -37
- package/esm/generators/select.js +6 -659
- package/generators/field-selector.d.ts +5 -28
- package/generators/field-selector.js +12 -385
- package/generators/mutations.d.ts +5 -28
- package/generators/mutations.js +9 -234
- package/generators/naming-helpers.d.ts +3 -45
- package/generators/naming-helpers.js +15 -164
- package/generators/select.d.ts +6 -37
- package/generators/select.js +17 -703
- package/package.json +7 -6
- package/core/meta-object/format.json +0 -93
- package/esm/core/meta-object/format.json +0 -93
package/esm/core/types.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
return false;
|
|
11
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
12
|
-
if (typeof key !== 'string')
|
|
13
|
-
return false;
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
if (!value.every((item) => isGraphQLVariableValue(item) || isGraphQLVariables(item))) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
else if (!isGraphQLVariableValue(value) && !isGraphQLVariables(value)) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Re-export core types from @constructive-io/graphql-query.
|
|
3
|
+
*
|
|
4
|
+
* This file used to contain the canonical type definitions. They now live in
|
|
5
|
+
* the `graphql-query` package and are re-exported here for backward
|
|
6
|
+
* compatibility so existing codegen consumers continue to work unchanged.
|
|
7
|
+
*/
|
|
8
|
+
// Re-export everything from the canonical source
|
|
9
|
+
export { isGraphQLVariableValue, isGraphQLVariables, } from '@constructive-io/graphql-query';
|
|
@@ -1,30 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Re-export field selector utilities from @constructive-io/graphql-query.
|
|
3
|
+
*
|
|
4
|
+
* The canonical implementations of convertToSelectionOptions, isRelationalField,
|
|
5
|
+
* getAvailableRelations, and validateFieldSelection now live in graphql-query.
|
|
4
6
|
*/
|
|
5
|
-
|
|
6
|
-
import type { CleanTable } from '../types/schema';
|
|
7
|
-
import type { FieldSelection } from '../types/selection';
|
|
8
|
-
/**
|
|
9
|
-
* Convert simplified field selection to QueryBuilder SelectionOptions
|
|
10
|
-
*/
|
|
11
|
-
export declare function convertToSelectionOptions(table: CleanTable, allTables: CleanTable[], selection?: FieldSelection): QuerySelectionOptions | null;
|
|
12
|
-
/**
|
|
13
|
-
* Check if a field is relational using table metadata
|
|
14
|
-
*/
|
|
15
|
-
export declare function isRelationalField(fieldName: string, table: CleanTable): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Get all available relation fields from a table
|
|
18
|
-
*/
|
|
19
|
-
export declare function getAvailableRelations(table: CleanTable): Array<{
|
|
20
|
-
fieldName: string;
|
|
21
|
-
type: 'belongsTo' | 'hasOne' | 'hasMany' | 'manyToMany';
|
|
22
|
-
referencedTable?: string;
|
|
23
|
-
}>;
|
|
24
|
-
/**
|
|
25
|
-
* Validate field selection against table schema
|
|
26
|
-
*/
|
|
27
|
-
export declare function validateFieldSelection(selection: FieldSelection, table: CleanTable): {
|
|
28
|
-
isValid: boolean;
|
|
29
|
-
errors: string[];
|
|
30
|
-
};
|
|
7
|
+
export { convertToSelectionOptions, isRelationalField, getAvailableRelations, validateFieldSelection, } from '@constructive-io/graphql-query';
|
|
@@ -1,381 +1,7 @@
|
|
|
1
|
-
const relationalFieldSetCache = new WeakMap();
|
|
2
|
-
function getRelationalFieldSet(table) {
|
|
3
|
-
const cached = relationalFieldSetCache.get(table);
|
|
4
|
-
if (cached)
|
|
5
|
-
return cached;
|
|
6
|
-
const set = new Set();
|
|
7
|
-
for (const rel of table.relations.belongsTo) {
|
|
8
|
-
if (rel.fieldName)
|
|
9
|
-
set.add(rel.fieldName);
|
|
10
|
-
}
|
|
11
|
-
for (const rel of table.relations.hasOne) {
|
|
12
|
-
if (rel.fieldName)
|
|
13
|
-
set.add(rel.fieldName);
|
|
14
|
-
}
|
|
15
|
-
for (const rel of table.relations.hasMany) {
|
|
16
|
-
if (rel.fieldName)
|
|
17
|
-
set.add(rel.fieldName);
|
|
18
|
-
}
|
|
19
|
-
for (const rel of table.relations.manyToMany) {
|
|
20
|
-
if (rel.fieldName)
|
|
21
|
-
set.add(rel.fieldName);
|
|
22
|
-
}
|
|
23
|
-
relationalFieldSetCache.set(table, set);
|
|
24
|
-
return set;
|
|
25
|
-
}
|
|
26
1
|
/**
|
|
27
|
-
*
|
|
2
|
+
* Re-export field selector utilities from @constructive-io/graphql-query.
|
|
3
|
+
*
|
|
4
|
+
* The canonical implementations of convertToSelectionOptions, isRelationalField,
|
|
5
|
+
* getAvailableRelations, and validateFieldSelection now live in graphql-query.
|
|
28
6
|
*/
|
|
29
|
-
export
|
|
30
|
-
if (!selection) {
|
|
31
|
-
return convertPresetToSelection(table, 'display');
|
|
32
|
-
}
|
|
33
|
-
if (typeof selection === 'string') {
|
|
34
|
-
return convertPresetToSelection(table, selection);
|
|
35
|
-
}
|
|
36
|
-
return convertCustomSelectionToOptions(table, allTables, selection);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Convert preset to selection options
|
|
40
|
-
*/
|
|
41
|
-
function convertPresetToSelection(table, preset) {
|
|
42
|
-
const options = {};
|
|
43
|
-
switch (preset) {
|
|
44
|
-
case 'minimal': {
|
|
45
|
-
// Just id and first display field
|
|
46
|
-
const minimalFields = getMinimalFields(table);
|
|
47
|
-
minimalFields.forEach((field) => {
|
|
48
|
-
options[field] = true;
|
|
49
|
-
});
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case 'display': {
|
|
53
|
-
// Common display fields
|
|
54
|
-
const displayFields = getDisplayFields(table);
|
|
55
|
-
displayFields.forEach((field) => {
|
|
56
|
-
options[field] = true;
|
|
57
|
-
});
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
case 'all': {
|
|
61
|
-
// All non-relational fields (includes complex fields like JSON, geometry, etc.)
|
|
62
|
-
const allFields = getNonRelationalFields(table);
|
|
63
|
-
allFields.forEach((field) => {
|
|
64
|
-
options[field] = true;
|
|
65
|
-
});
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case 'full':
|
|
69
|
-
// All fields including basic relations
|
|
70
|
-
table.fields.forEach((field) => {
|
|
71
|
-
options[field.name] = true;
|
|
72
|
-
});
|
|
73
|
-
break;
|
|
74
|
-
default: {
|
|
75
|
-
// Default to display
|
|
76
|
-
const defaultFields = getDisplayFields(table);
|
|
77
|
-
defaultFields.forEach((field) => {
|
|
78
|
-
options[field] = true;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return options;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Convert custom selection to options
|
|
86
|
-
*/
|
|
87
|
-
function convertCustomSelectionToOptions(table, allTables, selection) {
|
|
88
|
-
const options = {};
|
|
89
|
-
// Start with selected fields or all non-relational fields (including complex types)
|
|
90
|
-
let fieldsToInclude;
|
|
91
|
-
if (selection.select) {
|
|
92
|
-
fieldsToInclude = selection.select;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
fieldsToInclude = getNonRelationalFields(table);
|
|
96
|
-
}
|
|
97
|
-
// Add basic fields
|
|
98
|
-
fieldsToInclude.forEach((field) => {
|
|
99
|
-
if (table.fields.some((f) => f.name === field)) {
|
|
100
|
-
options[field] = true;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
// Handle includeRelations (simple API for relation fields)
|
|
104
|
-
if (selection.includeRelations) {
|
|
105
|
-
selection.includeRelations.forEach((relationField) => {
|
|
106
|
-
if (isRelationalField(relationField, table)) {
|
|
107
|
-
// Include with dynamically determined scalar fields from the related table
|
|
108
|
-
options[relationField] = {
|
|
109
|
-
select: getRelatedTableScalarFields(relationField, table, allTables),
|
|
110
|
-
variables: {},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
// Handle includes (relations) - more detailed API
|
|
116
|
-
if (selection.include) {
|
|
117
|
-
Object.entries(selection.include).forEach(([relationField, relationSelection]) => {
|
|
118
|
-
if (isRelationalField(relationField, table)) {
|
|
119
|
-
if (relationSelection === true) {
|
|
120
|
-
// Include with dynamically determined scalar fields from the related table
|
|
121
|
-
options[relationField] = {
|
|
122
|
-
select: getRelatedTableScalarFields(relationField, table, allTables),
|
|
123
|
-
variables: {},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
else if (Array.isArray(relationSelection)) {
|
|
127
|
-
// Include with specific fields
|
|
128
|
-
const selectObj = {};
|
|
129
|
-
relationSelection.forEach((field) => {
|
|
130
|
-
selectObj[field] = true;
|
|
131
|
-
});
|
|
132
|
-
options[relationField] = {
|
|
133
|
-
select: selectObj,
|
|
134
|
-
variables: {},
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
// Handle excludes
|
|
141
|
-
if (selection.exclude) {
|
|
142
|
-
selection.exclude.forEach((field) => {
|
|
143
|
-
delete options[field];
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
return options;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get minimal fields - completely schema-driven, no hardcoded assumptions
|
|
150
|
-
*/
|
|
151
|
-
function getMinimalFields(table) {
|
|
152
|
-
// Get all non-relational fields from the actual schema
|
|
153
|
-
const nonRelationalFields = getNonRelationalFields(table);
|
|
154
|
-
// Return the first few fields from the schema (typically includes primary key and basic fields)
|
|
155
|
-
// This is completely dynamic based on what the schema actually provides
|
|
156
|
-
return nonRelationalFields.slice(0, 3); // Limit to first 3 fields for minimal selection
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Get display fields - completely schema-driven, no hardcoded field names
|
|
160
|
-
*/
|
|
161
|
-
function getDisplayFields(table) {
|
|
162
|
-
// Get all non-relational fields from the actual schema
|
|
163
|
-
const nonRelationalFields = getNonRelationalFields(table);
|
|
164
|
-
// Return a reasonable subset for display purposes (first half of available fields)
|
|
165
|
-
// This is completely dynamic based on what the schema actually provides
|
|
166
|
-
const maxDisplayFields = Math.max(5, Math.floor(nonRelationalFields.length / 2));
|
|
167
|
-
return nonRelationalFields.slice(0, maxDisplayFields);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Get all non-relational fields (includes both scalar and complex fields)
|
|
171
|
-
* Complex fields like JSON, geometry, images should be included by default
|
|
172
|
-
*/
|
|
173
|
-
function getNonRelationalFields(table) {
|
|
174
|
-
return table.fields
|
|
175
|
-
.filter((field) => !isRelationalField(field.name, table))
|
|
176
|
-
.map((field) => field.name);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Check if a field is relational using table metadata
|
|
180
|
-
*/
|
|
181
|
-
export function isRelationalField(fieldName, table) {
|
|
182
|
-
return getRelationalFieldSet(table).has(fieldName);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Get scalar fields for a related table to include in relation queries
|
|
186
|
-
* Uses only the _meta query data - no hardcoded field names or assumptions
|
|
187
|
-
*/
|
|
188
|
-
function getRelatedTableScalarFields(relationField, table, allTables) {
|
|
189
|
-
// Find the related table name
|
|
190
|
-
let referencedTableName;
|
|
191
|
-
// Check belongsTo relations
|
|
192
|
-
const belongsToRel = table.relations.belongsTo.find((rel) => rel.fieldName === relationField);
|
|
193
|
-
if (belongsToRel) {
|
|
194
|
-
referencedTableName = belongsToRel.referencesTable;
|
|
195
|
-
}
|
|
196
|
-
// Check hasOne relations
|
|
197
|
-
if (!referencedTableName) {
|
|
198
|
-
const hasOneRel = table.relations.hasOne.find((rel) => rel.fieldName === relationField);
|
|
199
|
-
if (hasOneRel) {
|
|
200
|
-
referencedTableName = hasOneRel.referencedByTable;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
// Check hasMany relations
|
|
204
|
-
if (!referencedTableName) {
|
|
205
|
-
const hasManyRel = table.relations.hasMany.find((rel) => rel.fieldName === relationField);
|
|
206
|
-
if (hasManyRel) {
|
|
207
|
-
referencedTableName = hasManyRel.referencedByTable;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
// Check manyToMany relations
|
|
211
|
-
if (!referencedTableName) {
|
|
212
|
-
const manyToManyRel = table.relations.manyToMany.find((rel) => rel.fieldName === relationField);
|
|
213
|
-
if (manyToManyRel) {
|
|
214
|
-
referencedTableName = manyToManyRel.rightTable;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (!referencedTableName) {
|
|
218
|
-
// No related table found - return empty selection
|
|
219
|
-
return {};
|
|
220
|
-
}
|
|
221
|
-
// Find the related table in allTables
|
|
222
|
-
const relatedTable = allTables.find((t) => t.name === referencedTableName);
|
|
223
|
-
if (!relatedTable) {
|
|
224
|
-
// Related table not found in schema - return empty selection
|
|
225
|
-
return {};
|
|
226
|
-
}
|
|
227
|
-
// Get ALL scalar fields from the related table (non-relational fields)
|
|
228
|
-
// This is completely dynamic based on the actual schema
|
|
229
|
-
const scalarFields = relatedTable.fields
|
|
230
|
-
.filter((field) => !isRelationalField(field.name, relatedTable))
|
|
231
|
-
.map((field) => field.name);
|
|
232
|
-
// Perf guardrail: select a small, display-oriented subset.
|
|
233
|
-
const MAX_RELATED_FIELDS = 8;
|
|
234
|
-
const preferred = [
|
|
235
|
-
'displayName',
|
|
236
|
-
'fullName',
|
|
237
|
-
'preferredName',
|
|
238
|
-
'nickname',
|
|
239
|
-
'firstName',
|
|
240
|
-
'lastName',
|
|
241
|
-
'username',
|
|
242
|
-
'email',
|
|
243
|
-
'name',
|
|
244
|
-
'title',
|
|
245
|
-
'label',
|
|
246
|
-
'slug',
|
|
247
|
-
'code',
|
|
248
|
-
'createdAt',
|
|
249
|
-
'updatedAt',
|
|
250
|
-
];
|
|
251
|
-
const scalarFieldSet = new Set(scalarFields);
|
|
252
|
-
// Use Set for O(1) duplicate checking
|
|
253
|
-
const includedSet = new Set();
|
|
254
|
-
const included = [];
|
|
255
|
-
const push = (fieldName) => {
|
|
256
|
-
if (!fieldName)
|
|
257
|
-
return;
|
|
258
|
-
if (!scalarFieldSet.has(fieldName))
|
|
259
|
-
return;
|
|
260
|
-
if (includedSet.has(fieldName))
|
|
261
|
-
return;
|
|
262
|
-
if (included.length >= MAX_RELATED_FIELDS)
|
|
263
|
-
return;
|
|
264
|
-
includedSet.add(fieldName);
|
|
265
|
-
included.push(fieldName);
|
|
266
|
-
};
|
|
267
|
-
// Always try to include stable identifiers first.
|
|
268
|
-
push('id');
|
|
269
|
-
push('rowId');
|
|
270
|
-
push('nodeId');
|
|
271
|
-
for (const fieldName of preferred)
|
|
272
|
-
push(fieldName);
|
|
273
|
-
for (const fieldName of scalarFields)
|
|
274
|
-
push(fieldName);
|
|
275
|
-
const selection = {};
|
|
276
|
-
for (const fieldName of included)
|
|
277
|
-
selection[fieldName] = true;
|
|
278
|
-
return selection;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Get all available relation fields from a table
|
|
282
|
-
*/
|
|
283
|
-
export function getAvailableRelations(table) {
|
|
284
|
-
const relations = [];
|
|
285
|
-
// Add belongsTo relations
|
|
286
|
-
table.relations.belongsTo.forEach((rel) => {
|
|
287
|
-
if (rel.fieldName) {
|
|
288
|
-
relations.push({
|
|
289
|
-
fieldName: rel.fieldName,
|
|
290
|
-
type: 'belongsTo',
|
|
291
|
-
referencedTable: rel.referencesTable || undefined,
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
// Add hasOne relations
|
|
296
|
-
table.relations.hasOne.forEach((rel) => {
|
|
297
|
-
if (rel.fieldName) {
|
|
298
|
-
relations.push({
|
|
299
|
-
fieldName: rel.fieldName,
|
|
300
|
-
type: 'hasOne',
|
|
301
|
-
referencedTable: rel.referencedByTable || undefined,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
// Add hasMany relations
|
|
306
|
-
table.relations.hasMany.forEach((rel) => {
|
|
307
|
-
if (rel.fieldName) {
|
|
308
|
-
relations.push({
|
|
309
|
-
fieldName: rel.fieldName,
|
|
310
|
-
type: 'hasMany',
|
|
311
|
-
referencedTable: rel.referencedByTable || undefined,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
// Add manyToMany relations
|
|
316
|
-
table.relations.manyToMany.forEach((rel) => {
|
|
317
|
-
if (rel.fieldName) {
|
|
318
|
-
relations.push({
|
|
319
|
-
fieldName: rel.fieldName,
|
|
320
|
-
type: 'manyToMany',
|
|
321
|
-
referencedTable: rel.rightTable || undefined,
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
return relations;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Validate field selection against table schema
|
|
329
|
-
*/
|
|
330
|
-
export function validateFieldSelection(selection, table) {
|
|
331
|
-
const errors = [];
|
|
332
|
-
if (typeof selection === 'string') {
|
|
333
|
-
// Presets are always valid
|
|
334
|
-
return { isValid: true, errors: [] };
|
|
335
|
-
}
|
|
336
|
-
const tableFieldNames = table.fields.map((f) => f.name);
|
|
337
|
-
// Validate select fields
|
|
338
|
-
if (selection.select) {
|
|
339
|
-
selection.select.forEach((field) => {
|
|
340
|
-
if (!tableFieldNames.includes(field)) {
|
|
341
|
-
errors.push(`Field '${field}' does not exist in table '${table.name}'`);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
// Validate includeRelations fields
|
|
346
|
-
if (selection.includeRelations) {
|
|
347
|
-
selection.includeRelations.forEach((field) => {
|
|
348
|
-
if (!isRelationalField(field, table)) {
|
|
349
|
-
errors.push(`Field '${field}' is not a relational field in table '${table.name}'`);
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
// Validate include fields
|
|
354
|
-
if (selection.include) {
|
|
355
|
-
Object.keys(selection.include).forEach((field) => {
|
|
356
|
-
if (!isRelationalField(field, table)) {
|
|
357
|
-
errors.push(`Field '${field}' is not a relational field in table '${table.name}'`);
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
// Validate exclude fields
|
|
362
|
-
if (selection.exclude) {
|
|
363
|
-
selection.exclude.forEach((field) => {
|
|
364
|
-
if (!tableFieldNames.includes(field)) {
|
|
365
|
-
errors.push(`Exclude field '${field}' does not exist in table '${table.name}'`);
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
// Validate maxDepth
|
|
370
|
-
if (selection.maxDepth !== undefined) {
|
|
371
|
-
if (typeof selection.maxDepth !== 'number' ||
|
|
372
|
-
selection.maxDepth < 0 ||
|
|
373
|
-
selection.maxDepth > 5) {
|
|
374
|
-
errors.push('maxDepth must be a number between 0 and 5');
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return {
|
|
378
|
-
isValid: errors.length === 0,
|
|
379
|
-
errors,
|
|
380
|
-
};
|
|
381
|
-
}
|
|
7
|
+
export { convertToSelectionOptions, isRelationalField, getAvailableRelations, validateFieldSelection, } from '@constructive-io/graphql-query';
|
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
import { TypedDocumentString } from '../client/typed-document';
|
|
2
|
-
import type { MutationOptions } from '../types/mutation';
|
|
3
|
-
import type { CleanTable } from '../types/schema';
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Re-export mutation generators from @constructive-io/graphql-query.
|
|
3
|
+
*
|
|
4
|
+
* The canonical implementations of buildPostGraphileCreate, buildPostGraphileUpdate,
|
|
5
|
+
* and buildPostGraphileDelete now live in graphql-query.
|
|
7
6
|
*/
|
|
8
|
-
export
|
|
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
|
-
} & Record<string, unknown>;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Build PostGraphile-style DELETE mutation
|
|
24
|
-
* PostGraphile expects: mutation { deleteTableName(input: { id: UUID! }) { clientMutationId } }
|
|
25
|
-
*/
|
|
26
|
-
export declare function buildPostGraphileDelete(table: CleanTable, _allTables: CleanTable[], _options?: MutationOptions): TypedDocumentString<Record<string, unknown>, {
|
|
27
|
-
input: {
|
|
28
|
-
id: string | number;
|
|
29
|
-
};
|
|
30
|
-
}>;
|
|
7
|
+
export { buildPostGraphileCreate, buildPostGraphileUpdate, buildPostGraphileDelete, } from '@constructive-io/graphql-query';
|