drizzle-graphql-plus 0.8.6 → 0.8.7

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.
@@ -1,840 +0,0 @@
1
- import {
2
- and,
3
- asc,
4
- desc,
5
- eq,
6
- getTableColumns,
7
- gt,
8
- gte,
9
- ilike,
10
- inArray,
11
- is,
12
- isNotNull,
13
- isNull,
14
- like,
15
- lt,
16
- lte,
17
- ne,
18
- notIlike,
19
- notInArray,
20
- notLike,
21
- One,
22
- or,
23
- SQL,
24
- } from "drizzle-orm";
25
- import {
26
- GraphQLBoolean,
27
- GraphQLEnumType,
28
- GraphQLError,
29
- GraphQLInputObjectType,
30
- GraphQLInt,
31
- GraphQLList,
32
- GraphQLNonNull,
33
- GraphQLObjectType,
34
- GraphQLString,
35
- GraphQLInterfaceType,
36
- } from "graphql";
37
-
38
- import { capitalize } from "@/util/case-ops";
39
- import { remapFromGraphQLCore } from "@/util/data-mappers";
40
- import {
41
- ConvertedColumn,
42
- ConvertedInputColumn,
43
- ConvertedRelationColumnWithArgs,
44
- drizzleColumnToGraphQLType,
45
- } from "@/util/type-converter";
46
-
47
- import type { Column, Table } from "drizzle-orm";
48
- import type { ResolveTree } from "graphql-parse-resolve-info";
49
- import type {
50
- FilterColumnOperators,
51
- FilterColumnOperatorsCore,
52
- Filters,
53
- FiltersCore,
54
- GeneratedTableTypes,
55
- GeneratedTableTypesOutputs,
56
- OrderByArgs,
57
- ProcessedTableSelectArgs,
58
- SelectData,
59
- SelectedColumnsRaw,
60
- SelectedSQLColumns,
61
- TableNamedRelations,
62
- TableSelectArgs,
63
- } from "./types";
64
-
65
- const rqbCrashTypes = ["SQLiteBigInt", "SQLiteBlobJson", "SQLiteBlobBuffer"];
66
-
67
- export const extractSelectedColumnsFromTree = (
68
- tree: Record<string, ResolveTree>,
69
- table: Table
70
- ): Record<string, true> => {
71
- const tableColumns = getTableColumns(table);
72
-
73
- const treeEntries = Object.entries(tree);
74
- const selectedColumns: SelectedColumnsRaw = [];
75
-
76
- for (const [fieldName, fieldData] of treeEntries) {
77
- if (!tableColumns[fieldData.name]) continue;
78
-
79
- selectedColumns.push([fieldData.name, true]);
80
- }
81
-
82
- if (!selectedColumns.length) {
83
- const columnKeys = Object.entries(tableColumns);
84
- const columnName =
85
- columnKeys.find((e) =>
86
- rqbCrashTypes.find((haram) => e[1].columnType !== haram)
87
- )?.[0] ?? columnKeys[0]![0];
88
-
89
- selectedColumns.push([columnName, true]);
90
- }
91
-
92
- return Object.fromEntries(selectedColumns);
93
- };
94
-
95
- /**
96
- * Can't automatically determine column type on type level
97
- * Since drizzle table types extend eachother
98
- */
99
- export const extractSelectedColumnsFromTreeSQLFormat = <
100
- TColType extends Column = Column
101
- >(
102
- tree: Record<string, ResolveTree>,
103
- table: Table
104
- ): Record<string, TColType> => {
105
- const tableColumns = getTableColumns(table);
106
-
107
- const treeEntries = Object.entries(tree);
108
- const selectedColumns: SelectedSQLColumns = [];
109
-
110
- for (const [fieldName, fieldData] of treeEntries) {
111
- if (!tableColumns[fieldData.name]) continue;
112
-
113
- selectedColumns.push([fieldData.name, tableColumns[fieldData.name]!]);
114
- }
115
-
116
- if (!selectedColumns.length) {
117
- const columnKeys = Object.entries(tableColumns);
118
- const columnName =
119
- columnKeys.find((e) =>
120
- rqbCrashTypes.find((haram) => e[1].columnType !== haram)
121
- )?.[0] ?? columnKeys[0]![0];
122
-
123
- selectedColumns.push([columnName, tableColumns[columnName]!]);
124
- }
125
-
126
- return Object.fromEntries(selectedColumns) as Record<string, TColType>;
127
- };
128
-
129
- export const innerOrder = new GraphQLInputObjectType({
130
- name: "InnerOrder" as const,
131
- fields: {
132
- direction: {
133
- type: new GraphQLNonNull(
134
- new GraphQLEnumType({
135
- name: "OrderDirection",
136
- description: "Order by direction",
137
- values: {
138
- asc: {
139
- value: "asc",
140
- description: "Ascending order",
141
- },
142
- desc: {
143
- value: "desc",
144
- description: "Descending order",
145
- },
146
- },
147
- })
148
- ),
149
- },
150
- priority: {
151
- type: new GraphQLNonNull(GraphQLInt),
152
- description: "Priority of current field",
153
- },
154
- } as const,
155
- });
156
-
157
- const generateColumnFilterValues = (
158
- column: Column,
159
- tableName: string,
160
- columnName: string
161
- ): GraphQLInputObjectType => {
162
- const columnGraphQLType = drizzleColumnToGraphQLType(
163
- column,
164
- columnName,
165
- tableName,
166
- true,
167
- false,
168
- true
169
- );
170
- const columnArr = new GraphQLList(new GraphQLNonNull(columnGraphQLType.type));
171
-
172
- const baseFields = {
173
- eq: {
174
- type: columnGraphQLType.type,
175
- description: columnGraphQLType.description,
176
- },
177
- ne: {
178
- type: columnGraphQLType.type,
179
- description: columnGraphQLType.description,
180
- },
181
- lt: {
182
- type: columnGraphQLType.type,
183
- description: columnGraphQLType.description,
184
- },
185
- lte: {
186
- type: columnGraphQLType.type,
187
- description: columnGraphQLType.description,
188
- },
189
- gt: {
190
- type: columnGraphQLType.type,
191
- description: columnGraphQLType.description,
192
- },
193
- gte: {
194
- type: columnGraphQLType.type,
195
- description: columnGraphQLType.description,
196
- },
197
- like: { type: GraphQLString },
198
- notLike: { type: GraphQLString },
199
- ilike: { type: GraphQLString },
200
- notIlike: { type: GraphQLString },
201
- inArray: {
202
- type: columnArr,
203
- description: `Array<${columnGraphQLType.description}>`,
204
- },
205
- notInArray: {
206
- type: columnArr,
207
- description: `Array<${columnGraphQLType.description}>`,
208
- },
209
- isNull: { type: GraphQLBoolean },
210
- isNotNull: { type: GraphQLBoolean },
211
- };
212
-
213
- const type: GraphQLInputObjectType = new GraphQLInputObjectType({
214
- name: `${capitalize(tableName)}${capitalize(columnName)}Filters`,
215
- fields: {
216
- ...baseFields,
217
- OR: {
218
- type: new GraphQLList(
219
- new GraphQLNonNull(
220
- new GraphQLInputObjectType({
221
- name: `${capitalize(tableName)}${capitalize(
222
- columnName
223
- )}filtersOr`,
224
- fields: {
225
- ...baseFields,
226
- },
227
- })
228
- )
229
- ),
230
- },
231
- },
232
- });
233
-
234
- return type;
235
- };
236
-
237
- const orderMap = new WeakMap<Object, Record<string, ConvertedInputColumn>>();
238
- const generateTableOrderCached = (table: Table) => {
239
- if (orderMap.has(table)) return orderMap.get(table)!;
240
-
241
- const columns = getTableColumns(table);
242
- const columnEntries = Object.entries(columns);
243
-
244
- const remapped = Object.fromEntries(
245
- columnEntries.map(([columnName, columnDescription]) => [
246
- columnName,
247
- { type: innerOrder },
248
- ])
249
- );
250
-
251
- orderMap.set(table, remapped);
252
-
253
- return remapped;
254
- };
255
-
256
- const filterMap = new WeakMap<Object, Record<string, ConvertedInputColumn>>();
257
- const generateTableFilterValuesCached = (table: Table, tableName: string) => {
258
- if (filterMap.has(table)) return filterMap.get(table)!;
259
-
260
- const columns = getTableColumns(table);
261
- const columnEntries = Object.entries(columns);
262
-
263
- const remapped = Object.fromEntries(
264
- columnEntries.map(([columnName, columnDescription]) => [
265
- columnName,
266
- {
267
- type: generateColumnFilterValues(
268
- columnDescription,
269
- tableName,
270
- columnName
271
- ),
272
- },
273
- ])
274
- );
275
-
276
- filterMap.set(table, remapped);
277
-
278
- return remapped;
279
- };
280
-
281
- const fieldMap = new WeakMap<Object, Record<string, ConvertedColumn>>();
282
- const generateTableSelectTypeFieldsCached = (
283
- table: Table,
284
- tableName: string
285
- ): Record<string, ConvertedColumn> => {
286
- if (fieldMap.has(table)) return fieldMap.get(table)!;
287
-
288
- const columns = getTableColumns(table);
289
- const columnEntries = Object.entries(columns);
290
-
291
- const remapped = Object.fromEntries(
292
- columnEntries.map(([columnName, columnDescription]) => [
293
- columnName,
294
- drizzleColumnToGraphQLType(columnDescription, columnName, tableName),
295
- ])
296
- );
297
-
298
- fieldMap.set(table, remapped);
299
-
300
- return remapped;
301
- };
302
-
303
- const orderTypeMap = new WeakMap<Object, GraphQLInputObjectType>();
304
- const generateTableOrderTypeCached = (table: Table, tableName: string) => {
305
- if (orderTypeMap.has(table)) return orderTypeMap.get(table)!;
306
-
307
- const orderColumns = generateTableOrderCached(table);
308
- const order = new GraphQLInputObjectType({
309
- name: `${capitalize(tableName)}OrderBy`,
310
- fields: orderColumns,
311
- });
312
-
313
- orderTypeMap.set(table, order);
314
-
315
- return order;
316
- };
317
-
318
- const filterTypeMap = new WeakMap<Object, GraphQLInputObjectType>();
319
- const generateTableFilterTypeCached = (table: Table, tableName: string) => {
320
- if (filterTypeMap.has(table)) return filterTypeMap.get(table)!;
321
-
322
- const filterColumns = generateTableFilterValuesCached(table, tableName);
323
- const filters: GraphQLInputObjectType = new GraphQLInputObjectType({
324
- name: `${capitalize(tableName)}Filters`,
325
- fields: {
326
- ...filterColumns,
327
- OR: {
328
- type: new GraphQLList(
329
- new GraphQLNonNull(
330
- new GraphQLInputObjectType({
331
- name: `${capitalize(tableName)}FiltersOr`,
332
- fields: filterColumns,
333
- })
334
- )
335
- ),
336
- },
337
- },
338
- });
339
-
340
- filterTypeMap.set(table, filters);
341
-
342
- return filters;
343
- };
344
-
345
- const generateSelectFields = <TWithOrder extends boolean>(
346
- tables: Record<string, Table>,
347
- tableName: string,
348
- relationMap: Record<string, Record<string, TableNamedRelations>>,
349
- typeName: string,
350
- withOrder: TWithOrder,
351
- relationsDepthLimit: number | undefined,
352
- currentDepth: number = 0,
353
- usedTables: Set<string> = new Set()
354
- ): SelectData<TWithOrder> => {
355
- const relations = relationMap[tableName];
356
- const relationEntries: [string, TableNamedRelations][] = relations
357
- ? Object.entries(relations)
358
- : [];
359
-
360
- const table = tables[tableName]!;
361
-
362
- const order = withOrder
363
- ? generateTableOrderTypeCached(table, tableName)
364
- : undefined;
365
-
366
- const filters = generateTableFilterTypeCached(table, tableName);
367
-
368
- const tableFields = generateTableSelectTypeFieldsCached(table, tableName);
369
-
370
- if (
371
- usedTables.has(tableName) ||
372
- (typeof relationsDepthLimit === "number" &&
373
- currentDepth >= relationsDepthLimit) ||
374
- !relationEntries.length
375
- ) {
376
- return {
377
- order,
378
- filters,
379
- tableFields,
380
- relationFields: {},
381
- } as SelectData<TWithOrder>;
382
- }
383
-
384
- const rawRelationFields: [string, ConvertedRelationColumnWithArgs][] = [];
385
- const updatedUsedTables = new Set(usedTables).add(tableName);
386
- const newDepth = currentDepth + 1;
387
-
388
- for (const [relationName, { targetTableName, relation }] of relationEntries) {
389
- const relTypeName = `${typeName}${capitalize(relationName)}Relation`;
390
- const isOne = is(relation, One);
391
-
392
- const relData = generateSelectFields(
393
- tables,
394
- targetTableName,
395
- relationMap,
396
- relTypeName,
397
- !isOne,
398
- relationsDepthLimit,
399
- newDepth,
400
- updatedUsedTables
401
- );
402
-
403
- const relType = new GraphQLObjectType({
404
- name: relTypeName,
405
- fields: { ...relData.tableFields, ...relData.relationFields },
406
- });
407
-
408
- if (isOne) {
409
- rawRelationFields.push([
410
- relationName,
411
- {
412
- type: relType,
413
- args: {
414
- where: { type: relData.filters },
415
- },
416
- },
417
- ]);
418
-
419
- continue;
420
- }
421
-
422
- rawRelationFields.push([
423
- relationName,
424
- {
425
- type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(relType))),
426
- args: {
427
- where: { type: relData.filters },
428
- orderBy: { type: relData.order! },
429
- offset: { type: GraphQLInt },
430
- limit: { type: GraphQLInt },
431
- },
432
- },
433
- ]);
434
- }
435
-
436
- const relationFields = Object.fromEntries(rawRelationFields);
437
-
438
- return {
439
- order,
440
- filters,
441
- tableFields,
442
- relationFields,
443
- } as SelectData<TWithOrder>;
444
- };
445
-
446
- export const generateTableTypes = <WithReturning extends boolean>(
447
- tableName: string,
448
- tables: Record<string, Table>,
449
- relationMap: Record<string, Record<string, TableNamedRelations>>,
450
- withReturning: WithReturning,
451
- relationsDepthLimit: number | undefined
452
- ): GeneratedTableTypes<WithReturning> => {
453
- const stylizedName = capitalize(tableName);
454
- const { tableFields, relationFields, filters, order } = generateSelectFields(
455
- tables,
456
- tableName,
457
- relationMap,
458
- stylizedName,
459
- true,
460
- relationsDepthLimit
461
- );
462
-
463
- const table = tables[tableName]!;
464
- const columns = getTableColumns(table);
465
- const columnEntries = Object.entries(columns);
466
-
467
- const insertFields = Object.fromEntries(
468
- columnEntries.map(([columnName, columnDescription]) => [
469
- columnName,
470
- drizzleColumnToGraphQLType(
471
- columnDescription,
472
- columnName,
473
- tableName,
474
- false,
475
- true,
476
- true
477
- ),
478
- ])
479
- );
480
-
481
- const updateFields = Object.fromEntries(
482
- columnEntries.map(([columnName, columnDescription]) => [
483
- columnName,
484
- drizzleColumnToGraphQLType(
485
- columnDescription,
486
- columnName,
487
- tableName,
488
- true,
489
- false,
490
- true
491
- ),
492
- ])
493
- );
494
-
495
- const insertInput = new GraphQLInputObjectType({
496
- name: `${stylizedName}InsertInput`,
497
- fields: insertFields,
498
- });
499
-
500
- const tableFieldsInterface = new GraphQLInterfaceType({
501
- name: `${stylizedName}Fields`,
502
- fields: tableFields,
503
- });
504
-
505
- const selectSingleOutput = new GraphQLObjectType({
506
- name: `${stylizedName}SelectItem`,
507
- fields: { ...tableFields, ...relationFields },
508
- interfaces: [tableFieldsInterface],
509
- });
510
-
511
- const selectArrOutput = new GraphQLNonNull(
512
- new GraphQLList(new GraphQLNonNull(selectSingleOutput))
513
- );
514
-
515
- const singleTableItemOutput = withReturning
516
- ? new GraphQLObjectType({
517
- name: `${stylizedName}Item`,
518
- fields: tableFields,
519
- interfaces: [tableFieldsInterface],
520
- })
521
- : undefined;
522
-
523
- const arrTableItemOutput = withReturning
524
- ? new GraphQLNonNull(
525
- new GraphQLList(new GraphQLNonNull(singleTableItemOutput!))
526
- )
527
- : undefined;
528
-
529
- const updateInput = new GraphQLInputObjectType({
530
- name: `${stylizedName}UpdateInput`,
531
- fields: updateFields,
532
- });
533
-
534
- const inputs = {
535
- insertInput,
536
- updateInput,
537
- tableOrder: order,
538
- tableFilters: filters,
539
- };
540
-
541
- const outputs = (
542
- withReturning
543
- ? {
544
- selectSingleOutput,
545
- selectArrOutput,
546
- singleTableItemOutput: singleTableItemOutput!,
547
- arrTableItemOutput: arrTableItemOutput!,
548
- }
549
- : {
550
- selectSingleOutput,
551
- selectArrOutput,
552
- }
553
- ) as GeneratedTableTypesOutputs<WithReturning>;
554
-
555
- return {
556
- inputs,
557
- outputs,
558
- };
559
- };
560
-
561
- export const extractOrderBy = <
562
- TTable extends Table,
563
- TArgs extends OrderByArgs<any> = OrderByArgs<TTable>
564
- >(
565
- table: TTable,
566
- orderArgs: TArgs
567
- ): SQL[] => {
568
- const res = [] as SQL[];
569
-
570
- for (const [column, config] of Object.entries(orderArgs).sort(
571
- (a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0)
572
- )) {
573
- if (!config) continue;
574
- const { direction } = config;
575
-
576
- res.push(
577
- direction === "asc"
578
- ? asc(getTableColumns(table)[column]!)
579
- : desc(getTableColumns(table)[column]!)
580
- );
581
- }
582
-
583
- return res;
584
- };
585
-
586
- export const extractFiltersColumn = <TColumn extends Column>(
587
- column: TColumn,
588
- columnName: string,
589
- operators: FilterColumnOperators<TColumn>
590
- ): SQL | undefined => {
591
- if (!operators.OR?.length) delete operators.OR;
592
-
593
- const entries = Object.entries(
594
- operators as FilterColumnOperatorsCore<TColumn>
595
- );
596
-
597
- if (operators.OR) {
598
- if (entries.length > 1) {
599
- throw new GraphQLError(
600
- `WHERE ${columnName}: Cannot specify both fields and 'OR' in column operators!`
601
- );
602
- }
603
-
604
- const variants = [] as SQL[];
605
-
606
- for (const variant of operators.OR) {
607
- const extracted = extractFiltersColumn(column, columnName, variant);
608
-
609
- if (extracted) variants.push(extracted);
610
- }
611
-
612
- return variants.length
613
- ? variants.length > 1
614
- ? or(...variants)
615
- : variants[0]
616
- : undefined;
617
- }
618
-
619
- const variants = [] as SQL[];
620
- for (const [operatorName, operatorValue] of entries) {
621
- if (operatorValue === null || operatorValue === false) continue;
622
-
623
- let operator: ((...args: any[]) => SQL) | undefined;
624
- switch (operatorName as keyof FilterColumnOperatorsCore<TColumn>) {
625
- // @ts-ignore
626
- case "eq":
627
- operator = operator ?? eq;
628
- // @ts-ignore
629
- case "ne":
630
- operator = operator ?? ne;
631
- // @ts-ignore
632
- case "gt":
633
- operator = operator ?? gt;
634
- // @ts-ignore
635
- case "gte":
636
- operator = operator ?? gte;
637
- // @ts-ignore
638
- case "lt":
639
- operator = operator ?? lt;
640
- case "lte":
641
- operator = operator ?? lte;
642
-
643
- const singleValue = remapFromGraphQLCore(
644
- operatorValue,
645
- column,
646
- columnName
647
- );
648
- variants.push(operator(column, singleValue));
649
-
650
- break;
651
-
652
- // @ts-ignore
653
- case "like":
654
- operator = operator ?? like;
655
- // @ts-ignore
656
- case "notLike":
657
- operator = operator ?? notLike;
658
- // @ts-ignore
659
- case "ilike":
660
- operator = operator ?? ilike;
661
- case "notIlike":
662
- operator = operator ?? notIlike;
663
-
664
- variants.push(operator(column, operatorValue as string));
665
-
666
- break;
667
-
668
- // @ts-ignore
669
- case "inArray":
670
- operator = operator ?? inArray;
671
- case "notInArray":
672
- operator = operator ?? notInArray;
673
-
674
- if (!(operatorValue as any[]).length) {
675
- throw new GraphQLError(
676
- `WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`
677
- );
678
- }
679
- const arrayValue = (operatorValue as any[]).map((val) =>
680
- remapFromGraphQLCore(val, column, columnName)
681
- );
682
-
683
- variants.push(operator(column, arrayValue));
684
- break;
685
-
686
- // @ts-ignore
687
- case "isNull":
688
- operator = operator ?? isNull;
689
- case "isNotNull":
690
- operator = operator ?? isNotNull;
691
-
692
- variants.push(operator(column));
693
- }
694
- }
695
-
696
- return variants.length
697
- ? variants.length > 1
698
- ? and(...variants)
699
- : variants[0]
700
- : undefined;
701
- };
702
-
703
- export const extractFilters = <TTable extends Table>(
704
- table: TTable,
705
- tableName: string,
706
- filters: Filters<TTable>
707
- ): SQL | undefined => {
708
- if (!filters.OR?.length) delete filters.OR;
709
-
710
- const entries = Object.entries(filters as FiltersCore<TTable>);
711
- if (!entries.length) return;
712
-
713
- if (filters.OR) {
714
- if (entries.length > 1) {
715
- throw new GraphQLError(
716
- `WHERE ${tableName}: Cannot specify both fields and 'OR' in table filters!`
717
- );
718
- }
719
-
720
- const variants = [] as SQL[];
721
-
722
- for (const variant of filters.OR) {
723
- const extracted = extractFilters(table, tableName, variant);
724
- if (extracted) variants.push(extracted);
725
- }
726
-
727
- return variants.length
728
- ? variants.length > 1
729
- ? or(...variants)
730
- : variants[0]
731
- : undefined;
732
- }
733
-
734
- const variants = [] as SQL[];
735
- for (const [columnName, operators] of entries) {
736
- if (operators === null) continue;
737
-
738
- const column = getTableColumns(table)[columnName]!;
739
- variants.push(extractFiltersColumn(column, columnName, operators)!);
740
- }
741
-
742
- return variants.length
743
- ? variants.length > 1
744
- ? and(...variants)
745
- : variants[0]
746
- : undefined;
747
- };
748
-
749
- const extractRelationsParamsInner = (
750
- relationMap: Record<string, Record<string, TableNamedRelations>>,
751
- tables: Record<string, Table>,
752
- tableName: string,
753
- typeName: string,
754
- originField: ResolveTree,
755
- isInitial: boolean = false
756
- ) => {
757
- const relations = relationMap[tableName];
758
- if (!relations) return undefined;
759
-
760
- const baseField = Object.entries(originField.fieldsByTypeName).find(
761
- ([key, value]) => key === typeName
762
- )?.[1];
763
- if (!baseField) return undefined;
764
-
765
- const args: Record<string, Partial<ProcessedTableSelectArgs>> = {};
766
-
767
- for (const [relName, { targetTableName, relation }] of Object.entries(
768
- relations
769
- )) {
770
- const relTypeName = `${
771
- isInitial ? capitalize(tableName) : typeName
772
- }${capitalize(relName)}Relation`;
773
- const relFieldSelection = Object.values(baseField).find(
774
- (field) => field.name === relName
775
- )?.fieldsByTypeName[relTypeName];
776
- if (!relFieldSelection) continue;
777
-
778
- const columns = extractSelectedColumnsFromTree(
779
- relFieldSelection,
780
- tables[targetTableName]!
781
- );
782
-
783
- const thisRecord: Partial<ProcessedTableSelectArgs> = {};
784
- thisRecord.columns = columns;
785
-
786
- const relationField = Object.values(baseField).find(
787
- (e) => e.name === relName
788
- );
789
- const relationArgs: Partial<TableSelectArgs> | undefined =
790
- relationField?.args;
791
-
792
- const orderBy = relationArgs?.orderBy
793
- ? extractOrderBy(tables[targetTableName]!, relationArgs.orderBy!)
794
- : undefined;
795
- const where = relationArgs?.where
796
- ? extractFilters(tables[targetTableName]!, relName, relationArgs?.where)
797
- : undefined;
798
- const offset = relationArgs?.offset ?? undefined;
799
- const limit = relationArgs?.limit ?? undefined;
800
-
801
- thisRecord.orderBy = orderBy;
802
- thisRecord.where = where;
803
- thisRecord.offset = offset;
804
- thisRecord.limit = limit;
805
-
806
- const relWith = relationField
807
- ? extractRelationsParamsInner(
808
- relationMap,
809
- tables,
810
- targetTableName,
811
- relTypeName,
812
- relationField
813
- )
814
- : undefined;
815
- thisRecord.with = relWith;
816
-
817
- args[relName] = thisRecord;
818
- }
819
-
820
- return args;
821
- };
822
-
823
- export const extractRelationsParams = (
824
- relationMap: Record<string, Record<string, TableNamedRelations>>,
825
- tables: Record<string, Table>,
826
- tableName: string,
827
- info: ResolveTree | undefined,
828
- typeName: string
829
- ): Record<string, Partial<ProcessedTableSelectArgs>> | undefined => {
830
- if (!info) return undefined;
831
-
832
- return extractRelationsParamsInner(
833
- relationMap,
834
- tables,
835
- tableName,
836
- typeName,
837
- info,
838
- true
839
- );
840
- };