@pothos/plugin-drizzle 0.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.
Files changed (179) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +6 -0
  3. package/README.md +437 -0
  4. package/TODO.md +21 -0
  5. package/drizzle/meta/_journal.json +1 -0
  6. package/drizzle.config.ts +10 -0
  7. package/dts/drizzle-field-builder.d.ts +124 -0
  8. package/dts/drizzle-field-builder.d.ts.map +1 -0
  9. package/dts/field-builder.d.ts +2 -0
  10. package/dts/field-builder.d.ts.map +1 -0
  11. package/dts/global-types.d.ts +92 -0
  12. package/dts/global-types.d.ts.map +1 -0
  13. package/dts/index.d.ts +13 -0
  14. package/dts/index.d.ts.map +1 -0
  15. package/dts/interface-ref.d.ts +9 -0
  16. package/dts/interface-ref.d.ts.map +1 -0
  17. package/dts/model-loader.d.ts +44 -0
  18. package/dts/model-loader.d.ts.map +1 -0
  19. package/dts/node-ref.d.ts +5 -0
  20. package/dts/node-ref.d.ts.map +1 -0
  21. package/dts/object-ref.d.ts +14 -0
  22. package/dts/object-ref.d.ts.map +1 -0
  23. package/dts/schema-builder.d.ts +2 -0
  24. package/dts/schema-builder.d.ts.map +1 -0
  25. package/dts/types.d.ts +147 -0
  26. package/dts/types.d.ts.map +1 -0
  27. package/dts/utils/config.d.ts +7 -0
  28. package/dts/utils/config.d.ts.map +1 -0
  29. package/dts/utils/cursors.d.ts +58 -0
  30. package/dts/utils/cursors.d.ts.map +1 -0
  31. package/dts/utils/deep-equal.d.ts +2 -0
  32. package/dts/utils/deep-equal.d.ts.map +1 -0
  33. package/dts/utils/drizzle-graphql.d.ts +18 -0
  34. package/dts/utils/drizzle-graphql.d.ts.map +1 -0
  35. package/dts/utils/loader-map.d.ts +11 -0
  36. package/dts/utils/loader-map.d.ts.map +1 -0
  37. package/dts/utils/map-query.d.ts +30 -0
  38. package/dts/utils/map-query.d.ts.map +1 -0
  39. package/dts/utils/refs.d.ts +5 -0
  40. package/dts/utils/refs.d.ts.map +1 -0
  41. package/dts/utils/selections.d.ts +22 -0
  42. package/dts/utils/selections.d.ts.map +1 -0
  43. package/dts/utils/usage.d.ts +5 -0
  44. package/dts/utils/usage.d.ts.map +1 -0
  45. package/esm/drizzle-field-builder.d.ts +216 -0
  46. package/esm/drizzle-field-builder.d.ts.map +1 -0
  47. package/esm/field-builder.d.ts +2 -0
  48. package/esm/field-builder.d.ts.map +1 -0
  49. package/esm/global-types.d.ts +124 -0
  50. package/esm/global-types.d.ts.map +1 -0
  51. package/esm/index.d.ts +13 -0
  52. package/esm/index.d.ts.map +1 -0
  53. package/esm/interface-ref.d.ts +9 -0
  54. package/esm/interface-ref.d.ts.map +1 -0
  55. package/esm/model-loader.d.ts +45 -0
  56. package/esm/model-loader.d.ts.map +1 -0
  57. package/esm/node-ref.d.ts +5 -0
  58. package/esm/node-ref.d.ts.map +1 -0
  59. package/esm/object-ref.d.ts +14 -0
  60. package/esm/object-ref.d.ts.map +1 -0
  61. package/esm/package.json +3 -0
  62. package/esm/schema-builder.d.ts +2 -0
  63. package/esm/schema-builder.d.ts.map +1 -0
  64. package/esm/src/drizzle-field-builder.js +215 -0
  65. package/esm/src/drizzle-field-builder.js.map +1 -0
  66. package/esm/src/field-builder.js +77 -0
  67. package/esm/src/field-builder.js.map +1 -0
  68. package/esm/src/global-types.js +2 -0
  69. package/esm/src/global-types.js.map +1 -0
  70. package/esm/src/index.js +107 -0
  71. package/esm/src/index.js.map +1 -0
  72. package/esm/src/interface-ref.js +26 -0
  73. package/esm/src/interface-ref.js.map +1 -0
  74. package/esm/src/model-loader.js +168 -0
  75. package/esm/src/model-loader.js.map +1 -0
  76. package/esm/src/node-ref.js +4 -0
  77. package/esm/src/node-ref.js.map +1 -0
  78. package/esm/src/object-ref.js +38 -0
  79. package/esm/src/object-ref.js.map +1 -0
  80. package/esm/src/schema-builder.js +190 -0
  81. package/esm/src/schema-builder.js.map +1 -0
  82. package/esm/src/types.js +2 -0
  83. package/esm/src/types.js.map +1 -0
  84. package/esm/src/utils/config.js +15 -0
  85. package/esm/src/utils/config.js.map +1 -0
  86. package/esm/src/utils/cursors.js +316 -0
  87. package/esm/src/utils/cursors.js.map +1 -0
  88. package/esm/src/utils/deep-equal.js +44 -0
  89. package/esm/src/utils/deep-equal.js.map +1 -0
  90. package/esm/src/utils/drizzle-graphql.js +176 -0
  91. package/esm/src/utils/drizzle-graphql.js.map +1 -0
  92. package/esm/src/utils/loader-map.js +35 -0
  93. package/esm/src/utils/loader-map.js.map +1 -0
  94. package/esm/src/utils/map-query.js +284 -0
  95. package/esm/src/utils/map-query.js.map +1 -0
  96. package/esm/src/utils/refs.js +14 -0
  97. package/esm/src/utils/refs.js.map +1 -0
  98. package/esm/src/utils/selections.js +136 -0
  99. package/esm/src/utils/selections.js.map +1 -0
  100. package/esm/src/utils/usage.js +59 -0
  101. package/esm/src/utils/usage.js.map +1 -0
  102. package/esm/types.d.ts +161 -0
  103. package/esm/types.d.ts.map +1 -0
  104. package/esm/utils/config.d.ts +7 -0
  105. package/esm/utils/config.d.ts.map +1 -0
  106. package/esm/utils/cursors.d.ts +58 -0
  107. package/esm/utils/cursors.d.ts.map +1 -0
  108. package/esm/utils/deep-equal.d.ts +2 -0
  109. package/esm/utils/deep-equal.d.ts.map +1 -0
  110. package/esm/utils/drizzle-graphql.d.ts +18 -0
  111. package/esm/utils/drizzle-graphql.d.ts.map +1 -0
  112. package/esm/utils/loader-map.d.ts +11 -0
  113. package/esm/utils/loader-map.d.ts.map +1 -0
  114. package/esm/utils/map-query.d.ts +30 -0
  115. package/esm/utils/map-query.d.ts.map +1 -0
  116. package/esm/utils/refs.d.ts +5 -0
  117. package/esm/utils/refs.d.ts.map +1 -0
  118. package/esm/utils/selections.d.ts +22 -0
  119. package/esm/utils/selections.d.ts.map +1 -0
  120. package/esm/utils/usage.d.ts +5 -0
  121. package/esm/utils/usage.d.ts.map +1 -0
  122. package/lib/src/drizzle-field-builder.js +225 -0
  123. package/lib/src/drizzle-field-builder.js.map +1 -0
  124. package/lib/src/field-builder.js +82 -0
  125. package/lib/src/field-builder.js.map +1 -0
  126. package/lib/src/global-types.js +6 -0
  127. package/lib/src/global-types.js.map +1 -0
  128. package/lib/src/index.js +180 -0
  129. package/lib/src/index.js.map +1 -0
  130. package/lib/src/interface-ref.js +36 -0
  131. package/lib/src/interface-ref.js.map +1 -0
  132. package/lib/src/model-loader.js +176 -0
  133. package/lib/src/model-loader.js.map +1 -0
  134. package/lib/src/node-ref.js +15 -0
  135. package/lib/src/node-ref.js.map +1 -0
  136. package/lib/src/object-ref.js +56 -0
  137. package/lib/src/object-ref.js.map +1 -0
  138. package/lib/src/schema-builder.js +236 -0
  139. package/lib/src/schema-builder.js.map +1 -0
  140. package/lib/src/types.js +13 -0
  141. package/lib/src/types.js.map +1 -0
  142. package/lib/src/utils/config.js +26 -0
  143. package/lib/src/utils/config.js.map +1 -0
  144. package/lib/src/utils/cursors.js +362 -0
  145. package/lib/src/utils/cursors.js.map +1 -0
  146. package/lib/src/utils/deep-equal.js +55 -0
  147. package/lib/src/utils/deep-equal.js.map +1 -0
  148. package/lib/src/utils/drizzle-graphql.js +192 -0
  149. package/lib/src/utils/drizzle-graphql.js.map +1 -0
  150. package/lib/src/utils/loader-map.js +57 -0
  151. package/lib/src/utils/loader-map.js.map +1 -0
  152. package/lib/src/utils/map-query.js +308 -0
  153. package/lib/src/utils/map-query.js.map +1 -0
  154. package/lib/src/utils/refs.js +33 -0
  155. package/lib/src/utils/refs.js.map +1 -0
  156. package/lib/src/utils/selections.js +163 -0
  157. package/lib/src/utils/selections.js.map +1 -0
  158. package/lib/src/utils/usage.js +84 -0
  159. package/lib/src/utils/usage.js.map +1 -0
  160. package/package.json +66 -0
  161. package/src/drizzle-field-builder.ts +500 -0
  162. package/src/field-builder.ts +168 -0
  163. package/src/global-types.ts +481 -0
  164. package/src/index.ts +175 -0
  165. package/src/interface-ref.ts +24 -0
  166. package/src/model-loader.ts +235 -0
  167. package/src/node-ref.ts +8 -0
  168. package/src/object-ref.ts +51 -0
  169. package/src/schema-builder.ts +299 -0
  170. package/src/types.ts +640 -0
  171. package/src/utils/config.ts +28 -0
  172. package/src/utils/cursors.ts +446 -0
  173. package/src/utils/deep-equal.ts +58 -0
  174. package/src/utils/drizzle-graphql.ts +235 -0
  175. package/src/utils/loader-map.ts +51 -0
  176. package/src/utils/map-query.ts +582 -0
  177. package/src/utils/refs.ts +25 -0
  178. package/src/utils/selections.ts +209 -0
  179. package/src/utils/usage.ts +64 -0
