@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/core/ast.js
CHANGED
|
@@ -1,594 +1,19 @@
|
|
|
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.deleteOne = exports.patchOne = exports.createOne = exports.getOne = exports.getMany = exports.getCount = exports.getAll = void 0;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const opSel = !modelName
|
|
54
|
-
? [
|
|
55
|
-
t.field({
|
|
56
|
-
name: operationName,
|
|
57
|
-
args: selectArgs,
|
|
58
|
-
selectionSet: t.selectionSet({ selections }),
|
|
59
|
-
}),
|
|
60
|
-
]
|
|
61
|
-
: [
|
|
62
|
-
t.field({
|
|
63
|
-
name: operationName,
|
|
64
|
-
args: selectArgs,
|
|
65
|
-
selectionSet: t.selectionSet({
|
|
66
|
-
selections: useModel
|
|
67
|
-
? [
|
|
68
|
-
t.field({
|
|
69
|
-
name: modelName,
|
|
70
|
-
selectionSet: t.selectionSet({ selections }),
|
|
71
|
-
}),
|
|
72
|
-
]
|
|
73
|
-
: selections,
|
|
74
|
-
}),
|
|
75
|
-
}),
|
|
76
|
-
];
|
|
77
|
-
return t.document({
|
|
78
|
-
definitions: [
|
|
79
|
-
t.operationDefinition({
|
|
80
|
-
operation: graphql_1.OperationTypeNode.MUTATION,
|
|
81
|
-
name: mutationName,
|
|
82
|
-
variableDefinitions,
|
|
83
|
-
selectionSet: t.selectionSet({ selections: opSel }),
|
|
84
|
-
}),
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
const getAll = ({ queryName, operationName, selection, }) => {
|
|
89
|
-
const selections = getSelections(selection);
|
|
90
|
-
const opSel = [
|
|
91
|
-
t.field({
|
|
92
|
-
name: operationName,
|
|
93
|
-
selectionSet: t.selectionSet({
|
|
94
|
-
selections: [
|
|
95
|
-
t.field({
|
|
96
|
-
name: 'totalCount',
|
|
97
|
-
}),
|
|
98
|
-
t.field({
|
|
99
|
-
name: 'nodes',
|
|
100
|
-
selectionSet: t.selectionSet({ selections }),
|
|
101
|
-
}),
|
|
102
|
-
],
|
|
103
|
-
}),
|
|
104
|
-
}),
|
|
105
|
-
];
|
|
106
|
-
const ast = t.document({
|
|
107
|
-
definitions: [
|
|
108
|
-
t.operationDefinition({
|
|
109
|
-
operation: graphql_1.OperationTypeNode.QUERY,
|
|
110
|
-
name: queryName,
|
|
111
|
-
selectionSet: t.selectionSet({ selections: opSel }),
|
|
112
|
-
}),
|
|
113
|
-
],
|
|
114
|
-
});
|
|
115
|
-
return ast;
|
|
116
|
-
};
|
|
117
|
-
exports.getAll = getAll;
|
|
118
|
-
const getCount = ({ queryName, operationName, query, }) => {
|
|
119
|
-
const Singular = query.model;
|
|
120
|
-
const Filter = `${Singular}Filter`;
|
|
121
|
-
const Condition = `${Singular}Condition`;
|
|
122
|
-
const variableDefinitions = [
|
|
123
|
-
t.variableDefinition({
|
|
124
|
-
variable: t.variable({ name: 'condition' }),
|
|
125
|
-
type: t.namedType({ type: Condition }),
|
|
126
|
-
}),
|
|
127
|
-
t.variableDefinition({
|
|
128
|
-
variable: t.variable({ name: 'filter' }),
|
|
129
|
-
type: t.namedType({ type: Filter }),
|
|
130
|
-
}),
|
|
131
|
-
];
|
|
132
|
-
const args = [
|
|
133
|
-
t.argument({ name: 'condition', value: t.variable({ name: 'condition' }) }),
|
|
134
|
-
t.argument({ name: 'filter', value: t.variable({ name: 'filter' }) }),
|
|
135
|
-
];
|
|
136
|
-
// PostGraphile supports totalCount through connections
|
|
137
|
-
const opSel = [
|
|
138
|
-
t.field({
|
|
139
|
-
name: operationName,
|
|
140
|
-
args,
|
|
141
|
-
selectionSet: t.selectionSet({
|
|
142
|
-
selections: [
|
|
143
|
-
t.field({
|
|
144
|
-
name: 'totalCount',
|
|
145
|
-
}),
|
|
146
|
-
],
|
|
147
|
-
}),
|
|
148
|
-
}),
|
|
149
|
-
];
|
|
150
|
-
const ast = t.document({
|
|
151
|
-
definitions: [
|
|
152
|
-
t.operationDefinition({
|
|
153
|
-
operation: graphql_1.OperationTypeNode.QUERY,
|
|
154
|
-
name: queryName,
|
|
155
|
-
variableDefinitions,
|
|
156
|
-
selectionSet: t.selectionSet({ selections: opSel }),
|
|
157
|
-
}),
|
|
158
|
-
],
|
|
159
|
-
});
|
|
160
|
-
return ast;
|
|
161
|
-
};
|
|
162
|
-
exports.getCount = getCount;
|
|
163
|
-
const getMany = ({ builder, queryName, operationName, query, selection, }) => {
|
|
164
|
-
const Singular = query.model;
|
|
165
|
-
const Plural = operationName.charAt(0).toUpperCase() + operationName.slice(1);
|
|
166
|
-
const Condition = `${Singular}Condition`;
|
|
167
|
-
const Filter = `${Singular}Filter`;
|
|
168
|
-
const OrderBy = `${Plural}OrderBy`;
|
|
169
|
-
const selections = getSelections(selection);
|
|
170
|
-
const variableDefinitions = [
|
|
171
|
-
t.variableDefinition({
|
|
172
|
-
variable: t.variable({ name: 'first' }),
|
|
173
|
-
type: t.namedType({ type: 'Int' }),
|
|
174
|
-
}),
|
|
175
|
-
t.variableDefinition({
|
|
176
|
-
variable: t.variable({ name: 'last' }),
|
|
177
|
-
type: t.namedType({ type: 'Int' }),
|
|
178
|
-
}),
|
|
179
|
-
t.variableDefinition({
|
|
180
|
-
variable: t.variable({ name: 'after' }),
|
|
181
|
-
type: t.namedType({ type: 'Cursor' }),
|
|
182
|
-
}),
|
|
183
|
-
t.variableDefinition({
|
|
184
|
-
variable: t.variable({ name: 'before' }),
|
|
185
|
-
type: t.namedType({ type: 'Cursor' }),
|
|
186
|
-
}),
|
|
187
|
-
t.variableDefinition({
|
|
188
|
-
variable: t.variable({ name: 'offset' }),
|
|
189
|
-
type: t.namedType({ type: 'Int' }),
|
|
190
|
-
}),
|
|
191
|
-
t.variableDefinition({
|
|
192
|
-
variable: t.variable({ name: 'condition' }),
|
|
193
|
-
type: t.namedType({ type: Condition }),
|
|
194
|
-
}),
|
|
195
|
-
t.variableDefinition({
|
|
196
|
-
variable: t.variable({ name: 'filter' }),
|
|
197
|
-
type: t.namedType({ type: Filter }),
|
|
198
|
-
}),
|
|
199
|
-
t.variableDefinition({
|
|
200
|
-
variable: t.variable({ name: 'orderBy' }),
|
|
201
|
-
type: t.listType({
|
|
202
|
-
type: t.nonNullType({ type: t.namedType({ type: OrderBy }) }),
|
|
203
|
-
}),
|
|
204
|
-
}),
|
|
205
|
-
];
|
|
206
|
-
const args = [
|
|
207
|
-
t.argument({ name: 'first', value: t.variable({ name: 'first' }) }),
|
|
208
|
-
t.argument({ name: 'last', value: t.variable({ name: 'last' }) }),
|
|
209
|
-
t.argument({ name: 'offset', value: t.variable({ name: 'offset' }) }),
|
|
210
|
-
t.argument({ name: 'after', value: t.variable({ name: 'after' }) }),
|
|
211
|
-
t.argument({ name: 'before', value: t.variable({ name: 'before' }) }),
|
|
212
|
-
t.argument({
|
|
213
|
-
name: 'condition',
|
|
214
|
-
value: t.variable({ name: 'condition' }),
|
|
215
|
-
}),
|
|
216
|
-
t.argument({ name: 'filter', value: t.variable({ name: 'filter' }) }),
|
|
217
|
-
t.argument({ name: 'orderBy', value: t.variable({ name: 'orderBy' }) }),
|
|
218
|
-
];
|
|
219
|
-
const pageInfoFields = [
|
|
220
|
-
t.field({ name: 'hasNextPage' }),
|
|
221
|
-
t.field({ name: 'hasPreviousPage' }),
|
|
222
|
-
t.field({ name: 'endCursor' }),
|
|
223
|
-
t.field({ name: 'startCursor' }),
|
|
224
|
-
];
|
|
225
|
-
const dataField = builder?._edges
|
|
226
|
-
? t.field({
|
|
227
|
-
name: 'edges',
|
|
228
|
-
selectionSet: t.selectionSet({
|
|
229
|
-
selections: [
|
|
230
|
-
t.field({ name: 'cursor' }),
|
|
231
|
-
t.field({
|
|
232
|
-
name: 'node',
|
|
233
|
-
selectionSet: t.selectionSet({ selections }),
|
|
234
|
-
}),
|
|
235
|
-
],
|
|
236
|
-
}),
|
|
237
|
-
})
|
|
238
|
-
: t.field({
|
|
239
|
-
name: 'nodes',
|
|
240
|
-
selectionSet: t.selectionSet({ selections }),
|
|
241
|
-
});
|
|
242
|
-
const connectionFields = [
|
|
243
|
-
t.field({ name: 'totalCount' }),
|
|
244
|
-
t.field({
|
|
245
|
-
name: 'pageInfo',
|
|
246
|
-
selectionSet: t.selectionSet({ selections: pageInfoFields }),
|
|
247
|
-
}),
|
|
248
|
-
dataField,
|
|
249
|
-
];
|
|
250
|
-
const ast = t.document({
|
|
251
|
-
definitions: [
|
|
252
|
-
t.operationDefinition({
|
|
253
|
-
operation: graphql_1.OperationTypeNode.QUERY,
|
|
254
|
-
name: queryName,
|
|
255
|
-
variableDefinitions,
|
|
256
|
-
selectionSet: t.selectionSet({
|
|
257
|
-
selections: [
|
|
258
|
-
t.field({
|
|
259
|
-
name: operationName,
|
|
260
|
-
args,
|
|
261
|
-
selectionSet: t.selectionSet({ selections: connectionFields }),
|
|
262
|
-
}),
|
|
263
|
-
],
|
|
264
|
-
}),
|
|
265
|
-
}),
|
|
266
|
-
],
|
|
267
|
-
});
|
|
268
|
-
return ast;
|
|
269
|
-
};
|
|
270
|
-
exports.getMany = getMany;
|
|
271
|
-
const getOne = ({ queryName, operationName, query, selection, }) => {
|
|
272
|
-
const variableDefinitions = Object.keys(query.properties)
|
|
273
|
-
.map((key) => ({ key, ...query.properties[key] }))
|
|
274
|
-
.filter((field) => field.isNotNull)
|
|
275
|
-
.map((field) => {
|
|
276
|
-
const { key: fieldName, type: fieldType, isNotNull, isArray, isArrayNotNull, } = field;
|
|
277
|
-
let type = t.namedType({ type: fieldType });
|
|
278
|
-
if (isNotNull)
|
|
279
|
-
type = t.nonNullType({ type });
|
|
280
|
-
if (isArray) {
|
|
281
|
-
type = t.listType({ type });
|
|
282
|
-
if (isArrayNotNull)
|
|
283
|
-
type = t.nonNullType({ type });
|
|
284
|
-
}
|
|
285
|
-
return t.variableDefinition({
|
|
286
|
-
variable: t.variable({ name: fieldName }),
|
|
287
|
-
type,
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
const props = objectToArray(query.properties);
|
|
291
|
-
const selectArgs = props
|
|
292
|
-
.filter((field) => field.isNotNull)
|
|
293
|
-
.map((field) => {
|
|
294
|
-
return t.argument({
|
|
295
|
-
name: field.name,
|
|
296
|
-
value: t.variable({ name: field.name }),
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
const selections = getSelections(selection);
|
|
300
|
-
const opSel = [
|
|
301
|
-
t.field({
|
|
302
|
-
name: operationName,
|
|
303
|
-
args: selectArgs,
|
|
304
|
-
selectionSet: t.selectionSet({ selections }),
|
|
305
|
-
}),
|
|
306
|
-
];
|
|
307
|
-
const ast = t.document({
|
|
308
|
-
definitions: [
|
|
309
|
-
t.operationDefinition({
|
|
310
|
-
operation: graphql_1.OperationTypeNode.QUERY,
|
|
311
|
-
name: queryName,
|
|
312
|
-
variableDefinitions,
|
|
313
|
-
selectionSet: t.selectionSet({ selections: opSel }),
|
|
314
|
-
}),
|
|
315
|
-
],
|
|
316
|
-
});
|
|
317
|
-
return ast;
|
|
318
|
-
};
|
|
319
|
-
exports.getOne = getOne;
|
|
320
|
-
const createOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
321
|
-
if (!mutation.properties?.input?.properties) {
|
|
322
|
-
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
323
|
-
}
|
|
324
|
-
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
325
|
-
const inputProperties = mutation.properties.input
|
|
326
|
-
.properties;
|
|
327
|
-
const modelProperties = inputProperties[modelName];
|
|
328
|
-
if (!modelProperties.properties) {
|
|
329
|
-
throw new Error(`No properties found for model: ${modelName}`);
|
|
330
|
-
}
|
|
331
|
-
const allAttrs = objectToArray(modelProperties.properties);
|
|
332
|
-
const attrs = allAttrs.filter((field) => !NON_MUTABLE_PROPS.includes(field.name));
|
|
333
|
-
const variableDefinitions = getCreateVariablesAst(attrs);
|
|
334
|
-
const selectArgs = [
|
|
335
|
-
t.argument({
|
|
336
|
-
name: 'input',
|
|
337
|
-
value: t.objectValue({
|
|
338
|
-
fields: [
|
|
339
|
-
t.objectField({
|
|
340
|
-
name: modelName,
|
|
341
|
-
value: t.objectValue({
|
|
342
|
-
fields: attrs.map((field) => t.objectField({
|
|
343
|
-
name: field.name,
|
|
344
|
-
value: t.variable({ name: field.name }),
|
|
345
|
-
})),
|
|
346
|
-
}),
|
|
347
|
-
}),
|
|
348
|
-
],
|
|
349
|
-
}),
|
|
350
|
-
}),
|
|
351
|
-
];
|
|
352
|
-
const selections = selection
|
|
353
|
-
? getSelections(selection)
|
|
354
|
-
: allAttrs.map((field) => t.field({ name: field.name }));
|
|
355
|
-
const ast = createGqlMutation({
|
|
356
|
-
operationName,
|
|
357
|
-
mutationName,
|
|
358
|
-
selectArgs,
|
|
359
|
-
selections,
|
|
360
|
-
variableDefinitions,
|
|
361
|
-
modelName,
|
|
362
|
-
});
|
|
363
|
-
return ast;
|
|
364
|
-
};
|
|
365
|
-
exports.createOne = createOne;
|
|
366
|
-
const patchOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
367
|
-
if (!mutation.properties?.input?.properties) {
|
|
368
|
-
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
369
|
-
}
|
|
370
|
-
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
371
|
-
const inputProperties = mutation.properties.input
|
|
372
|
-
.properties;
|
|
373
|
-
const patchProperties = inputProperties['patch'];
|
|
374
|
-
const allAttrs = patchProperties?.properties
|
|
375
|
-
? objectToArray(patchProperties.properties)
|
|
376
|
-
: [];
|
|
377
|
-
const patchAttrs = allAttrs.filter((prop) => !NON_MUTABLE_PROPS.includes(prop.name));
|
|
378
|
-
const patchByAttrs = objectToArray(inputProperties).filter((n) => n.name !== 'patch');
|
|
379
|
-
const patchers = patchByAttrs.map((p) => p.name);
|
|
380
|
-
const variableDefinitions = getUpdateVariablesAst(patchAttrs, patchers);
|
|
381
|
-
const selectArgs = [
|
|
382
|
-
t.argument({
|
|
383
|
-
name: 'input',
|
|
384
|
-
value: t.objectValue({
|
|
385
|
-
fields: [
|
|
386
|
-
...patchByAttrs.map((field) => t.objectField({
|
|
387
|
-
name: field.name,
|
|
388
|
-
value: t.variable({ name: field.name }),
|
|
389
|
-
})),
|
|
390
|
-
t.objectField({
|
|
391
|
-
name: 'patch',
|
|
392
|
-
value: t.objectValue({
|
|
393
|
-
fields: patchAttrs
|
|
394
|
-
.filter((field) => !patchers.includes(field.name))
|
|
395
|
-
.map((field) => t.objectField({
|
|
396
|
-
name: field.name,
|
|
397
|
-
value: t.variable({ name: field.name }),
|
|
398
|
-
})),
|
|
399
|
-
}),
|
|
400
|
-
}),
|
|
401
|
-
],
|
|
402
|
-
}),
|
|
403
|
-
}),
|
|
404
|
-
];
|
|
405
|
-
const selections = selection
|
|
406
|
-
? getSelections(selection)
|
|
407
|
-
: allAttrs.map((field) => t.field({ name: field.name }));
|
|
408
|
-
const ast = createGqlMutation({
|
|
409
|
-
operationName,
|
|
410
|
-
mutationName,
|
|
411
|
-
selectArgs,
|
|
412
|
-
selections,
|
|
413
|
-
variableDefinitions,
|
|
414
|
-
modelName,
|
|
415
|
-
});
|
|
416
|
-
return ast;
|
|
417
|
-
};
|
|
418
|
-
exports.patchOne = patchOne;
|
|
419
|
-
const deleteOne = ({ mutationName, operationName, mutation, }) => {
|
|
420
|
-
if (!mutation.properties?.input?.properties) {
|
|
421
|
-
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
422
|
-
}
|
|
423
|
-
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
424
|
-
const inputProperties = mutation.properties.input
|
|
425
|
-
.properties;
|
|
426
|
-
const deleteAttrs = objectToArray(inputProperties);
|
|
427
|
-
const variableDefinitions = deleteAttrs.map((field) => {
|
|
428
|
-
const { name: fieldName, type: fieldType, isNotNull, isArray } = field;
|
|
429
|
-
let type = t.namedType({ type: fieldType });
|
|
430
|
-
if (isNotNull)
|
|
431
|
-
type = t.nonNullType({ type });
|
|
432
|
-
if (isArray) {
|
|
433
|
-
type = t.listType({ type });
|
|
434
|
-
// no need to check isArrayNotNull since we need this field for deletion
|
|
435
|
-
type = t.nonNullType({ type });
|
|
436
|
-
}
|
|
437
|
-
return t.variableDefinition({
|
|
438
|
-
variable: t.variable({ name: fieldName }),
|
|
439
|
-
type,
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
const selectArgs = [
|
|
443
|
-
t.argument({
|
|
444
|
-
name: 'input',
|
|
445
|
-
value: t.objectValue({
|
|
446
|
-
fields: deleteAttrs.map((f) => t.objectField({
|
|
447
|
-
name: f.name,
|
|
448
|
-
value: t.variable({ name: f.name }),
|
|
449
|
-
})),
|
|
450
|
-
}),
|
|
451
|
-
}),
|
|
452
|
-
];
|
|
453
|
-
// so we can support column select grants plugin
|
|
454
|
-
const selections = [t.field({ name: 'clientMutationId' })];
|
|
455
|
-
const ast = createGqlMutation({
|
|
456
|
-
operationName,
|
|
457
|
-
mutationName,
|
|
458
|
-
selectArgs,
|
|
459
|
-
selections,
|
|
460
|
-
useModel: false,
|
|
461
|
-
variableDefinitions,
|
|
462
|
-
modelName,
|
|
463
|
-
});
|
|
464
|
-
return ast;
|
|
465
|
-
};
|
|
466
|
-
exports.deleteOne = deleteOne;
|
|
467
|
-
function getSelections(selection = []) {
|
|
468
|
-
const selectionAst = (field) => {
|
|
469
|
-
if (typeof field === 'string') {
|
|
470
|
-
return t.field({ name: field });
|
|
471
|
-
}
|
|
472
|
-
// Check if fieldDefn has MetaField shape (has type.pgType)
|
|
473
|
-
const fieldDefn = field.fieldDefn;
|
|
474
|
-
if (fieldDefn &&
|
|
475
|
-
'type' in fieldDefn &&
|
|
476
|
-
fieldDefn.type &&
|
|
477
|
-
typeof fieldDefn.type === 'object' &&
|
|
478
|
-
'pgType' in fieldDefn.type) {
|
|
479
|
-
const customAst = (0, custom_ast_1.getCustomAst)(fieldDefn);
|
|
480
|
-
if (customAst)
|
|
481
|
-
return customAst;
|
|
482
|
-
}
|
|
483
|
-
return t.field({ name: field.name });
|
|
484
|
-
};
|
|
485
|
-
return selection
|
|
486
|
-
.map((selectionDefn) => {
|
|
487
|
-
if (selectionDefn.isObject) {
|
|
488
|
-
const { name, selection, variables = {}, isBelongTo } = selectionDefn;
|
|
489
|
-
const args = Object.entries(variables).reduce((acc, variable) => {
|
|
490
|
-
const [argName, argValue] = variable;
|
|
491
|
-
const argAst = t.argument({
|
|
492
|
-
name: argName,
|
|
493
|
-
value: getComplexValueAst(argValue),
|
|
494
|
-
});
|
|
495
|
-
return argAst ? [...acc, argAst] : acc;
|
|
496
|
-
}, []);
|
|
497
|
-
const subSelections = selection?.map((field) => selectionAst(field)) || [];
|
|
498
|
-
const selectionSet = isBelongTo
|
|
499
|
-
? t.selectionSet({ selections: subSelections })
|
|
500
|
-
: t.selectionSet({
|
|
501
|
-
selections: [
|
|
502
|
-
t.field({ name: 'totalCount' }),
|
|
503
|
-
t.field({
|
|
504
|
-
name: 'nodes',
|
|
505
|
-
selectionSet: t.selectionSet({ selections: subSelections }),
|
|
506
|
-
}),
|
|
507
|
-
],
|
|
508
|
-
});
|
|
509
|
-
return t.field({
|
|
510
|
-
name,
|
|
511
|
-
args,
|
|
512
|
-
selectionSet,
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
return selectionAst(selectionDefn);
|
|
517
|
-
}
|
|
518
|
-
})
|
|
519
|
-
.filter((node) => node !== null);
|
|
520
|
-
}
|
|
521
|
-
function getComplexValueAst(value) {
|
|
522
|
-
// Handle null
|
|
523
|
-
if (value === null) {
|
|
524
|
-
return t.nullValue();
|
|
525
|
-
}
|
|
526
|
-
// Handle primitives
|
|
527
|
-
if (typeof value === 'boolean') {
|
|
528
|
-
return t.booleanValue({ value });
|
|
529
|
-
}
|
|
530
|
-
if (typeof value === 'number') {
|
|
531
|
-
return t.intValue({ value: value.toString() });
|
|
532
|
-
}
|
|
533
|
-
if (typeof value === 'string') {
|
|
534
|
-
return t.stringValue({ value });
|
|
535
|
-
}
|
|
536
|
-
// Handle arrays
|
|
537
|
-
if (Array.isArray(value)) {
|
|
538
|
-
return t.listValue({
|
|
539
|
-
values: value.map((item) => getComplexValueAst(item)),
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
// Handle objects
|
|
543
|
-
if (typeof value === 'object' && value !== null) {
|
|
544
|
-
const obj = value;
|
|
545
|
-
return t.objectValue({
|
|
546
|
-
fields: Object.entries(obj).map(([key, val]) => t.objectField({
|
|
547
|
-
name: key,
|
|
548
|
-
value: getComplexValueAst(val),
|
|
549
|
-
})),
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
throw new Error(`Unsupported value type: ${typeof value}`);
|
|
553
|
-
}
|
|
554
|
-
function getCreateVariablesAst(attrs) {
|
|
555
|
-
return attrs.map((field) => {
|
|
556
|
-
const { name: fieldName, type: fieldType, isNotNull, isArray, isArrayNotNull, } = field;
|
|
557
|
-
let type = t.namedType({ type: fieldType });
|
|
558
|
-
if (isNotNull)
|
|
559
|
-
type = t.nonNullType({ type });
|
|
560
|
-
if (isArray) {
|
|
561
|
-
type = t.listType({ type });
|
|
562
|
-
if (isArrayNotNull)
|
|
563
|
-
type = t.nonNullType({ type });
|
|
564
|
-
}
|
|
565
|
-
return t.variableDefinition({
|
|
566
|
-
variable: t.variable({ name: fieldName }),
|
|
567
|
-
type,
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
function getUpdateVariablesAst(attrs, patchers) {
|
|
572
|
-
const patchVariables = attrs
|
|
573
|
-
.filter((field) => !patchers.includes(field.name))
|
|
574
|
-
.map((field) => {
|
|
575
|
-
const { name: fieldName, type: fieldType, isArray, isArrayNotNull, } = field;
|
|
576
|
-
let type = t.namedType({ type: fieldType });
|
|
577
|
-
if (isArray) {
|
|
578
|
-
type = t.listType({ type });
|
|
579
|
-
if (isArrayNotNull)
|
|
580
|
-
type = t.nonNullType({ type });
|
|
581
|
-
}
|
|
582
|
-
return t.variableDefinition({
|
|
583
|
-
variable: t.variable({ name: fieldName }),
|
|
584
|
-
type,
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
const patcherVariables = patchers.map((patcher) => {
|
|
588
|
-
return t.variableDefinition({
|
|
589
|
-
variable: t.variable({ name: patcher }),
|
|
590
|
-
type: t.nonNullType({ type: t.namedType({ type: 'String' }) }),
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
return [...patchVariables, ...patcherVariables];
|
|
594
|
-
}
|
|
3
|
+
exports.getSelections = exports.deleteOne = exports.patchOne = exports.createOne = exports.getOne = exports.getMany = exports.getCount = exports.getAll = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Re-export AST builders from @constructive-io/graphql-query.
|
|
6
|
+
*
|
|
7
|
+
* These are the low-level AST generation functions (getAll, getMany, getOne,
|
|
8
|
+
* createOne, patchOne, deleteOne, getSelections). The canonical implementations
|
|
9
|
+
* now live in graphql-query.
|
|
10
|
+
*/
|
|
11
|
+
var graphql_query_1 = require("@constructive-io/graphql-query");
|
|
12
|
+
Object.defineProperty(exports, "getAll", { enumerable: true, get: function () { return graphql_query_1.getAll; } });
|
|
13
|
+
Object.defineProperty(exports, "getCount", { enumerable: true, get: function () { return graphql_query_1.getCount; } });
|
|
14
|
+
Object.defineProperty(exports, "getMany", { enumerable: true, get: function () { return graphql_query_1.getMany; } });
|
|
15
|
+
Object.defineProperty(exports, "getOne", { enumerable: true, get: function () { return graphql_query_1.getOne; } });
|
|
16
|
+
Object.defineProperty(exports, "createOne", { enumerable: true, get: function () { return graphql_query_1.createOne; } });
|
|
17
|
+
Object.defineProperty(exports, "patchOne", { enumerable: true, get: function () { return graphql_query_1.patchOne; } });
|
|
18
|
+
Object.defineProperty(exports, "deleteOne", { enumerable: true, get: function () { return graphql_query_1.deleteOne; } });
|
|
19
|
+
Object.defineProperty(exports, "getSelections", { enumerable: true, get: function () { return graphql_query_1.getSelections; } });
|
package/core/custom-ast.d.ts
CHANGED
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
import type { FieldNode } from 'graphql';
|
|
2
|
-
import type { CleanField } from '../types/schema';
|
|
3
|
-
import type { MetaField } from './types';
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
2
|
+
* Re-export custom AST utilities from @constructive-io/graphql-query.
|
|
3
|
+
*
|
|
4
|
+
* These custom AST builders handle PostgreSQL types that need subfield selections
|
|
5
|
+
* (geometry, interval, etc.). The canonical implementations now live in graphql-query.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
/**
|
|
9
|
-
* Generate custom AST for CleanField type - handles GraphQL types that need subfield selections
|
|
10
|
-
*/
|
|
11
|
-
export declare function getCustomAstForCleanField(field: CleanField): FieldNode;
|
|
12
|
-
/**
|
|
13
|
-
* Check if a CleanField requires subfield selection based on its GraphQL type
|
|
14
|
-
*/
|
|
15
|
-
export declare function requiresSubfieldSelection(field: CleanField): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Generate AST for GeometryPoint type
|
|
18
|
-
*/
|
|
19
|
-
export declare function geometryPointAst(name: string): FieldNode;
|
|
20
|
-
/**
|
|
21
|
-
* Generate AST for GeometryGeometryCollection type
|
|
22
|
-
*/
|
|
23
|
-
export declare function geometryCollectionAst(name: string): FieldNode;
|
|
24
|
-
/**
|
|
25
|
-
* Generate AST for generic geometry type (returns geojson)
|
|
26
|
-
*/
|
|
27
|
-
export declare function geometryAst(name: string): FieldNode;
|
|
28
|
-
/**
|
|
29
|
-
* Generate AST for interval type
|
|
30
|
-
*/
|
|
31
|
-
export declare function intervalAst(name: string): FieldNode;
|
|
32
|
-
/**
|
|
33
|
-
* Check if an object has interval type shape
|
|
34
|
-
*/
|
|
35
|
-
export declare function isIntervalType(obj: unknown): boolean;
|
|
7
|
+
export { getCustomAst, getCustomAstForCleanField, requiresSubfieldSelection, geometryPointAst, geometryCollectionAst, geometryAst, intervalAst, isIntervalType, } from '@constructive-io/graphql-query';
|