@constructive-io/graphql-server 3.1.1 → 4.0.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.
- package/errors/404-message.js +1 -1
- package/errors/api-errors.d.ts +200 -0
- package/errors/api-errors.js +276 -0
- package/esm/errors/404-message.js +1 -1
- package/esm/errors/api-errors.js +261 -0
- package/esm/index.js +2 -0
- package/esm/middleware/api.js +355 -277
- package/esm/middleware/auth.js +25 -7
- package/esm/middleware/error-handler.js +86 -0
- package/esm/middleware/favicon.js +12 -0
- package/esm/middleware/graphile.js +149 -64
- package/esm/options.js +232 -0
- package/esm/schema.js +24 -11
- package/esm/server.js +41 -5
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/middleware/api.d.ts +3 -15
- package/middleware/api.js +359 -283
- package/middleware/auth.js +25 -7
- package/middleware/error-handler.d.ts +4 -0
- package/middleware/error-handler.js +94 -0
- package/middleware/favicon.d.ts +2 -0
- package/middleware/favicon.js +16 -0
- package/middleware/graphile.d.ts +14 -0
- package/middleware/graphile.js +149 -64
- package/options.d.ts +131 -0
- package/options.js +244 -0
- package/package.json +23 -24
- package/schema.d.ts +2 -2
- package/schema.js +23 -10
- package/server.d.ts +24 -2
- package/server.js +39 -3
- package/codegen/orm/client.d.ts +0 -55
- package/codegen/orm/client.js +0 -75
- package/codegen/orm/index.d.ts +0 -36
- package/codegen/orm/index.js +0 -59
- package/codegen/orm/input-types.d.ts +0 -20140
- package/codegen/orm/input-types.js +0 -2
- package/codegen/orm/models/api.d.ts +0 -42
- package/codegen/orm/models/api.js +0 -76
- package/codegen/orm/models/domain.d.ts +0 -42
- package/codegen/orm/models/domain.js +0 -76
- package/codegen/orm/models/index.d.ts +0 -7
- package/codegen/orm/models/index.js +0 -12
- package/codegen/orm/mutation/index.d.ts +0 -7
- package/codegen/orm/mutation/index.js +0 -7
- package/codegen/orm/query/index.d.ts +0 -20
- package/codegen/orm/query/index.js +0 -24
- package/codegen/orm/query-builder.d.ts +0 -81
- package/codegen/orm/query-builder.js +0 -496
- package/codegen/orm/select-types.d.ts +0 -83
- package/codegen/orm/select-types.js +0 -7
- package/codegen/orm/types.d.ts +0 -6
- package/codegen/orm/types.js +0 -23
- package/esm/codegen/orm/client.js +0 -70
- package/esm/codegen/orm/index.js +0 -39
- package/esm/codegen/orm/input-types.js +0 -1
- package/esm/codegen/orm/models/api.js +0 -72
- package/esm/codegen/orm/models/domain.js +0 -72
- package/esm/codegen/orm/models/index.js +0 -7
- package/esm/codegen/orm/mutation/index.js +0 -4
- package/esm/codegen/orm/query/index.js +0 -21
- package/esm/codegen/orm/query-builder.js +0 -452
- package/esm/codegen/orm/select-types.js +0 -6
- package/esm/codegen/orm/types.js +0 -7
- package/esm/middleware/gql.js +0 -116
- package/esm/plugins/PublicKeySignature.js +0 -114
- package/esm/scripts/codegen-schema.js +0 -71
- package/esm/scripts/create-bucket.js +0 -40
- package/middleware/gql.d.ts +0 -164
- package/middleware/gql.js +0 -121
- package/plugins/PublicKeySignature.d.ts +0 -11
- package/plugins/PublicKeySignature.js +0 -121
- package/scripts/codegen-schema.d.ts +0 -1
- package/scripts/codegen-schema.js +0 -76
- package/scripts/create-bucket.d.ts +0 -1
- package/scripts/create-bucket.js +0 -42
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Query Builder - Builds and executes GraphQL operations
|
|
4
|
-
* @generated by @constructive-io/graphql-codegen
|
|
5
|
-
* DO NOT EDIT - changes will be overwritten
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.QueryBuilder = void 0;
|
|
42
|
-
exports.buildSelections = buildSelections;
|
|
43
|
-
exports.buildFindManyDocument = buildFindManyDocument;
|
|
44
|
-
exports.buildFindFirstDocument = buildFindFirstDocument;
|
|
45
|
-
exports.buildCreateDocument = buildCreateDocument;
|
|
46
|
-
exports.buildUpdateDocument = buildUpdateDocument;
|
|
47
|
-
exports.buildDeleteDocument = buildDeleteDocument;
|
|
48
|
-
exports.buildCustomDocument = buildCustomDocument;
|
|
49
|
-
const t = __importStar(require("gql-ast"));
|
|
50
|
-
const graphql_1 = require("graphql");
|
|
51
|
-
const client_1 = require("./client");
|
|
52
|
-
class QueryBuilder {
|
|
53
|
-
config;
|
|
54
|
-
constructor(config) {
|
|
55
|
-
this.config = config;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Execute the query and return a discriminated union result
|
|
59
|
-
* Use result.ok to check success, or .unwrap() to throw on error
|
|
60
|
-
*/
|
|
61
|
-
async execute() {
|
|
62
|
-
return this.config.client.execute(this.config.document, this.config.variables);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Execute and unwrap the result, throwing GraphQLRequestError on failure
|
|
66
|
-
* @throws {GraphQLRequestError} If the query returns errors
|
|
67
|
-
*/
|
|
68
|
-
async unwrap() {
|
|
69
|
-
const result = await this.execute();
|
|
70
|
-
if (!result.ok) {
|
|
71
|
-
throw new client_1.GraphQLRequestError(result.errors, result.data);
|
|
72
|
-
}
|
|
73
|
-
return result.data;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Execute and unwrap, returning defaultValue on error instead of throwing
|
|
77
|
-
*/
|
|
78
|
-
async unwrapOr(defaultValue) {
|
|
79
|
-
const result = await this.execute();
|
|
80
|
-
if (!result.ok) {
|
|
81
|
-
return defaultValue;
|
|
82
|
-
}
|
|
83
|
-
return result.data;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Execute and unwrap, calling onError callback on failure
|
|
87
|
-
*/
|
|
88
|
-
async unwrapOrElse(onError) {
|
|
89
|
-
const result = await this.execute();
|
|
90
|
-
if (!result.ok) {
|
|
91
|
-
return onError(result.errors);
|
|
92
|
-
}
|
|
93
|
-
return result.data;
|
|
94
|
-
}
|
|
95
|
-
toGraphQL() {
|
|
96
|
-
return this.config.document;
|
|
97
|
-
}
|
|
98
|
-
getVariables() {
|
|
99
|
-
return this.config.variables;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.QueryBuilder = QueryBuilder;
|
|
103
|
-
// ============================================================================
|
|
104
|
-
// Selection Builders
|
|
105
|
-
// ============================================================================
|
|
106
|
-
function buildSelections(select) {
|
|
107
|
-
if (!select) {
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
110
|
-
const fields = [];
|
|
111
|
-
for (const [key, value] of Object.entries(select)) {
|
|
112
|
-
if (value === false || value === undefined) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (value === true) {
|
|
116
|
-
fields.push(t.field({ name: key }));
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
if (typeof value === 'object' && value !== null) {
|
|
120
|
-
const nested = value;
|
|
121
|
-
if (nested.select) {
|
|
122
|
-
const nestedSelections = buildSelections(nested.select);
|
|
123
|
-
const isConnection = nested.connection === true ||
|
|
124
|
-
nested.first !== undefined ||
|
|
125
|
-
nested.filter !== undefined;
|
|
126
|
-
const args = buildArgs([
|
|
127
|
-
buildOptionalArg('first', nested.first),
|
|
128
|
-
nested.filter
|
|
129
|
-
? t.argument({
|
|
130
|
-
name: 'filter',
|
|
131
|
-
value: buildValueAst(nested.filter),
|
|
132
|
-
})
|
|
133
|
-
: null,
|
|
134
|
-
buildEnumListArg('orderBy', nested.orderBy),
|
|
135
|
-
]);
|
|
136
|
-
if (isConnection) {
|
|
137
|
-
fields.push(t.field({
|
|
138
|
-
name: key,
|
|
139
|
-
args,
|
|
140
|
-
selectionSet: t.selectionSet({
|
|
141
|
-
selections: buildConnectionSelections(nestedSelections),
|
|
142
|
-
}),
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
fields.push(t.field({
|
|
147
|
-
name: key,
|
|
148
|
-
args,
|
|
149
|
-
selectionSet: t.selectionSet({ selections: nestedSelections }),
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return fields;
|
|
156
|
-
}
|
|
157
|
-
// ============================================================================
|
|
158
|
-
// Document Builders
|
|
159
|
-
// ============================================================================
|
|
160
|
-
function buildFindManyDocument(operationName, queryField, select, args, filterTypeName, orderByTypeName) {
|
|
161
|
-
const selections = select
|
|
162
|
-
? buildSelections(select)
|
|
163
|
-
: [t.field({ name: 'id' })];
|
|
164
|
-
const variableDefinitions = [];
|
|
165
|
-
const queryArgs = [];
|
|
166
|
-
const variables = {};
|
|
167
|
-
addVariable({
|
|
168
|
-
varName: 'where',
|
|
169
|
-
argName: 'filter',
|
|
170
|
-
typeName: filterTypeName,
|
|
171
|
-
value: args.where,
|
|
172
|
-
}, variableDefinitions, queryArgs, variables);
|
|
173
|
-
addVariable({
|
|
174
|
-
varName: 'orderBy',
|
|
175
|
-
typeName: '[' + orderByTypeName + '!]',
|
|
176
|
-
value: args.orderBy?.length ? args.orderBy : undefined,
|
|
177
|
-
}, variableDefinitions, queryArgs, variables);
|
|
178
|
-
addVariable({ varName: 'first', typeName: 'Int', value: args.first }, variableDefinitions, queryArgs, variables);
|
|
179
|
-
addVariable({ varName: 'last', typeName: 'Int', value: args.last }, variableDefinitions, queryArgs, variables);
|
|
180
|
-
addVariable({ varName: 'after', typeName: 'Cursor', value: args.after }, variableDefinitions, queryArgs, variables);
|
|
181
|
-
addVariable({ varName: 'before', typeName: 'Cursor', value: args.before }, variableDefinitions, queryArgs, variables);
|
|
182
|
-
addVariable({ varName: 'offset', typeName: 'Int', value: args.offset }, variableDefinitions, queryArgs, variables);
|
|
183
|
-
const document = t.document({
|
|
184
|
-
definitions: [
|
|
185
|
-
t.operationDefinition({
|
|
186
|
-
operation: 'query',
|
|
187
|
-
name: operationName + 'Query',
|
|
188
|
-
variableDefinitions: variableDefinitions.length
|
|
189
|
-
? variableDefinitions
|
|
190
|
-
: undefined,
|
|
191
|
-
selectionSet: t.selectionSet({
|
|
192
|
-
selections: [
|
|
193
|
-
t.field({
|
|
194
|
-
name: queryField,
|
|
195
|
-
args: queryArgs.length ? queryArgs : undefined,
|
|
196
|
-
selectionSet: t.selectionSet({
|
|
197
|
-
selections: buildConnectionSelections(selections),
|
|
198
|
-
}),
|
|
199
|
-
}),
|
|
200
|
-
],
|
|
201
|
-
}),
|
|
202
|
-
}),
|
|
203
|
-
],
|
|
204
|
-
});
|
|
205
|
-
return { document: (0, graphql_1.print)(document), variables };
|
|
206
|
-
}
|
|
207
|
-
function buildFindFirstDocument(operationName, queryField, select, args, filterTypeName) {
|
|
208
|
-
const selections = select
|
|
209
|
-
? buildSelections(select)
|
|
210
|
-
: [t.field({ name: 'id' })];
|
|
211
|
-
const variableDefinitions = [];
|
|
212
|
-
const queryArgs = [];
|
|
213
|
-
const variables = {};
|
|
214
|
-
// Always add first: 1 for findFirst
|
|
215
|
-
addVariable({ varName: 'first', typeName: 'Int', value: 1 }, variableDefinitions, queryArgs, variables);
|
|
216
|
-
addVariable({
|
|
217
|
-
varName: 'where',
|
|
218
|
-
argName: 'filter',
|
|
219
|
-
typeName: filterTypeName,
|
|
220
|
-
value: args.where,
|
|
221
|
-
}, variableDefinitions, queryArgs, variables);
|
|
222
|
-
const document = t.document({
|
|
223
|
-
definitions: [
|
|
224
|
-
t.operationDefinition({
|
|
225
|
-
operation: 'query',
|
|
226
|
-
name: operationName + 'Query',
|
|
227
|
-
variableDefinitions,
|
|
228
|
-
selectionSet: t.selectionSet({
|
|
229
|
-
selections: [
|
|
230
|
-
t.field({
|
|
231
|
-
name: queryField,
|
|
232
|
-
args: queryArgs,
|
|
233
|
-
selectionSet: t.selectionSet({
|
|
234
|
-
selections: [
|
|
235
|
-
t.field({
|
|
236
|
-
name: 'nodes',
|
|
237
|
-
selectionSet: t.selectionSet({ selections }),
|
|
238
|
-
}),
|
|
239
|
-
],
|
|
240
|
-
}),
|
|
241
|
-
}),
|
|
242
|
-
],
|
|
243
|
-
}),
|
|
244
|
-
}),
|
|
245
|
-
],
|
|
246
|
-
});
|
|
247
|
-
return { document: (0, graphql_1.print)(document), variables };
|
|
248
|
-
}
|
|
249
|
-
function buildCreateDocument(operationName, mutationField, entityField, select, data, inputTypeName) {
|
|
250
|
-
const selections = select
|
|
251
|
-
? buildSelections(select)
|
|
252
|
-
: [t.field({ name: 'id' })];
|
|
253
|
-
return {
|
|
254
|
-
document: buildInputMutationDocument({
|
|
255
|
-
operationName,
|
|
256
|
-
mutationField,
|
|
257
|
-
inputTypeName,
|
|
258
|
-
resultSelections: [
|
|
259
|
-
t.field({
|
|
260
|
-
name: entityField,
|
|
261
|
-
selectionSet: t.selectionSet({ selections }),
|
|
262
|
-
}),
|
|
263
|
-
],
|
|
264
|
-
}),
|
|
265
|
-
variables: {
|
|
266
|
-
input: {
|
|
267
|
-
[entityField]: data,
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
function buildUpdateDocument(operationName, mutationField, entityField, select, where, data, inputTypeName) {
|
|
273
|
-
const selections = select
|
|
274
|
-
? buildSelections(select)
|
|
275
|
-
: [t.field({ name: 'id' })];
|
|
276
|
-
return {
|
|
277
|
-
document: buildInputMutationDocument({
|
|
278
|
-
operationName,
|
|
279
|
-
mutationField,
|
|
280
|
-
inputTypeName,
|
|
281
|
-
resultSelections: [
|
|
282
|
-
t.field({
|
|
283
|
-
name: entityField,
|
|
284
|
-
selectionSet: t.selectionSet({ selections }),
|
|
285
|
-
}),
|
|
286
|
-
],
|
|
287
|
-
}),
|
|
288
|
-
variables: {
|
|
289
|
-
input: {
|
|
290
|
-
id: where.id,
|
|
291
|
-
patch: data,
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
function buildDeleteDocument(operationName, mutationField, entityField, where, inputTypeName) {
|
|
297
|
-
return {
|
|
298
|
-
document: buildInputMutationDocument({
|
|
299
|
-
operationName,
|
|
300
|
-
mutationField,
|
|
301
|
-
inputTypeName,
|
|
302
|
-
resultSelections: [
|
|
303
|
-
t.field({
|
|
304
|
-
name: entityField,
|
|
305
|
-
selectionSet: t.selectionSet({
|
|
306
|
-
selections: [t.field({ name: 'id' })],
|
|
307
|
-
}),
|
|
308
|
-
}),
|
|
309
|
-
],
|
|
310
|
-
}),
|
|
311
|
-
variables: {
|
|
312
|
-
input: {
|
|
313
|
-
id: where.id,
|
|
314
|
-
},
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
function buildCustomDocument(operationType, operationName, fieldName, select, args, variableDefinitions) {
|
|
319
|
-
let actualSelect = select;
|
|
320
|
-
let isConnection = false;
|
|
321
|
-
if (select && typeof select === 'object' && 'select' in select) {
|
|
322
|
-
const wrapper = select;
|
|
323
|
-
if (wrapper.select) {
|
|
324
|
-
actualSelect = wrapper.select;
|
|
325
|
-
isConnection = wrapper.connection === true;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
const selections = actualSelect
|
|
329
|
-
? buildSelections(actualSelect)
|
|
330
|
-
: [];
|
|
331
|
-
const variableDefs = variableDefinitions.map((definition) => t.variableDefinition({
|
|
332
|
-
variable: t.variable({ name: definition.name }),
|
|
333
|
-
type: (0, graphql_1.parseType)(definition.type),
|
|
334
|
-
}));
|
|
335
|
-
const fieldArgs = variableDefinitions.map((definition) => t.argument({
|
|
336
|
-
name: definition.name,
|
|
337
|
-
value: t.variable({ name: definition.name }),
|
|
338
|
-
}));
|
|
339
|
-
const fieldSelections = isConnection
|
|
340
|
-
? buildConnectionSelections(selections)
|
|
341
|
-
: selections;
|
|
342
|
-
const document = t.document({
|
|
343
|
-
definitions: [
|
|
344
|
-
t.operationDefinition({
|
|
345
|
-
operation: operationType,
|
|
346
|
-
name: operationName,
|
|
347
|
-
variableDefinitions: variableDefs.length ? variableDefs : undefined,
|
|
348
|
-
selectionSet: t.selectionSet({
|
|
349
|
-
selections: [
|
|
350
|
-
t.field({
|
|
351
|
-
name: fieldName,
|
|
352
|
-
args: fieldArgs.length ? fieldArgs : undefined,
|
|
353
|
-
selectionSet: fieldSelections.length
|
|
354
|
-
? t.selectionSet({ selections: fieldSelections })
|
|
355
|
-
: undefined,
|
|
356
|
-
}),
|
|
357
|
-
],
|
|
358
|
-
}),
|
|
359
|
-
}),
|
|
360
|
-
],
|
|
361
|
-
});
|
|
362
|
-
return {
|
|
363
|
-
document: (0, graphql_1.print)(document),
|
|
364
|
-
variables: (args ?? {}),
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
// ============================================================================
|
|
368
|
-
// Helper Functions
|
|
369
|
-
// ============================================================================
|
|
370
|
-
function buildArgs(args) {
|
|
371
|
-
return args.filter((arg) => arg !== null);
|
|
372
|
-
}
|
|
373
|
-
function buildOptionalArg(name, value) {
|
|
374
|
-
if (value === undefined) {
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
const valueNode = typeof value === 'number'
|
|
378
|
-
? t.intValue({ value: value.toString() })
|
|
379
|
-
: t.stringValue({ value });
|
|
380
|
-
return t.argument({ name, value: valueNode });
|
|
381
|
-
}
|
|
382
|
-
function buildEnumListArg(name, values) {
|
|
383
|
-
if (!values || values.length === 0) {
|
|
384
|
-
return null;
|
|
385
|
-
}
|
|
386
|
-
return t.argument({
|
|
387
|
-
name,
|
|
388
|
-
value: t.listValue({
|
|
389
|
-
values: values.map((value) => buildEnumValue(value)),
|
|
390
|
-
}),
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
function buildEnumValue(value) {
|
|
394
|
-
return {
|
|
395
|
-
kind: 'EnumValue',
|
|
396
|
-
value,
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
function buildPageInfoSelections() {
|
|
400
|
-
return [
|
|
401
|
-
t.field({ name: 'hasNextPage' }),
|
|
402
|
-
t.field({ name: 'hasPreviousPage' }),
|
|
403
|
-
t.field({ name: 'startCursor' }),
|
|
404
|
-
t.field({ name: 'endCursor' }),
|
|
405
|
-
];
|
|
406
|
-
}
|
|
407
|
-
function buildConnectionSelections(nodeSelections) {
|
|
408
|
-
return [
|
|
409
|
-
t.field({
|
|
410
|
-
name: 'nodes',
|
|
411
|
-
selectionSet: t.selectionSet({ selections: nodeSelections }),
|
|
412
|
-
}),
|
|
413
|
-
t.field({ name: 'totalCount' }),
|
|
414
|
-
t.field({
|
|
415
|
-
name: 'pageInfo',
|
|
416
|
-
selectionSet: t.selectionSet({ selections: buildPageInfoSelections() }),
|
|
417
|
-
}),
|
|
418
|
-
];
|
|
419
|
-
}
|
|
420
|
-
function buildInputMutationDocument(config) {
|
|
421
|
-
const document = t.document({
|
|
422
|
-
definitions: [
|
|
423
|
-
t.operationDefinition({
|
|
424
|
-
operation: 'mutation',
|
|
425
|
-
name: config.operationName + 'Mutation',
|
|
426
|
-
variableDefinitions: [
|
|
427
|
-
t.variableDefinition({
|
|
428
|
-
variable: t.variable({ name: 'input' }),
|
|
429
|
-
type: (0, graphql_1.parseType)(config.inputTypeName + '!'),
|
|
430
|
-
}),
|
|
431
|
-
],
|
|
432
|
-
selectionSet: t.selectionSet({
|
|
433
|
-
selections: [
|
|
434
|
-
t.field({
|
|
435
|
-
name: config.mutationField,
|
|
436
|
-
args: [
|
|
437
|
-
t.argument({
|
|
438
|
-
name: 'input',
|
|
439
|
-
value: t.variable({ name: 'input' }),
|
|
440
|
-
}),
|
|
441
|
-
],
|
|
442
|
-
selectionSet: t.selectionSet({
|
|
443
|
-
selections: config.resultSelections,
|
|
444
|
-
}),
|
|
445
|
-
}),
|
|
446
|
-
],
|
|
447
|
-
}),
|
|
448
|
-
}),
|
|
449
|
-
],
|
|
450
|
-
});
|
|
451
|
-
return (0, graphql_1.print)(document);
|
|
452
|
-
}
|
|
453
|
-
function addVariable(spec, definitions, args, variables) {
|
|
454
|
-
if (spec.value === undefined)
|
|
455
|
-
return;
|
|
456
|
-
definitions.push(t.variableDefinition({
|
|
457
|
-
variable: t.variable({ name: spec.varName }),
|
|
458
|
-
type: (0, graphql_1.parseType)(spec.typeName),
|
|
459
|
-
}));
|
|
460
|
-
args.push(t.argument({
|
|
461
|
-
name: spec.argName ?? spec.varName,
|
|
462
|
-
value: t.variable({ name: spec.varName }),
|
|
463
|
-
}));
|
|
464
|
-
variables[spec.varName] = spec.value;
|
|
465
|
-
}
|
|
466
|
-
function buildValueAst(value) {
|
|
467
|
-
if (value === null) {
|
|
468
|
-
return t.nullValue();
|
|
469
|
-
}
|
|
470
|
-
if (typeof value === 'boolean') {
|
|
471
|
-
return t.booleanValue({ value });
|
|
472
|
-
}
|
|
473
|
-
if (typeof value === 'number') {
|
|
474
|
-
return Number.isInteger(value)
|
|
475
|
-
? t.intValue({ value: value.toString() })
|
|
476
|
-
: t.floatValue({ value: value.toString() });
|
|
477
|
-
}
|
|
478
|
-
if (typeof value === 'string') {
|
|
479
|
-
return t.stringValue({ value });
|
|
480
|
-
}
|
|
481
|
-
if (Array.isArray(value)) {
|
|
482
|
-
return t.listValue({
|
|
483
|
-
values: value.map((item) => buildValueAst(item)),
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
if (typeof value === 'object' && value !== null) {
|
|
487
|
-
const obj = value;
|
|
488
|
-
return t.objectValue({
|
|
489
|
-
fields: Object.entries(obj).map(([key, val]) => t.objectField({
|
|
490
|
-
name: key,
|
|
491
|
-
value: buildValueAst(val),
|
|
492
|
-
})),
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
throw new Error('Unsupported value type: ' + typeof value);
|
|
496
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type utilities for select inference
|
|
3
|
-
* @generated by @constructive-io/graphql-codegen
|
|
4
|
-
* DO NOT EDIT - changes will be overwritten
|
|
5
|
-
*/
|
|
6
|
-
export interface ConnectionResult<T> {
|
|
7
|
-
nodes: T[];
|
|
8
|
-
totalCount: number;
|
|
9
|
-
pageInfo: PageInfo;
|
|
10
|
-
}
|
|
11
|
-
export interface PageInfo {
|
|
12
|
-
hasNextPage: boolean;
|
|
13
|
-
hasPreviousPage: boolean;
|
|
14
|
-
startCursor?: string | null;
|
|
15
|
-
endCursor?: string | null;
|
|
16
|
-
}
|
|
17
|
-
export interface FindManyArgs<TSelect, TWhere, TOrderBy> {
|
|
18
|
-
select?: TSelect;
|
|
19
|
-
where?: TWhere;
|
|
20
|
-
orderBy?: TOrderBy[];
|
|
21
|
-
first?: number;
|
|
22
|
-
last?: number;
|
|
23
|
-
after?: string;
|
|
24
|
-
before?: string;
|
|
25
|
-
offset?: number;
|
|
26
|
-
}
|
|
27
|
-
export interface FindFirstArgs<TSelect, TWhere> {
|
|
28
|
-
select?: TSelect;
|
|
29
|
-
where?: TWhere;
|
|
30
|
-
}
|
|
31
|
-
export interface CreateArgs<TSelect, TData> {
|
|
32
|
-
data: TData;
|
|
33
|
-
select?: TSelect;
|
|
34
|
-
}
|
|
35
|
-
export interface UpdateArgs<TSelect, TWhere, TData> {
|
|
36
|
-
where: TWhere;
|
|
37
|
-
data: TData;
|
|
38
|
-
select?: TSelect;
|
|
39
|
-
}
|
|
40
|
-
export interface DeleteArgs<TWhere> {
|
|
41
|
-
where: TWhere;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Recursively validates select objects, rejecting unknown keys.
|
|
45
|
-
*
|
|
46
|
-
* This type ensures that users can only select fields that actually exist
|
|
47
|
-
* in the GraphQL schema. It returns `never` if any excess keys are found
|
|
48
|
-
* at any nesting level, causing a TypeScript compile error.
|
|
49
|
-
*
|
|
50
|
-
* Why this is needed:
|
|
51
|
-
* TypeScript's excess property checking has a quirk where it only catches
|
|
52
|
-
* invalid fields when they are the ONLY fields. When mixed with valid fields
|
|
53
|
-
* (e.g., `{ id: true, invalidField: true }`), the structural typing allows
|
|
54
|
-
* the excess property through. This type explicitly checks for and rejects
|
|
55
|
-
* such cases.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* // This will cause a type error because 'invalid' doesn't exist:
|
|
59
|
-
* type Result = DeepExact<{ id: true, invalid: true }, { id?: boolean }>;
|
|
60
|
-
* // Result = never (causes assignment error)
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* // This works because all fields are valid:
|
|
64
|
-
* type Result = DeepExact<{ id: true }, { id?: boolean; name?: boolean }>;
|
|
65
|
-
* // Result = { id: true }
|
|
66
|
-
*/
|
|
67
|
-
export type DeepExact<T, Shape> = T extends Shape ? Exclude<keyof T, keyof Shape> extends never ? {
|
|
68
|
-
[K in keyof T]: K extends keyof Shape ? T[K] extends {
|
|
69
|
-
select: infer NS;
|
|
70
|
-
} ? Shape[K] extends {
|
|
71
|
-
select?: infer ShapeNS;
|
|
72
|
-
} ? {
|
|
73
|
-
select: DeepExact<NS, NonNullable<ShapeNS>>;
|
|
74
|
-
} : T[K] : T[K] : never;
|
|
75
|
-
} : never : never;
|
|
76
|
-
/**
|
|
77
|
-
* Infer result type from select configuration
|
|
78
|
-
*/
|
|
79
|
-
export type InferSelectResult<TEntity, TSelect> = TSelect extends undefined ? TEntity : {
|
|
80
|
-
[K in keyof TSelect as TSelect[K] extends false | undefined ? never : K]: TSelect[K] extends true ? K extends keyof TEntity ? TEntity[K] : never : TSelect[K] extends {
|
|
81
|
-
select: infer NestedSelect;
|
|
82
|
-
} ? K extends keyof TEntity ? NonNullable<TEntity[K]> extends ConnectionResult<infer NodeType> ? ConnectionResult<InferSelectResult<NodeType, NestedSelect>> : InferSelectResult<NonNullable<TEntity[K]>, NestedSelect> | (null extends TEntity[K] ? null : never) : never : K extends keyof TEntity ? TEntity[K] : never;
|
|
83
|
-
};
|
package/codegen/orm/types.d.ts
DELETED
package/codegen/orm/types.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Types re-export
|
|
4
|
-
* @generated by @constructive-io/graphql-codegen
|
|
5
|
-
* DO NOT EDIT - changes will be overwritten
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
// Re-export all types from input-types
|
|
23
|
-
__exportStar(require("./input-types"), exports);
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ORM Client - Runtime GraphQL executor
|
|
3
|
-
* @generated by @constructive-io/graphql-codegen
|
|
4
|
-
* DO NOT EDIT - changes will be overwritten
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Error thrown when GraphQL request fails
|
|
8
|
-
*/
|
|
9
|
-
export class GraphQLRequestError extends Error {
|
|
10
|
-
errors;
|
|
11
|
-
data;
|
|
12
|
-
constructor(errors, data = null) {
|
|
13
|
-
const messages = errors.map((e) => e.message).join('; ');
|
|
14
|
-
super(`GraphQL Error: ${messages}`);
|
|
15
|
-
this.errors = errors;
|
|
16
|
-
this.data = data;
|
|
17
|
-
this.name = 'GraphQLRequestError';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export class OrmClient {
|
|
21
|
-
endpoint;
|
|
22
|
-
headers;
|
|
23
|
-
constructor(config) {
|
|
24
|
-
this.endpoint = config.endpoint;
|
|
25
|
-
this.headers = config.headers ?? {};
|
|
26
|
-
}
|
|
27
|
-
async execute(document, variables) {
|
|
28
|
-
const response = await fetch(this.endpoint, {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
headers: {
|
|
31
|
-
'Content-Type': 'application/json',
|
|
32
|
-
Accept: 'application/json',
|
|
33
|
-
...this.headers,
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify({
|
|
36
|
-
query: document,
|
|
37
|
-
variables: variables ?? {},
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
return {
|
|
42
|
-
ok: false,
|
|
43
|
-
data: null,
|
|
44
|
-
errors: [
|
|
45
|
-
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
46
|
-
],
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const json = (await response.json());
|
|
50
|
-
// Return discriminated union based on presence of errors
|
|
51
|
-
if (json.errors && json.errors.length > 0) {
|
|
52
|
-
return {
|
|
53
|
-
ok: false,
|
|
54
|
-
data: null,
|
|
55
|
-
errors: json.errors,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
ok: true,
|
|
60
|
-
data: json.data,
|
|
61
|
-
errors: undefined,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
setHeaders(headers) {
|
|
65
|
-
this.headers = { ...this.headers, ...headers };
|
|
66
|
-
}
|
|
67
|
-
getEndpoint() {
|
|
68
|
-
return this.endpoint;
|
|
69
|
-
}
|
|
70
|
-
}
|