remult 0.25.4 → 0.25.5-exp.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/esm/graphql.js +127 -71
- package/esm/src/remult3/remult3.js +2 -0
- package/graphql.d.ts +1 -1
- package/graphql.js +127 -63
- package/package.json +1 -1
- package/src/remult3/remult3.js +2 -0
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,68 +205,7 @@ export function remultGraphql(options) {
|
|
|
205
205
|
}, setResult, arg1, req);
|
|
206
206
|
});
|
|
207
207
|
};
|
|
208
|
-
const queryArgsConnection =
|
|
209
|
-
{
|
|
210
|
-
key: 'limit',
|
|
211
|
-
value: 'Int',
|
|
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
|
-
}
|
|
208
|
+
const queryArgsConnection = getQueryArgsConnection(key);
|
|
270
209
|
const getSingleEntityKey = toCamelCase(getMetaType(meta));
|
|
271
210
|
root_query.fields.push({
|
|
272
211
|
key: getSingleEntityKey,
|
|
@@ -458,9 +397,6 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
458
397
|
for (const f of meta.fields) {
|
|
459
398
|
const ri = getRelationInfo(f.options);
|
|
460
399
|
// let's not consider toMany relations for now
|
|
461
|
-
if (ri?.type === 'toMany') {
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
400
|
if (f.options.includeInApi === false)
|
|
465
401
|
continue;
|
|
466
402
|
let type = 'String';
|
|
@@ -478,11 +414,66 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
478
414
|
}
|
|
479
415
|
break;
|
|
480
416
|
}
|
|
481
|
-
const ref = entities.find((i) => i.entityType === f.valueType);
|
|
482
417
|
currentType.query.resultProcessors.push((r) => {
|
|
483
418
|
r[nodeIdKey] = () => getMetaType(meta) + ':' + meta.idMetadata.getId(r);
|
|
484
419
|
});
|
|
485
|
-
|
|
420
|
+
let ref = entities.find((i) => i.entityType === f.valueType);
|
|
421
|
+
let notARealField = false;
|
|
422
|
+
if (ri) {
|
|
423
|
+
{
|
|
424
|
+
const refType = ri.toType();
|
|
425
|
+
ref = entities.find((i) => i.entityType === refType);
|
|
426
|
+
}
|
|
427
|
+
notARealField = ri.type === 'toOne' || ri.type === 'toMany';
|
|
428
|
+
const refKey = ref.key;
|
|
429
|
+
switch (ri.type) {
|
|
430
|
+
case 'reference':
|
|
431
|
+
case 'toOne':
|
|
432
|
+
currentType.fields.push({
|
|
433
|
+
key: f.key,
|
|
434
|
+
value: `${getMetaType(ref)}${f.allowNull ? '' : '!'}`,
|
|
435
|
+
comment: f.caption,
|
|
436
|
+
});
|
|
437
|
+
currentType.query.resultProcessors.push((r) => {
|
|
438
|
+
const val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
439
|
+
if (val === null || val === undefined)
|
|
440
|
+
return null;
|
|
441
|
+
r[f.key] = async (args, req, gqlInfo) => {
|
|
442
|
+
const queryResult = await (await root[refKey]({
|
|
443
|
+
...args.where,
|
|
444
|
+
where: { id: { eq: val } },
|
|
445
|
+
options: { limit: 1 },
|
|
446
|
+
}, req, gqlInfo)).items();
|
|
447
|
+
if (queryResult.length > 0)
|
|
448
|
+
return queryResult[0];
|
|
449
|
+
return null;
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
break;
|
|
453
|
+
case 'toMany':
|
|
454
|
+
// will do: Category.tasks (actually: Category.tasksOfcategory & tasksOfcategory2)
|
|
455
|
+
currentType.fields.push({
|
|
456
|
+
key: f.key,
|
|
457
|
+
args: getQueryArgsConnection(refKey),
|
|
458
|
+
value: `${getMetaType(ref)}Connection`,
|
|
459
|
+
order: 10,
|
|
460
|
+
comment: `List all \`${getMetaType(meta)}\` of \`${refKey}\``,
|
|
461
|
+
});
|
|
462
|
+
currentType.query.resultProcessors.push((r) => {
|
|
463
|
+
const val = r.id;
|
|
464
|
+
r[f.key] = async (args, req, gqlInfo) => {
|
|
465
|
+
return await root[ref.key]({
|
|
466
|
+
where: {
|
|
467
|
+
...args.where,
|
|
468
|
+
[f.options.field /*//p1 to fix*/]: { eq: val },
|
|
469
|
+
},
|
|
470
|
+
options: { ...args.limit, ...args.page, ...args.orderBy },
|
|
471
|
+
}, req, gqlInfo);
|
|
472
|
+
};
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
else if (ref !== undefined) {
|
|
486
477
|
// will do: Task.category
|
|
487
478
|
currentType.fields.push({
|
|
488
479
|
key: f.key,
|
|
@@ -538,10 +529,10 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
538
529
|
// helper
|
|
539
530
|
const it_is_not_at_ref = ref === undefined;
|
|
540
531
|
// where
|
|
541
|
-
if (it_is_not_at_ref && !f.isServerExpression) {
|
|
532
|
+
if (it_is_not_at_ref && !f.isServerExpression && !notARealField) {
|
|
542
533
|
whereTypeFields.push(`${f.key}: Where${type}${f.allowNull ? 'Nullable' : ''}`);
|
|
543
534
|
}
|
|
544
|
-
const includeInUpdateOrInsert = f.options.allowApiUpdate !== false;
|
|
535
|
+
const includeInUpdateOrInsert = f.options.allowApiUpdate !== false && !notARealField;
|
|
545
536
|
const updateType = it_is_not_at_ref ? type : 'ID';
|
|
546
537
|
if (includeInUpdateOrInsert) {
|
|
547
538
|
// create
|
|
@@ -687,6 +678,71 @@ _Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
|
687
678
|
`,
|
|
688
679
|
};
|
|
689
680
|
}
|
|
681
|
+
function getQueryArgsConnection(key) {
|
|
682
|
+
const queryArgsConnection = [
|
|
683
|
+
{
|
|
684
|
+
key: 'limit',
|
|
685
|
+
value: 'Int',
|
|
686
|
+
comment: `
|
|
687
|
+
For **page by page** pagination.
|
|
688
|
+
Limit the number of result.
|
|
689
|
+
_Side note: \`Math.ceil(totalCount / limit)\` to determine how many pages there are._`,
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
key: 'page',
|
|
693
|
+
value: 'Int',
|
|
694
|
+
comment: `
|
|
695
|
+
For **page by page** pagination.
|
|
696
|
+
Select a dedicated page.`,
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
key: 'offset',
|
|
700
|
+
value: 'Int',
|
|
701
|
+
comment: `
|
|
702
|
+
For **page by page** pagination.
|
|
703
|
+
Set the offset needed.
|
|
704
|
+
_Side node: if \`page\` arg is set, \`offset\` will be ignored._`,
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
key: 'orderBy',
|
|
708
|
+
value: `${key}OrderBy`,
|
|
709
|
+
comment: `Remult sorting options`,
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
key: 'where',
|
|
713
|
+
value: `${key}Where`,
|
|
714
|
+
comment: `Remult filtering options`,
|
|
715
|
+
},
|
|
716
|
+
];
|
|
717
|
+
if (v2ConnectionAndPagination) {
|
|
718
|
+
queryArgsConnection.push({
|
|
719
|
+
key: 'first',
|
|
720
|
+
value: 'Int',
|
|
721
|
+
comment: `
|
|
722
|
+
For **forward cursor** pagination
|
|
723
|
+
Takes the \`first\`: \`n\` elements from the list.`,
|
|
724
|
+
}, {
|
|
725
|
+
key: 'after',
|
|
726
|
+
value: 'String',
|
|
727
|
+
comment: `
|
|
728
|
+
For **forward cursor** pagination
|
|
729
|
+
\`after\` this \`cursor\`.`,
|
|
730
|
+
}, {
|
|
731
|
+
key: 'last',
|
|
732
|
+
value: 'Int',
|
|
733
|
+
comment: `
|
|
734
|
+
For **backward cursor** pagination
|
|
735
|
+
Takes the \`last\`: \`n\` elements from the list.`,
|
|
736
|
+
}, {
|
|
737
|
+
key: 'before',
|
|
738
|
+
value: 'String',
|
|
739
|
+
comment: `
|
|
740
|
+
For **backward cursor** pagination
|
|
741
|
+
\`before\` this \`cursor\`.`,
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
return queryArgsConnection;
|
|
745
|
+
}
|
|
690
746
|
// For cursor pagination (v2)
|
|
691
747
|
// function checkPaginationArgs(args: any) {
|
|
692
748
|
// 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
|
|
@@ -45,6 +46,7 @@ remult.apiClient.url='localhost:3007/api
|
|
|
45
46
|
*/
|
|
46
47
|
//p1 - investigate angular starter kit init request error
|
|
47
48
|
//p1 - fix angular starter kit await set password
|
|
49
|
+
//p1- fix angular starter kit with value list in uitoolsservice
|
|
48
50
|
//p1 - fix angular starter kit to latest version as well
|
|
49
51
|
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
50
52
|
//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`
|
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,52 +262,7 @@ 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));
|
|
309
267
|
root_query.fields.push({
|
|
310
268
|
key: getSingleEntityKey_1,
|
|
@@ -530,9 +488,6 @@ function remultGraphql(options) {
|
|
|
530
488
|
var _loop_2 = function (f) {
|
|
531
489
|
var ri = (0, internals_js_1.getRelationInfo)(f.options);
|
|
532
490
|
// 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
491
|
if (f.options.includeInApi === false)
|
|
537
492
|
return "continue";
|
|
538
493
|
var type = 'String';
|
|
@@ -550,20 +505,82 @@ function remultGraphql(options) {
|
|
|
550
505
|
}
|
|
551
506
|
break;
|
|
552
507
|
}
|
|
553
|
-
var ref = entities.find(function (i) { return i.entityType === f.valueType; });
|
|
554
508
|
currentType.query.resultProcessors.push(function (r) {
|
|
555
509
|
r[nodeIdKey] = function () {
|
|
556
510
|
return getMetaType(meta) + ':' + meta.idMetadata.getId(r);
|
|
557
511
|
};
|
|
558
512
|
});
|
|
559
|
-
|
|
513
|
+
var ref = entities.find(function (i) { return i.entityType === f.valueType; });
|
|
514
|
+
var notARealField = false;
|
|
515
|
+
if (ri) {
|
|
516
|
+
{
|
|
517
|
+
var refType_1 = ri.toType();
|
|
518
|
+
ref = entities.find(function (i) { return i.entityType === refType_1; });
|
|
519
|
+
}
|
|
520
|
+
notARealField = ri.type === 'toOne' || ri.type === 'toMany';
|
|
521
|
+
var refKey_1 = ref.key;
|
|
522
|
+
switch (ri.type) {
|
|
523
|
+
case 'reference':
|
|
524
|
+
case 'toOne':
|
|
525
|
+
currentType.fields.push({
|
|
526
|
+
key: f.key,
|
|
527
|
+
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
528
|
+
comment: f.caption,
|
|
529
|
+
});
|
|
530
|
+
currentType.query.resultProcessors.push(function (r) {
|
|
531
|
+
var val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
532
|
+
if (val === null || val === undefined)
|
|
533
|
+
return null;
|
|
534
|
+
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
535
|
+
var queryResult;
|
|
536
|
+
return tslib_1.__generator(this, function (_a) {
|
|
537
|
+
switch (_a.label) {
|
|
538
|
+
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)];
|
|
539
|
+
case 1: return [4 /*yield*/, (_a.sent()).items()];
|
|
540
|
+
case 2:
|
|
541
|
+
queryResult = _a.sent();
|
|
542
|
+
if (queryResult.length > 0)
|
|
543
|
+
return [2 /*return*/, queryResult[0]];
|
|
544
|
+
return [2 /*return*/, null];
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}); };
|
|
548
|
+
});
|
|
549
|
+
break;
|
|
550
|
+
case 'toMany':
|
|
551
|
+
// will do: Category.tasks (actually: Category.tasksOfcategory & tasksOfcategory2)
|
|
552
|
+
currentType.fields.push({
|
|
553
|
+
key: f.key,
|
|
554
|
+
args: getQueryArgsConnection(refKey_1),
|
|
555
|
+
value: "".concat(getMetaType(ref), "Connection"),
|
|
556
|
+
order: 10,
|
|
557
|
+
comment: "List all `".concat(getMetaType(meta), "` of `").concat(refKey_1, "`"),
|
|
558
|
+
});
|
|
559
|
+
currentType.query.resultProcessors.push(function (r) {
|
|
560
|
+
var val = r.id;
|
|
561
|
+
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
562
|
+
var _a;
|
|
563
|
+
return tslib_1.__generator(this, function (_b) {
|
|
564
|
+
switch (_b.label) {
|
|
565
|
+
case 0: return [4 /*yield*/, root[ref.key]({
|
|
566
|
+
where: tslib_1.__assign(tslib_1.__assign({}, args.where), (_a = {}, _a[f.options.field /*//p1 to fix*/] = { eq: val }, _a)),
|
|
567
|
+
options: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, args.limit), args.page), args.orderBy),
|
|
568
|
+
}, req, gqlInfo)];
|
|
569
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
}); };
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
else if (ref !== undefined) {
|
|
560
577
|
// will do: Task.category
|
|
561
578
|
currentType.fields.push({
|
|
562
579
|
key: f.key,
|
|
563
580
|
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
564
581
|
comment: f.caption,
|
|
565
582
|
});
|
|
566
|
-
var
|
|
583
|
+
var refKey_2 = ref.key;
|
|
567
584
|
currentType.query.resultProcessors.push(function (r) {
|
|
568
585
|
var val = r[f.key];
|
|
569
586
|
if (val === null || val === undefined)
|
|
@@ -572,7 +589,7 @@ function remultGraphql(options) {
|
|
|
572
589
|
var queryResult;
|
|
573
590
|
return tslib_1.__generator(this, function (_a) {
|
|
574
591
|
switch (_a.label) {
|
|
575
|
-
case 0: return [4 /*yield*/, root[
|
|
592
|
+
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
593
|
case 1: return [4 /*yield*/, (_a.sent()).items()];
|
|
577
594
|
case 2:
|
|
578
595
|
queryResult = _a.sent();
|
|
@@ -591,7 +608,7 @@ function remultGraphql(options) {
|
|
|
591
608
|
args: queryArgsConnection,
|
|
592
609
|
value: connectionKey,
|
|
593
610
|
order: 10,
|
|
594
|
-
comment: "List all `".concat(getMetaType(meta), "` of `").concat(
|
|
611
|
+
comment: "List all `".concat(getMetaType(meta), "` of `").concat(refKey_2, "`"),
|
|
595
612
|
});
|
|
596
613
|
refT.query.resultProcessors.push(function (r) {
|
|
597
614
|
var val = r.id;
|
|
@@ -622,10 +639,10 @@ function remultGraphql(options) {
|
|
|
622
639
|
// helper
|
|
623
640
|
var it_is_not_at_ref = ref === undefined;
|
|
624
641
|
// where
|
|
625
|
-
if (it_is_not_at_ref && !f.isServerExpression) {
|
|
642
|
+
if (it_is_not_at_ref && !f.isServerExpression && !notARealField) {
|
|
626
643
|
whereTypeFields.push("".concat(f.key, ": Where").concat(type).concat(f.allowNull ? 'Nullable' : ''));
|
|
627
644
|
}
|
|
628
|
-
var includeInUpdateOrInsert = f.options.allowApiUpdate !== false;
|
|
645
|
+
var includeInUpdateOrInsert = f.options.allowApiUpdate !== false && !notARealField;
|
|
629
646
|
var updateType = it_is_not_at_ref ? type : 'ID';
|
|
630
647
|
if (includeInUpdateOrInsert) {
|
|
631
648
|
// create
|
|
@@ -645,9 +662,7 @@ function remultGraphql(options) {
|
|
|
645
662
|
try {
|
|
646
663
|
for (var _s = (e_6 = void 0, tslib_1.__values(meta.fields)), _t = _s.next(); !_t.done; _t = _s.next()) {
|
|
647
664
|
var f = _t.value;
|
|
648
|
-
|
|
649
|
-
if (state_1 === "break")
|
|
650
|
-
break;
|
|
665
|
+
_loop_2(f);
|
|
651
666
|
}
|
|
652
667
|
}
|
|
653
668
|
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
@@ -808,6 +823,55 @@ function remultGraphql(options) {
|
|
|
808
823
|
};
|
|
809
824
|
}
|
|
810
825
|
exports.remultGraphql = remultGraphql;
|
|
826
|
+
function getQueryArgsConnection(key) {
|
|
827
|
+
var queryArgsConnection = [
|
|
828
|
+
{
|
|
829
|
+
key: 'limit',
|
|
830
|
+
value: 'Int',
|
|
831
|
+
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._",
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
key: 'page',
|
|
835
|
+
value: 'Int',
|
|
836
|
+
comment: "\nFor **page by page** pagination.\nSelect a dedicated page.",
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
key: 'offset',
|
|
840
|
+
value: 'Int',
|
|
841
|
+
comment: "\nFor **page by page** pagination.\nSet the offset needed.\n_Side node: if `page` arg is set, `offset` will be ignored._",
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
key: 'orderBy',
|
|
845
|
+
value: "".concat(key, "OrderBy"),
|
|
846
|
+
comment: "Remult sorting options",
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
key: 'where',
|
|
850
|
+
value: "".concat(key, "Where"),
|
|
851
|
+
comment: "Remult filtering options",
|
|
852
|
+
},
|
|
853
|
+
];
|
|
854
|
+
if (v2ConnectionAndPagination) {
|
|
855
|
+
queryArgsConnection.push({
|
|
856
|
+
key: 'first',
|
|
857
|
+
value: 'Int',
|
|
858
|
+
comment: "\n For **forward cursor** pagination\n Takes the `first`: `n` elements from the list.",
|
|
859
|
+
}, {
|
|
860
|
+
key: 'after',
|
|
861
|
+
value: 'String',
|
|
862
|
+
comment: "\n For **forward cursor** pagination\n `after` this `cursor`.",
|
|
863
|
+
}, {
|
|
864
|
+
key: 'last',
|
|
865
|
+
value: 'Int',
|
|
866
|
+
comment: "\n For **backward cursor** pagination\n Takes the `last`: `n` elements from the list.",
|
|
867
|
+
}, {
|
|
868
|
+
key: 'before',
|
|
869
|
+
value: 'String',
|
|
870
|
+
comment: "\n For **backward cursor** pagination\n `before` this `cursor`.",
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
return queryArgsConnection;
|
|
874
|
+
}
|
|
811
875
|
// For cursor pagination (v2)
|
|
812
876
|
// function checkPaginationArgs(args: any) {
|
|
813
877
|
// 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
|
|
@@ -46,6 +47,7 @@ remult.apiClient.url='localhost:3007/api
|
|
|
46
47
|
*/
|
|
47
48
|
//p1 - investigate angular starter kit init request error
|
|
48
49
|
//p1 - fix angular starter kit await set password
|
|
50
|
+
//p1- fix angular starter kit with value list in uitoolsservice
|
|
49
51
|
//p1 - fix angular starter kit to latest version as well
|
|
50
52
|
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
51
53
|
//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`
|