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