remult 0.25.4 → 0.25.5-exp.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/esm/graphql.js +130 -72
- package/esm/src/remult3/remult3.js +4 -5
- package/graphql.d.ts +1 -1
- package/graphql.js +129 -63
- package/package.json +1 -1
- package/src/remult3/remult3.js +4 -5
package/esm/graphql.js
CHANGED
|
@@ -6,7 +6,7 @@ const andImplementation = false;
|
|
|
6
6
|
let _removeComments = false;
|
|
7
7
|
export function remultGraphql(options) {
|
|
8
8
|
if (!options.getRemultFromRequest) {
|
|
9
|
-
options.getRemultFromRequest = () => remult;
|
|
9
|
+
options.getRemultFromRequest = async () => remult;
|
|
10
10
|
}
|
|
11
11
|
const { removeComments } = {
|
|
12
12
|
removeComments: false,
|
|
@@ -153,7 +153,7 @@ export function remultGraphql(options) {
|
|
|
153
153
|
};
|
|
154
154
|
const handleRequestWithDataApiContext = (work) => {
|
|
155
155
|
return createResultPromise(async (response, setResult, arg1, req) => {
|
|
156
|
-
const remult = options.getRemultFromRequest(req);
|
|
156
|
+
const remult = await options.getRemultFromRequest(req);
|
|
157
157
|
const repo = remult.repo(meta.entityType);
|
|
158
158
|
const dApi = new DataApi(repo, remult);
|
|
159
159
|
await work(dApi, response, setResult, arg1, meta);
|
|
@@ -205,69 +205,10 @@ export function remultGraphql(options) {
|
|
|
205
205
|
}, setResult, arg1, req);
|
|
206
206
|
});
|
|
207
207
|
};
|
|
208
|
-
const queryArgsConnection =
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
comment: `
|
|
213
|
-
For **page by page** pagination.
|
|
214
|
-
Limit the number of result.
|
|
215
|
-
_Side note: \`Math.ceil(totalCount / limit)\` to determine how many pages there are._`,
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
key: 'page',
|
|
219
|
-
value: 'Int',
|
|
220
|
-
comment: `
|
|
221
|
-
For **page by page** pagination.
|
|
222
|
-
Select a dedicated page.`,
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
key: 'offset',
|
|
226
|
-
value: 'Int',
|
|
227
|
-
comment: `
|
|
228
|
-
For **page by page** pagination.
|
|
229
|
-
Set the offset needed.
|
|
230
|
-
_Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
key: 'orderBy',
|
|
234
|
-
value: `${key}OrderBy`,
|
|
235
|
-
comment: `Remult sorting options`,
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
key: 'where',
|
|
239
|
-
value: `${key}Where`,
|
|
240
|
-
comment: `Remult filtering options`,
|
|
241
|
-
},
|
|
242
|
-
];
|
|
243
|
-
if (v2ConnectionAndPagination) {
|
|
244
|
-
queryArgsConnection.push({
|
|
245
|
-
key: 'first',
|
|
246
|
-
value: 'Int',
|
|
247
|
-
comment: `
|
|
248
|
-
For **forward cursor** pagination
|
|
249
|
-
Takes the \`first\`: \`n\` elements from the list.`,
|
|
250
|
-
}, {
|
|
251
|
-
key: 'after',
|
|
252
|
-
value: 'String',
|
|
253
|
-
comment: `
|
|
254
|
-
For **forward cursor** pagination
|
|
255
|
-
\`after\` this \`cursor\`.`,
|
|
256
|
-
}, {
|
|
257
|
-
key: 'last',
|
|
258
|
-
value: 'Int',
|
|
259
|
-
comment: `
|
|
260
|
-
For **backward cursor** pagination
|
|
261
|
-
Takes the \`last\`: \`n\` elements from the list.`,
|
|
262
|
-
}, {
|
|
263
|
-
key: 'before',
|
|
264
|
-
value: 'String',
|
|
265
|
-
comment: `
|
|
266
|
-
For **backward cursor** pagination
|
|
267
|
-
\`before\` this \`cursor\`.`,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
const getSingleEntityKey = toCamelCase(getMetaType(meta));
|
|
208
|
+
const queryArgsConnection = getQueryArgsConnection(key);
|
|
209
|
+
let getSingleEntityKey = toCamelCase(getMetaType(meta));
|
|
210
|
+
if (getSingleEntityKey === toCamelCase(key))
|
|
211
|
+
getSingleEntityKey = 'single' + key;
|
|
271
212
|
root_query.fields.push({
|
|
272
213
|
key: getSingleEntityKey,
|
|
273
214
|
args: [argId],
|
|
@@ -458,9 +399,6 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
458
399
|
for (const f of meta.fields) {
|
|
459
400
|
const ri = getRelationInfo(f.options);
|
|
460
401
|
// let's not consider toMany relations for now
|
|
461
|
-
if (ri?.type === 'toMany') {
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
402
|
if (f.options.includeInApi === false)
|
|
465
403
|
continue;
|
|
466
404
|
let type = 'String';
|
|
@@ -478,11 +416,66 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
478
416
|
}
|
|
479
417
|
break;
|
|
480
418
|
}
|
|
481
|
-
const ref = entities.find((i) => i.entityType === f.valueType);
|
|
482
419
|
currentType.query.resultProcessors.push((r) => {
|
|
483
420
|
r[nodeIdKey] = () => getMetaType(meta) + ':' + meta.idMetadata.getId(r);
|
|
484
421
|
});
|
|
485
|
-
|
|
422
|
+
let ref = entities.find((i) => i.entityType === f.valueType);
|
|
423
|
+
let notARealField = false;
|
|
424
|
+
if (ri) {
|
|
425
|
+
{
|
|
426
|
+
const refType = ri.toType();
|
|
427
|
+
ref = entities.find((i) => i.entityType === refType);
|
|
428
|
+
}
|
|
429
|
+
notARealField = ri.type === 'toOne' || ri.type === 'toMany';
|
|
430
|
+
const refKey = ref.key;
|
|
431
|
+
switch (ri.type) {
|
|
432
|
+
case 'reference':
|
|
433
|
+
case 'toOne':
|
|
434
|
+
currentType.fields.push({
|
|
435
|
+
key: f.key,
|
|
436
|
+
value: `${getMetaType(ref)}${f.allowNull ? '' : '!'}`,
|
|
437
|
+
comment: f.caption,
|
|
438
|
+
});
|
|
439
|
+
currentType.query.resultProcessors.push((r) => {
|
|
440
|
+
const val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
441
|
+
if (val === null || val === undefined)
|
|
442
|
+
return null;
|
|
443
|
+
r[f.key] = async (args, req, gqlInfo) => {
|
|
444
|
+
const queryResult = await (await root[refKey]({
|
|
445
|
+
...args.where,
|
|
446
|
+
where: { id: { eq: val } },
|
|
447
|
+
options: { limit: 1 },
|
|
448
|
+
}, req, gqlInfo)).items();
|
|
449
|
+
if (queryResult.length > 0)
|
|
450
|
+
return queryResult[0];
|
|
451
|
+
return null;
|
|
452
|
+
};
|
|
453
|
+
});
|
|
454
|
+
break;
|
|
455
|
+
case 'toMany':
|
|
456
|
+
// will do: Category.tasks (actually: Category.tasksOfcategory & tasksOfcategory2)
|
|
457
|
+
currentType.fields.push({
|
|
458
|
+
key: f.key,
|
|
459
|
+
args: getQueryArgsConnection(refKey),
|
|
460
|
+
value: `${getMetaType(ref)}Connection`,
|
|
461
|
+
order: 10,
|
|
462
|
+
comment: `List all \`${getMetaType(meta)}\` of \`${refKey}\``,
|
|
463
|
+
});
|
|
464
|
+
currentType.query.resultProcessors.push((r) => {
|
|
465
|
+
const val = r.id;
|
|
466
|
+
r[f.key] = async (args, req, gqlInfo) => {
|
|
467
|
+
return await root[ref.key]({
|
|
468
|
+
where: {
|
|
469
|
+
...args.where,
|
|
470
|
+
[f.options.field /*//p1 to fix*/]: { eq: val },
|
|
471
|
+
},
|
|
472
|
+
options: { ...args.limit, ...args.page, ...args.orderBy },
|
|
473
|
+
}, req, gqlInfo);
|
|
474
|
+
};
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else if (ref !== undefined) {
|
|
486
479
|
// will do: Task.category
|
|
487
480
|
currentType.fields.push({
|
|
488
481
|
key: f.key,
|
|
@@ -538,10 +531,10 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
538
531
|
// helper
|
|
539
532
|
const it_is_not_at_ref = ref === undefined;
|
|
540
533
|
// where
|
|
541
|
-
if (it_is_not_at_ref && !f.isServerExpression) {
|
|
534
|
+
if (it_is_not_at_ref && !f.isServerExpression && !notARealField) {
|
|
542
535
|
whereTypeFields.push(`${f.key}: Where${type}${f.allowNull ? 'Nullable' : ''}`);
|
|
543
536
|
}
|
|
544
|
-
const includeInUpdateOrInsert = f.options.allowApiUpdate !== false;
|
|
537
|
+
const includeInUpdateOrInsert = f.options.allowApiUpdate !== false && !notARealField;
|
|
545
538
|
const updateType = it_is_not_at_ref ? type : 'ID';
|
|
546
539
|
if (includeInUpdateOrInsert) {
|
|
547
540
|
// create
|
|
@@ -687,6 +680,71 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
687
680
|
`,
|
|
688
681
|
};
|
|
689
682
|
}
|
|
683
|
+
function getQueryArgsConnection(key) {
|
|
684
|
+
const queryArgsConnection = [
|
|
685
|
+
{
|
|
686
|
+
key: 'limit',
|
|
687
|
+
value: 'Int',
|
|
688
|
+
comment: `
|
|
689
|
+
For **page by page** pagination.
|
|
690
|
+
Limit the number of result.
|
|
691
|
+
_Side note: \`Math.ceil(totalCount / limit)\` to determine how many pages there are._`,
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
key: 'page',
|
|
695
|
+
value: 'Int',
|
|
696
|
+
comment: `
|
|
697
|
+
For **page by page** pagination.
|
|
698
|
+
Select a dedicated page.`,
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
key: 'offset',
|
|
702
|
+
value: 'Int',
|
|
703
|
+
comment: `
|
|
704
|
+
For **page by page** pagination.
|
|
705
|
+
Set the offset needed.
|
|
706
|
+
_Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
key: 'orderBy',
|
|
710
|
+
value: `${key}OrderBy`,
|
|
711
|
+
comment: `Remult sorting options`,
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
key: 'where',
|
|
715
|
+
value: `${key}Where`,
|
|
716
|
+
comment: `Remult filtering options`,
|
|
717
|
+
},
|
|
718
|
+
];
|
|
719
|
+
if (v2ConnectionAndPagination) {
|
|
720
|
+
queryArgsConnection.push({
|
|
721
|
+
key: 'first',
|
|
722
|
+
value: 'Int',
|
|
723
|
+
comment: `
|
|
724
|
+
For **forward cursor** pagination
|
|
725
|
+
Takes the \`first\`: \`n\` elements from the list.`,
|
|
726
|
+
}, {
|
|
727
|
+
key: 'after',
|
|
728
|
+
value: 'String',
|
|
729
|
+
comment: `
|
|
730
|
+
For **forward cursor** pagination
|
|
731
|
+
\`after\` this \`cursor\`.`,
|
|
732
|
+
}, {
|
|
733
|
+
key: 'last',
|
|
734
|
+
value: 'Int',
|
|
735
|
+
comment: `
|
|
736
|
+
For **backward cursor** pagination
|
|
737
|
+
Takes the \`last\`: \`n\` elements from the list.`,
|
|
738
|
+
}, {
|
|
739
|
+
key: 'before',
|
|
740
|
+
value: 'String',
|
|
741
|
+
comment: `
|
|
742
|
+
For **backward cursor** pagination
|
|
743
|
+
\`before\` this \`cursor\`.`,
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
return queryArgsConnection;
|
|
747
|
+
}
|
|
690
748
|
// For cursor pagination (v2)
|
|
691
749
|
// function checkPaginationArgs(args: any) {
|
|
692
750
|
// let paginationPage = !!args.limit ? 1 : 0
|
|
@@ -17,6 +17,7 @@ export {};
|
|
|
17
17
|
//p2 - allow find options preprocessor for api calls, to use for authorization
|
|
18
18
|
//p1 - write doc about controlling updates of rows...
|
|
19
19
|
//p1 - need a way to extract the fields from the relation - for generating relation based sql
|
|
20
|
+
//p1 - when doing this, work on graphql relation with fields not just field
|
|
20
21
|
//p1 - add docs for apply changes
|
|
21
22
|
//p1 - when subscribe is forbidden - the query still runs after the renew process
|
|
22
23
|
//p1 - 'update tasks set where id = $1
|
|
@@ -43,14 +44,12 @@ remult.apiClient.url='localhost:3007/api
|
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
*/
|
|
46
|
-
//p1 - investigate angular starter kit init request error
|
|
47
|
-
//p1 - fix angular starter kit await set password
|
|
48
|
-
//p1 - fix angular starter kit to latest version as well
|
|
49
|
-
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
50
|
-
//p1 - fix multiple instances of remult: the defaultRemult and async local hook - and columnsOfType - all can be tests with a vite project loading `remult-admin`
|
|
51
47
|
//p1 - crm demo graphql error
|
|
48
|
+
//p1 - fix multiple instances of remult: the defaultRemult and async local hook - and columnsOfType - all can be tests with a vite project loading `remult-admin`
|
|
49
|
+
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
52
50
|
//p1 - allow api update only for new rows
|
|
53
51
|
//p1 - getFields didn't work for kobi in the home component
|
|
52
|
+
//p1 - https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
|
|
54
53
|
//p2 - document validators
|
|
55
54
|
//p2 - and validators to reference
|
|
56
55
|
//y2 - discuss a default date formatter
|
package/graphql.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Remult } from './index.js';
|
|
|
3
3
|
export declare function remultGraphql(options: {
|
|
4
4
|
removeComments?: boolean;
|
|
5
5
|
entities: ClassType<any>[];
|
|
6
|
-
getRemultFromRequest?: (req: any) => Remult
|
|
6
|
+
getRemultFromRequest?: (req: any) => Promise<Remult>;
|
|
7
7
|
}): {
|
|
8
8
|
resolvers: {
|
|
9
9
|
Query: Record<string, unknown>;
|
package/graphql.js
CHANGED
|
@@ -13,7 +13,9 @@ function remultGraphql(options) {
|
|
|
13
13
|
var _this = this;
|
|
14
14
|
var _f, _g;
|
|
15
15
|
if (!options.getRemultFromRequest) {
|
|
16
|
-
options.getRemultFromRequest = function () { return
|
|
16
|
+
options.getRemultFromRequest = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
17
|
+
return [2 /*return*/, index_js_1.remult];
|
|
18
|
+
}); }); };
|
|
17
19
|
}
|
|
18
20
|
var removeComments = tslib_1.__assign({ removeComments: false }, options).removeComments;
|
|
19
21
|
if (removeComments) {
|
|
@@ -206,12 +208,13 @@ function remultGraphql(options) {
|
|
|
206
208
|
var remult, repo, dApi;
|
|
207
209
|
return tslib_1.__generator(this, function (_a) {
|
|
208
210
|
switch (_a.label) {
|
|
209
|
-
case 0:
|
|
210
|
-
|
|
211
|
+
case 0: return [4 /*yield*/, options.getRemultFromRequest(req)];
|
|
212
|
+
case 1:
|
|
213
|
+
remult = _a.sent();
|
|
211
214
|
repo = remult.repo(meta.entityType);
|
|
212
215
|
dApi = new data_api_js_1.DataApi(repo, remult);
|
|
213
216
|
return [4 /*yield*/, work(dApi, response, setResult, arg1, meta)];
|
|
214
|
-
case
|
|
217
|
+
case 2:
|
|
215
218
|
_a.sent();
|
|
216
219
|
return [2 /*return*/];
|
|
217
220
|
}
|
|
@@ -259,53 +262,10 @@ function remultGraphql(options) {
|
|
|
259
262
|
});
|
|
260
263
|
}); });
|
|
261
264
|
};
|
|
262
|
-
var queryArgsConnection =
|
|
263
|
-
{
|
|
264
|
-
key: 'limit',
|
|
265
|
-
value: 'Int',
|
|
266
|
-
comment: "\nFor **page by page** pagination.\nLimit the number of result. \n_Side note: `Math.ceil(totalCount / limit)` to determine how many pages there are._",
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
key: 'page',
|
|
270
|
-
value: 'Int',
|
|
271
|
-
comment: "\nFor **page by page** pagination.\nSelect a dedicated page.",
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
key: 'offset',
|
|
275
|
-
value: 'Int',
|
|
276
|
-
comment: "\nFor **page by page** pagination.\nSet the offset needed.\n_Side node: if `page` arg is set, `offset` will be ignored._",
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
key: 'orderBy',
|
|
280
|
-
value: "".concat(key, "OrderBy"),
|
|
281
|
-
comment: "Remult sorting options",
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
key: 'where',
|
|
285
|
-
value: "".concat(key, "Where"),
|
|
286
|
-
comment: "Remult filtering options",
|
|
287
|
-
},
|
|
288
|
-
];
|
|
289
|
-
if (v2ConnectionAndPagination) {
|
|
290
|
-
queryArgsConnection.push({
|
|
291
|
-
key: 'first',
|
|
292
|
-
value: 'Int',
|
|
293
|
-
comment: "\n For **forward cursor** pagination\n Takes the `first`: `n` elements from the list.",
|
|
294
|
-
}, {
|
|
295
|
-
key: 'after',
|
|
296
|
-
value: 'String',
|
|
297
|
-
comment: "\n For **forward cursor** pagination\n `after` this `cursor`.",
|
|
298
|
-
}, {
|
|
299
|
-
key: 'last',
|
|
300
|
-
value: 'Int',
|
|
301
|
-
comment: "\n For **backward cursor** pagination\n Takes the `last`: `n` elements from the list.",
|
|
302
|
-
}, {
|
|
303
|
-
key: 'before',
|
|
304
|
-
value: 'String',
|
|
305
|
-
comment: "\n For **backward cursor** pagination\n `before` this `cursor`.",
|
|
306
|
-
});
|
|
307
|
-
}
|
|
265
|
+
var queryArgsConnection = getQueryArgsConnection(key);
|
|
308
266
|
var getSingleEntityKey_1 = toCamelCase(getMetaType(meta));
|
|
267
|
+
if (getSingleEntityKey_1 === toCamelCase(key))
|
|
268
|
+
getSingleEntityKey_1 = 'single' + key;
|
|
309
269
|
root_query.fields.push({
|
|
310
270
|
key: getSingleEntityKey_1,
|
|
311
271
|
args: [argId],
|
|
@@ -530,9 +490,6 @@ function remultGraphql(options) {
|
|
|
530
490
|
var _loop_2 = function (f) {
|
|
531
491
|
var ri = (0, internals_js_1.getRelationInfo)(f.options);
|
|
532
492
|
// let's not consider toMany relations for now
|
|
533
|
-
if ((ri === null || ri === void 0 ? void 0 : ri.type) === 'toMany') {
|
|
534
|
-
return "break";
|
|
535
|
-
}
|
|
536
493
|
if (f.options.includeInApi === false)
|
|
537
494
|
return "continue";
|
|
538
495
|
var type = 'String';
|
|
@@ -550,20 +507,82 @@ function remultGraphql(options) {
|
|
|
550
507
|
}
|
|
551
508
|
break;
|
|
552
509
|
}
|
|
553
|
-
var ref = entities.find(function (i) { return i.entityType === f.valueType; });
|
|
554
510
|
currentType.query.resultProcessors.push(function (r) {
|
|
555
511
|
r[nodeIdKey] = function () {
|
|
556
512
|
return getMetaType(meta) + ':' + meta.idMetadata.getId(r);
|
|
557
513
|
};
|
|
558
514
|
});
|
|
559
|
-
|
|
515
|
+
var ref = entities.find(function (i) { return i.entityType === f.valueType; });
|
|
516
|
+
var notARealField = false;
|
|
517
|
+
if (ri) {
|
|
518
|
+
{
|
|
519
|
+
var refType_1 = ri.toType();
|
|
520
|
+
ref = entities.find(function (i) { return i.entityType === refType_1; });
|
|
521
|
+
}
|
|
522
|
+
notARealField = ri.type === 'toOne' || ri.type === 'toMany';
|
|
523
|
+
var refKey_1 = ref.key;
|
|
524
|
+
switch (ri.type) {
|
|
525
|
+
case 'reference':
|
|
526
|
+
case 'toOne':
|
|
527
|
+
currentType.fields.push({
|
|
528
|
+
key: f.key,
|
|
529
|
+
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
530
|
+
comment: f.caption,
|
|
531
|
+
});
|
|
532
|
+
currentType.query.resultProcessors.push(function (r) {
|
|
533
|
+
var val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
534
|
+
if (val === null || val === undefined)
|
|
535
|
+
return null;
|
|
536
|
+
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
537
|
+
var queryResult;
|
|
538
|
+
return tslib_1.__generator(this, function (_a) {
|
|
539
|
+
switch (_a.label) {
|
|
540
|
+
case 0: return [4 /*yield*/, root[refKey_1](tslib_1.__assign(tslib_1.__assign({}, args.where), { where: { id: { eq: val } }, options: { limit: 1 } }), req, gqlInfo)];
|
|
541
|
+
case 1: return [4 /*yield*/, (_a.sent()).items()];
|
|
542
|
+
case 2:
|
|
543
|
+
queryResult = _a.sent();
|
|
544
|
+
if (queryResult.length > 0)
|
|
545
|
+
return [2 /*return*/, queryResult[0]];
|
|
546
|
+
return [2 /*return*/, null];
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
}); };
|
|
550
|
+
});
|
|
551
|
+
break;
|
|
552
|
+
case 'toMany':
|
|
553
|
+
// will do: Category.tasks (actually: Category.tasksOfcategory & tasksOfcategory2)
|
|
554
|
+
currentType.fields.push({
|
|
555
|
+
key: f.key,
|
|
556
|
+
args: getQueryArgsConnection(refKey_1),
|
|
557
|
+
value: "".concat(getMetaType(ref), "Connection"),
|
|
558
|
+
order: 10,
|
|
559
|
+
comment: "List all `".concat(getMetaType(meta), "` of `").concat(refKey_1, "`"),
|
|
560
|
+
});
|
|
561
|
+
currentType.query.resultProcessors.push(function (r) {
|
|
562
|
+
var val = r.id;
|
|
563
|
+
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
564
|
+
var _a;
|
|
565
|
+
return tslib_1.__generator(this, function (_b) {
|
|
566
|
+
switch (_b.label) {
|
|
567
|
+
case 0: return [4 /*yield*/, root[ref.key]({
|
|
568
|
+
where: tslib_1.__assign(tslib_1.__assign({}, args.where), (_a = {}, _a[f.options.field /*//p1 to fix*/] = { eq: val }, _a)),
|
|
569
|
+
options: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, args.limit), args.page), args.orderBy),
|
|
570
|
+
}, req, gqlInfo)];
|
|
571
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}); };
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else if (ref !== undefined) {
|
|
560
579
|
// will do: Task.category
|
|
561
580
|
currentType.fields.push({
|
|
562
581
|
key: f.key,
|
|
563
582
|
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
564
583
|
comment: f.caption,
|
|
565
584
|
});
|
|
566
|
-
var
|
|
585
|
+
var refKey_2 = ref.key;
|
|
567
586
|
currentType.query.resultProcessors.push(function (r) {
|
|
568
587
|
var val = r[f.key];
|
|
569
588
|
if (val === null || val === undefined)
|
|
@@ -572,7 +591,7 @@ function remultGraphql(options) {
|
|
|
572
591
|
var queryResult;
|
|
573
592
|
return tslib_1.__generator(this, function (_a) {
|
|
574
593
|
switch (_a.label) {
|
|
575
|
-
case 0: return [4 /*yield*/, root[
|
|
594
|
+
case 0: return [4 /*yield*/, root[refKey_2](tslib_1.__assign(tslib_1.__assign({}, args.where), { where: { id: { eq: val } }, options: { limit: 1 } }), req, gqlInfo)];
|
|
576
595
|
case 1: return [4 /*yield*/, (_a.sent()).items()];
|
|
577
596
|
case 2:
|
|
578
597
|
queryResult = _a.sent();
|
|
@@ -591,7 +610,7 @@ function remultGraphql(options) {
|
|
|
591
610
|
args: queryArgsConnection,
|
|
592
611
|
value: connectionKey,
|
|
593
612
|
order: 10,
|
|
594
|
-
comment: "List all `".concat(getMetaType(meta), "` of `").concat(
|
|
613
|
+
comment: "List all `".concat(getMetaType(meta), "` of `").concat(refKey_2, "`"),
|
|
595
614
|
});
|
|
596
615
|
refT.query.resultProcessors.push(function (r) {
|
|
597
616
|
var val = r.id;
|
|
@@ -622,10 +641,10 @@ function remultGraphql(options) {
|
|
|
622
641
|
// helper
|
|
623
642
|
var it_is_not_at_ref = ref === undefined;
|
|
624
643
|
// where
|
|
625
|
-
if (it_is_not_at_ref && !f.isServerExpression) {
|
|
644
|
+
if (it_is_not_at_ref && !f.isServerExpression && !notARealField) {
|
|
626
645
|
whereTypeFields.push("".concat(f.key, ": Where").concat(type).concat(f.allowNull ? 'Nullable' : ''));
|
|
627
646
|
}
|
|
628
|
-
var includeInUpdateOrInsert = f.options.allowApiUpdate !== false;
|
|
647
|
+
var includeInUpdateOrInsert = f.options.allowApiUpdate !== false && !notARealField;
|
|
629
648
|
var updateType = it_is_not_at_ref ? type : 'ID';
|
|
630
649
|
if (includeInUpdateOrInsert) {
|
|
631
650
|
// create
|
|
@@ -645,9 +664,7 @@ function remultGraphql(options) {
|
|
|
645
664
|
try {
|
|
646
665
|
for (var _s = (e_6 = void 0, tslib_1.__values(meta.fields)), _t = _s.next(); !_t.done; _t = _s.next()) {
|
|
647
666
|
var f = _t.value;
|
|
648
|
-
|
|
649
|
-
if (state_1 === "break")
|
|
650
|
-
break;
|
|
667
|
+
_loop_2(f);
|
|
651
668
|
}
|
|
652
669
|
}
|
|
653
670
|
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
@@ -808,6 +825,55 @@ function remultGraphql(options) {
|
|
|
808
825
|
};
|
|
809
826
|
}
|
|
810
827
|
exports.remultGraphql = remultGraphql;
|
|
828
|
+
function getQueryArgsConnection(key) {
|
|
829
|
+
var queryArgsConnection = [
|
|
830
|
+
{
|
|
831
|
+
key: 'limit',
|
|
832
|
+
value: 'Int',
|
|
833
|
+
comment: "\nFor **page by page** pagination.\nLimit the number of result. \n_Side note: `Math.ceil(totalCount / limit)` to determine how many pages there are._",
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
key: 'page',
|
|
837
|
+
value: 'Int',
|
|
838
|
+
comment: "\nFor **page by page** pagination.\nSelect a dedicated page.",
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
key: 'offset',
|
|
842
|
+
value: 'Int',
|
|
843
|
+
comment: "\nFor **page by page** pagination.\nSet the offset needed.\n_Side node: if `page` arg is set, `offset` will be ignored._",
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
key: 'orderBy',
|
|
847
|
+
value: "".concat(key, "OrderBy"),
|
|
848
|
+
comment: "Remult sorting options",
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
key: 'where',
|
|
852
|
+
value: "".concat(key, "Where"),
|
|
853
|
+
comment: "Remult filtering options",
|
|
854
|
+
},
|
|
855
|
+
];
|
|
856
|
+
if (v2ConnectionAndPagination) {
|
|
857
|
+
queryArgsConnection.push({
|
|
858
|
+
key: 'first',
|
|
859
|
+
value: 'Int',
|
|
860
|
+
comment: "\n For **forward cursor** pagination\n Takes the `first`: `n` elements from the list.",
|
|
861
|
+
}, {
|
|
862
|
+
key: 'after',
|
|
863
|
+
value: 'String',
|
|
864
|
+
comment: "\n For **forward cursor** pagination\n `after` this `cursor`.",
|
|
865
|
+
}, {
|
|
866
|
+
key: 'last',
|
|
867
|
+
value: 'Int',
|
|
868
|
+
comment: "\n For **backward cursor** pagination\n Takes the `last`: `n` elements from the list.",
|
|
869
|
+
}, {
|
|
870
|
+
key: 'before',
|
|
871
|
+
value: 'String',
|
|
872
|
+
comment: "\n For **backward cursor** pagination\n `before` this `cursor`.",
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
return queryArgsConnection;
|
|
876
|
+
}
|
|
811
877
|
// For cursor pagination (v2)
|
|
812
878
|
// function checkPaginationArgs(args: any) {
|
|
813
879
|
// let paginationPage = !!args.limit ? 1 : 0
|
package/package.json
CHANGED
package/src/remult3/remult3.js
CHANGED
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
//p2 - allow find options preprocessor for api calls, to use for authorization
|
|
19
19
|
//p1 - write doc about controlling updates of rows...
|
|
20
20
|
//p1 - need a way to extract the fields from the relation - for generating relation based sql
|
|
21
|
+
//p1 - when doing this, work on graphql relation with fields not just field
|
|
21
22
|
//p1 - add docs for apply changes
|
|
22
23
|
//p1 - when subscribe is forbidden - the query still runs after the renew process
|
|
23
24
|
//p1 - 'update tasks set where id = $1
|
|
@@ -44,14 +45,12 @@ remult.apiClient.url='localhost:3007/api
|
|
|
44
45
|
|
|
45
46
|
|
|
46
47
|
*/
|
|
47
|
-
//p1 - investigate angular starter kit init request error
|
|
48
|
-
//p1 - fix angular starter kit await set password
|
|
49
|
-
//p1 - fix angular starter kit to latest version as well
|
|
50
|
-
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
51
|
-
//p1 - fix multiple instances of remult: the defaultRemult and async local hook - and columnsOfType - all can be tests with a vite project loading `remult-admin`
|
|
52
48
|
//p1 - crm demo graphql error
|
|
49
|
+
//p1 - fix multiple instances of remult: the defaultRemult and async local hook - and columnsOfType - all can be tests with a vite project loading `remult-admin`
|
|
50
|
+
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
53
51
|
//p1 - allow api update only for new rows
|
|
54
52
|
//p1 - getFields didn't work for kobi in the home component
|
|
53
|
+
//p1 - https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
|
|
55
54
|
//p2 - document validators
|
|
56
55
|
//p2 - and validators to reference
|
|
57
56
|
//y2 - discuss a default date formatter
|