@@ -0,0 +1,446 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ import {
3
+ decodeBase64,
4
+ encodeBase64,
5
+ MaybePromise,
6
+ PothosValidationError,
7
+ SchemaTypes,
8
+ } from '@pothos/core';
9
+ import {
10
+ Column,
11
+ getOperators,
12
+ getOrderByOperators,
13
+ RelationalSchemaConfig,
14
+ SQL,
15
+ TableRelationalConfig,
16
+ TablesRelationalConfig,
17
+ } from 'drizzle-orm';
18
+ import { ConnectionOrderBy, QueryForDrizzleConnection } from '../types';
19
+ import { SelectionMap } from './selections';
20
+ import { GraphQLResolveInfo } from 'graphql';
21
+ import { queryFromInfo } from './map-query';
22
+ import { PothosDrizzleSchemaConfig } from './config';
23
+
24
+ const DEFAULT_MAX_SIZE = 100;
25
+ const DEFAULT_SIZE = 20;
26
+
27
+ export function formatCursorChunk(value: unknown) {
28
+ if (value instanceof Date) {
29
+ return `D:${String(Number(value))}`;
30
+ }
31
+
32
+ switch (typeof value) {
33
+ case 'number':
34
+ return `N:${value}`;
35
+ case 'string':
36
+ return `S:${value}`;
37
+ case 'bigint':
38
+ return `I:${value}`;
39
+ default:
40
+ throw new PothosValidationError(`Unsupported cursor type ${typeof value}`);
41
+ }
42
+ }
43
+
44
+ export function formatDrizzleCursor(record: Record<string, unknown>, fields: Column[]) {
45
+ return getCursorFormatter(fields)(record);
46
+ }
47
+
48
+ export function getColumnSerializer(fields: Column[]) {
49
+ if (fields.length === 0) {
50
+ throw new PothosValidationError('Column serializer must have at least one field');
51
+ }
52
+
53
+ return (value: Record<string, unknown>) => {
54
+ if (fields.length > 1) {
55
+ return `J:${JSON.stringify(fields.map((col) => value[col.name]))}`;
56
+ }
57
+
58
+ return `${formatCursorChunk(value[fields[0].name])}`;
59
+ };
60
+ }
61
+
62
+ export function getCursorFormatter(fields: Column[]) {
63
+ if (fields.length === 0) {
64
+ throw new PothosValidationError('Cursor must have at least one field');
65
+ }
66
+
67
+ const serializer = getColumnSerializer(fields);
68
+
69
+ return (value: Record<string, unknown>) => {
70
+ return encodeBase64(`DC:${serializer(value)}`);
71
+ };
72
+ }
73
+
74
+ export function parseDrizzleCursor(cursor: unknown) {
75
+ if (typeof cursor !== 'string') {
76
+ throw new PothosValidationError('Cursor must be a string');
77
+ }
78
+
79
+ try {
80
+ const decoded = decodeBase64(cursor);
81
+ if (!decoded.startsWith('DC:')) {
82
+ throw new PothosValidationError('Invalid cursor');
83
+ }
84
+
85
+ return parseSerializedDrizzleColumn(decoded.slice(3));
86
+ } catch {
87
+ throw new PothosValidationError(`Invalid cursor: ${cursor}`);
88
+ }
89
+ }
90
+
91
+ export function parseSerializedDrizzleColumn(value: unknown) {
92
+ if (typeof value !== 'string') {
93
+ throw new PothosValidationError('value must be a string');
94
+ }
95
+
96
+ try {
97
+ const [, type, rawValue] = value.match(/^(S|N|D|J|I):(.*)/) as [string, string, string];
98
+
99
+ switch (type) {
100
+ case 'S':
101
+ return rawValue;
102
+ case 'N':
103
+ return Number.parseInt(rawValue, 10);
104
+ case 'D':
105
+ return new Date(Number.parseInt(rawValue, 10));
106
+ case 'J':
107
+ return JSON.parse(rawValue) as unknown;
108
+ case 'I':
109
+ return BigInt(rawValue);
110
+ default:
111
+ throw new PothosValidationError(`Invalid cursor type ${type}`);
112
+ }
113
+ } catch {
114
+ throw new PothosValidationError(`Invalid serialized data: ${value}`);
115
+ }
116
+ }
117
+
118
+ export function parseID(id: string, dataType: string): unknown {
119
+ if (!id) {
120
+ return id;
121
+ }
122
+
123
+ switch (dataType) {
124
+ case 'String':
125
+ return id;
126
+ case 'Int':
127
+ return Number.parseInt(id, 10);
128
+ case 'BigInt':
129
+ return BigInt(id);
130
+ case 'Boolean':
131
+ return id !== 'false';
132
+ case 'Float':
133
+ case 'Decimal':
134
+ return Number.parseFloat(id);
135
+ case 'DateTime':
136
+ return new Date(id);
137
+ case 'Json':
138
+ return JSON.parse(id) as unknown;
139
+ case 'Byte':
140
+ return Buffer.from(id, 'base64');
141
+ default:
142
+ return id;
143
+ }
144
+ }
145
+
146
+ export function getColumnParser(fields: readonly Column[]) {
147
+ if (fields.length === 0) {
148
+ throw new PothosValidationError('Column parser must have at least one field');
149
+ }
150
+
151
+ return (value: unknown) => {
152
+ const parsed = parseSerializedDrizzleColumn(value) as unknown[];
153
+
154
+ if (fields.length === 1) {
155
+ return { [fields[0].name]: parsed };
156
+ }
157
+
158
+ if (!Array.isArray(parsed)) {
159
+ throw new PothosValidationError(
160
+ `Expected compound cursor to contain an array, but got ${parsed}`,
161
+ );
162
+ }
163
+
164
+ const record: Record<string, unknown> = {};
165
+
166
+ fields.forEach((field, i) => {
167
+ record[field.name] = parsed[i];
168
+ });
169
+
170
+ return record;
171
+ };
172
+ }
173
+
174
+ export function getCursorParser(fields: readonly Column[]) {
175
+ if (fields.length === 0) {
176
+ throw new PothosValidationError('Cursor must have at least one field');
177
+ }
178
+
179
+ return (cursor: unknown) => {
180
+ const parsed = parseDrizzleCursor(cursor) as unknown[];
181
+
182
+ if (fields.length === 1) {
183
+ return { [fields[0].name]: parsed };
184
+ }
185
+
186
+ if (!Array.isArray(parsed)) {
187
+ throw new PothosValidationError(
188
+ `Expected compound cursor to contain an array, but got ${parsed}`,
189
+ );
190
+ }
191
+
192
+ const record: Record<string, unknown> = {};
193
+
194
+ fields.forEach((field, i) => {
195
+ record[field.name] = parsed[i];
196
+ });
197
+
198
+ return record;
199
+ };
200
+ }
201
+
202
+ export interface DrizzleCursorConnectionQueryOptions {
203
+ args: PothosSchemaTypes.DefaultConnectionArguments;
204
+ ctx: {};
205
+ defaultSize?: number | ((args: {}, ctx: {}) => number);
206
+ maxSize?: number | ((args: {}, ctx: {}) => number);
207
+ orderBy: ConnectionOrderBy;
208
+ where?: SQL;
209
+ }
210
+
211
+ const orderByOps = getOrderByOperators();
212
+
213
+ function parseOrderBy(orderBy: ConnectionOrderBy, invert: boolean) {
214
+ if (!Array.isArray(orderBy)) {
215
+ return parseOrderBy([orderBy], invert);
216
+ }
217
+
218
+ const asc = invert ? 'desc' : 'asc';
219
+ const desc = invert ? 'asc' : 'desc';
220
+
221
+ const normalized: { direction: 'asc' | 'desc'; column: Column }[] = orderBy.map((field) => {
222
+ if (typeof field === 'object' && 'asc' in field) {
223
+ return {
224
+ direction: asc,
225
+ column: field.asc,
226
+ };
227
+ } else if (typeof field === 'object' && 'desc' in field) {
228
+ return {
229
+ direction: desc,
230
+ column: field.desc,
231
+ };
232
+ }
233
+
234
+ return {
235
+ direction: asc,
236
+ column: field,
237
+ };
238
+ });
239
+
240
+ return {
241
+ normalized,
242
+ columns: normalized.map((field) => field.column),
243
+ sql: normalized.map((field) => orderByOps[field.direction](field.column)),
244
+ };
245
+ }
246
+
247
+ const ops = getOperators();
248
+
249
+ export function drizzleCursorConnectionQuery({
250
+ args,
251
+ ctx,
252
+ maxSize = DEFAULT_MAX_SIZE,
253
+ defaultSize = DEFAULT_SIZE,
254
+ orderBy,
255
+ where,
256
+ }: DrizzleCursorConnectionQueryOptions) {
257
+ const { before, after, first, last } = args;
258
+ if (first != null && first < 0) {
259
+ throw new PothosValidationError('Argument "first" must be a non-negative integer');
260
+ }
261
+
262
+ if (last != null && last < 0) {
263
+ throw new PothosValidationError('Argument "last" must be a non-negative integer');
264
+ }
265
+
266
+ if (before && after) {
267
+ throw new PothosValidationError(
268
+ 'Arguments "before" and "after" are not supported at the same time',
269
+ );
270
+ }
271
+
272
+ if (before != null && first != null) {
273
+ throw new PothosValidationError(
274
+ 'Arguments "before" and "first" are not supported at the same time',
275
+ );
276
+ }
277
+
278
+ if (after != null && last != null) {
279
+ throw new PothosValidationError(
280
+ 'Arguments "after" and "last" are not supported at the same time',
281
+ );
282
+ }
283
+
284
+ const cursor = before ?? after;
285
+
286
+ const maxSizeForConnection = typeof maxSize === 'function' ? maxSize(args, ctx) : maxSize;
287
+ const defaultSizeForConnection =
288
+ typeof defaultSize === 'function' ? defaultSize(args, ctx) : defaultSize;
289
+
290
+ let limit = Math.min(first ?? last ?? defaultSizeForConnection, maxSizeForConnection) + 1;
291
+
292
+ if (before ?? last) {
293
+ limit = -limit;
294
+ }
295
+
296
+ const parsedOrderBy = parseOrderBy(orderBy, limit < 0);
297
+
298
+ const columns: Record<string, boolean> = {};
299
+
300
+ parsedOrderBy.columns.forEach((column) => {
301
+ columns[column.name] = true;
302
+ });
303
+
304
+ let whereClauses: (SQL | undefined)[] = where ? [where] : [];
305
+
306
+ if (cursor) {
307
+ const cursorParser = getCursorParser(parsedOrderBy.columns);
308
+ const parsedCursor = cursorParser(cursor);
309
+
310
+ whereClauses.push(
311
+ ops.or(
312
+ ...parsedOrderBy.normalized.map(({ direction, column }, index) => {
313
+ const compare =
314
+ direction === 'asc'
315
+ ? ops.gt(column, parsedCursor[column.name])
316
+ : ops.lt(column, parsedCursor[column.name]);
317
+
318
+ if (index === 0) {
319
+ return compare;
320
+ }
321
+
322
+ return ops.and(
323
+ ...parsedOrderBy.normalized
324
+ .slice(0, index)
325
+ .map(({ column: c }) => ops.eq(c, parsedCursor[c.name])),
326
+ compare,
327
+ );
328
+ }),
329
+ ),
330
+ );
331
+ }
332
+
333
+ return {
334
+ cursorColumns: parsedOrderBy.columns,
335
+ columns,
336
+ orderBy: parsedOrderBy.sql,
337
+ limit,
338
+ offset: cursor ? 1 : 0,
339
+ where: ops.and(...whereClauses),
340
+ };
341
+ }
342
+
343
+ export function wrapConnectionResult<T extends {}>(
344
+ results: readonly T[],
345
+ args: PothosSchemaTypes.DefaultConnectionArguments,
346
+ limit: number,
347
+ cursor: (node: T) => string,
348
+ resolveNode?: (node: unknown) => unknown,
349
+ ) {
350
+ const gotFullResults = results.length === Math.abs(limit);
351
+ const hasNextPage = args.before ? true : args.last ? false : gotFullResults;
352
+ const hasPreviousPage = args.after ? true : args.before ?? args.last ? gotFullResults : false;
353
+ const nodes = gotFullResults
354
+ ? results.slice(limit < 0 ? 1 : 0, limit < 0 ? results.length : -1)
355
+ : results;
356
+
357
+ const connection = {
358
+ args,
359
+ edges: [] as ({ cursor: string; node: unknown } | null)[],
360
+ pageInfo: {
361
+ startCursor: null as string | null,
362
+ endCursor: null as string | null,
363
+ hasPreviousPage,
364
+ hasNextPage,
365
+ },
366
+ };
367
+
368
+ const edges = nodes.map((value, index) =>
369
+ value == null
370
+ ? null
371
+ : resolveNode
372
+ ? {
373
+ connection,
374
+ ...value,
375
+ cursor: cursor(value),
376
+ node: resolveNode(value),
377
+ }
378
+ : {
379
+ connection,
380
+ cursor: cursor(value),
381
+ node: value,
382
+ },
383
+ );
384
+
385
+ if (args.last && !args.first) {
386
+ edges.reverse();
387
+ }
388
+
389
+ connection.edges = edges;
390
+ connection.pageInfo.startCursor = edges[0]?.cursor ?? null;
391
+ connection.pageInfo.endCursor = edges[edges.length - 1]?.cursor ?? null;
392
+
393
+ return connection;
394
+ }
395
+
396
+ export async function resolveDrizzleCursorConnection<T extends {}>(
397
+ table: TableRelationalConfig,
398
+ info: GraphQLResolveInfo,
399
+ typeName: string,
400
+ config: PothosDrizzleSchemaConfig,
401
+ options: Omit<DrizzleCursorConnectionQueryOptions, 'orderBy'>,
402
+ resolve: (
403
+ queryFn: (query: QueryForDrizzleConnection<SchemaTypes, TableRelationalConfig>) => SelectionMap,
404
+ ) => MaybePromise<readonly T[]>,
405
+ ) {
406
+ let query;
407
+ let formatter;
408
+ const results = await resolve((q) => {
409
+ const { cursorColumns, ...connectionQuery } = drizzleCursorConnectionQuery({
410
+ ...options,
411
+ orderBy: q.orderBy
412
+ ? typeof q.orderBy === 'function'
413
+ ? q.orderBy(table.columns)
414
+ : q.orderBy
415
+ : table.primaryKey,
416
+ });
417
+ formatter = getCursorFormatter(cursorColumns);
418
+
419
+ const where = typeof q.where === 'function' ? q.where(table.columns, getOperators()) : q.where;
420
+
421
+ query = queryFromInfo({
422
+ context: options.ctx,
423
+ info,
424
+ select: {
425
+ ...connectionQuery,
426
+ columns: {
427
+ ...q.columns,
428
+ ...connectionQuery.columns,
429
+ },
430
+ where: ops.and(connectionQuery.where, where),
431
+ },
432
+ paths: [['nodes'], ['edges', 'node']],
433
+ typeName,
434
+ config,
435
+ // withUsageCheck: !!this.builder.options.prisma?.onUnusedQuery,
436
+ });
437
+
438
+ return query;
439
+ });
440
+
441
+ if (!results) {
442
+ return results;
443
+ }
444
+
445
+ return wrapConnectionResult(results, options.args, query!.limit, formatter!);
446
+ }
@@ -0,0 +1,58 @@
1
+ /* eslint-disable no-continue */
2
+ export function deepEqual(left: unknown, right: unknown, ignore?: Set<string>) {
3
+ if (left === right) {
4
+ return true;
5
+ }
6
+
7
+ if (left && right && typeof left === 'object' && typeof right === 'object') {
8
+ if (Array.isArray(left)) {
9
+ if (!Array.isArray(right)) {
10
+ return false;
11
+ }
12
+
13
+ const { length } = left;
14
+
15
+ if (right.length !== length) {
16
+ return false;
17
+ }
18
+
19
+ for (let i = 0; i < length; i += 1) {
20
+ if (!deepEqual(left[i], right[i])) {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ return true;
26
+ }
27
+
28
+ const lValue = left.valueOf?.();
29
+ const rValue = right.valueOf?.();
30
+
31
+ if ((lValue != null || rValue != null) && typeof lValue !== 'object') {
32
+ return lValue === rValue;
33
+ }
34
+
35
+ const keys = Object.keys(left);
36
+ const keyLength = keys.length;
37
+
38
+ if (keyLength !== Object.keys(right).length) {
39
+ return false;
40
+ }
41
+
42
+ for (const key of keys) {
43
+ if (ignore?.has(key)) {
44
+ continue;
45
+ }
46
+
47
+ if (
48
+ !deepEqual((left as Record<string, unknown>)[key], (right as Record<string, unknown>)[key])
49
+ ) {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ return true;
55
+ }
56
+
57
+ return false;
58
+ }