@pothos/plugin-drizzle 0.0.1 → 0.2.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.
Files changed (152) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/drizzle/meta/_journal.json +1 -1
  3. package/dts/drizzle-field-builder.d.ts +9 -9
  4. package/dts/drizzle-field-builder.d.ts.map +1 -1
  5. package/dts/global-types.d.ts +7 -7
  6. package/dts/global-types.d.ts.map +1 -1
  7. package/dts/index.d.ts +2 -2
  8. package/dts/index.d.ts.map +1 -1
  9. package/dts/interface-ref.d.ts +2 -2
  10. package/dts/interface-ref.d.ts.map +1 -1
  11. package/dts/model-loader.d.ts +7 -5
  12. package/dts/model-loader.d.ts.map +1 -1
  13. package/dts/node-ref.d.ts +1 -1
  14. package/dts/node-ref.d.ts.map +1 -1
  15. package/dts/object-ref.d.ts +1 -1
  16. package/dts/object-ref.d.ts.map +1 -1
  17. package/dts/types.d.ts +21 -14
  18. package/dts/types.d.ts.map +1 -1
  19. package/dts/utils/config.d.ts +4 -2
  20. package/dts/utils/config.d.ts.map +1 -1
  21. package/dts/utils/cursors.d.ts +7 -7
  22. package/dts/utils/cursors.d.ts.map +1 -1
  23. package/dts/utils/deep-equal.d.ts.map +1 -1
  24. package/dts/utils/drizzle-graphql.d.ts +1 -1
  25. package/dts/utils/drizzle-graphql.d.ts.map +1 -1
  26. package/dts/utils/loader-map.d.ts +1 -1
  27. package/dts/utils/loader-map.d.ts.map +1 -1
  28. package/dts/utils/map-query.d.ts +3 -3
  29. package/dts/utils/map-query.d.ts.map +1 -1
  30. package/dts/utils/refs.d.ts +2 -2
  31. package/dts/utils/refs.d.ts.map +1 -1
  32. package/dts/utils/selections.d.ts +3 -3
  33. package/dts/utils/selections.d.ts.map +1 -1
  34. package/dts/utils/usage.d.ts.map +1 -1
  35. package/esm/drizzle-field-builder.d.ts +9 -9
  36. package/esm/drizzle-field-builder.d.ts.map +1 -1
  37. package/esm/global-types.d.ts +7 -7
  38. package/esm/global-types.d.ts.map +1 -1
  39. package/esm/index.d.ts +2 -2
  40. package/esm/index.d.ts.map +1 -1
  41. package/esm/interface-ref.d.ts +2 -2
  42. package/esm/interface-ref.d.ts.map +1 -1
  43. package/esm/model-loader.d.ts +7 -5
  44. package/esm/model-loader.d.ts.map +1 -1
  45. package/esm/node-ref.d.ts +1 -1
  46. package/esm/node-ref.d.ts.map +1 -1
  47. package/esm/object-ref.d.ts +1 -1
  48. package/esm/object-ref.d.ts.map +1 -1
  49. package/esm/src/drizzle-field-builder.js +10 -9
  50. package/esm/src/drizzle-field-builder.js.map +1 -1
  51. package/esm/src/field-builder.js +4 -4
  52. package/esm/src/field-builder.js.map +1 -1
  53. package/esm/src/global-types.js +1 -1
  54. package/esm/src/global-types.js.map +1 -1
  55. package/esm/src/index.js +4 -4
  56. package/esm/src/index.js.map +1 -1
  57. package/esm/src/interface-ref.js.map +1 -1
  58. package/esm/src/model-loader.js +9 -6
  59. package/esm/src/model-loader.js.map +1 -1
  60. package/esm/src/object-ref.js +4 -2
  61. package/esm/src/object-ref.js.map +1 -1
  62. package/esm/src/schema-builder.js +19 -18
  63. package/esm/src/schema-builder.js.map +1 -1
  64. package/esm/src/types.js.map +1 -1
  65. package/esm/src/utils/config.js +15 -2
  66. package/esm/src/utils/config.js.map +1 -1
  67. package/esm/src/utils/cursors.js +6 -6
  68. package/esm/src/utils/cursors.js.map +1 -1
  69. package/esm/src/utils/deep-equal.js +1 -1
  70. package/esm/src/utils/deep-equal.js.map +1 -1
  71. package/esm/src/utils/drizzle-graphql.js +44 -21
  72. package/esm/src/utils/drizzle-graphql.js.map +1 -1
  73. package/esm/src/utils/loader-map.js +4 -5
  74. package/esm/src/utils/loader-map.js.map +1 -1
  75. package/esm/src/utils/map-query.js +1 -3
  76. package/esm/src/utils/map-query.js.map +1 -1
  77. package/esm/src/utils/refs.js.map +1 -1
  78. package/esm/src/utils/selections.js +3 -3
  79. package/esm/src/utils/selections.js.map +1 -1
  80. package/esm/src/utils/usage.js +0 -1
  81. package/esm/src/utils/usage.js.map +1 -1
  82. package/esm/types.d.ts +21 -14
  83. package/esm/types.d.ts.map +1 -1
  84. package/esm/utils/config.d.ts +4 -2
  85. package/esm/utils/config.d.ts.map +1 -1
  86. package/esm/utils/cursors.d.ts +7 -7
  87. package/esm/utils/cursors.d.ts.map +1 -1
  88. package/esm/utils/deep-equal.d.ts.map +1 -1
  89. package/esm/utils/drizzle-graphql.d.ts +1 -1
  90. package/esm/utils/drizzle-graphql.d.ts.map +1 -1
  91. package/esm/utils/loader-map.d.ts +1 -1
  92. package/esm/utils/loader-map.d.ts.map +1 -1
  93. package/esm/utils/map-query.d.ts +3 -3
  94. package/esm/utils/map-query.d.ts.map +1 -1
  95. package/esm/utils/refs.d.ts +2 -2
  96. package/esm/utils/refs.d.ts.map +1 -1
  97. package/esm/utils/selections.d.ts +3 -3
  98. package/esm/utils/selections.d.ts.map +1 -1
  99. package/esm/utils/usage.d.ts.map +1 -1
  100. package/lib/src/drizzle-field-builder.js +9 -8
  101. package/lib/src/drizzle-field-builder.js.map +1 -1
  102. package/lib/src/field-builder.js +4 -4
  103. package/lib/src/field-builder.js.map +1 -1
  104. package/lib/src/global-types.js +1 -1
  105. package/lib/src/global-types.js.map +1 -1
  106. package/lib/src/index.js +4 -4
  107. package/lib/src/index.js.map +1 -1
  108. package/lib/src/interface-ref.js.map +1 -1
  109. package/lib/src/model-loader.js +10 -6
  110. package/lib/src/model-loader.js.map +1 -1
  111. package/lib/src/object-ref.js +3 -1
  112. package/lib/src/object-ref.js.map +1 -1
  113. package/lib/src/schema-builder.js +19 -18
  114. package/lib/src/schema-builder.js.map +1 -1
  115. package/lib/src/types.js.map +1 -1
  116. package/lib/src/utils/config.js +26 -5
  117. package/lib/src/utils/config.js.map +1 -1
  118. package/lib/src/utils/cursors.js +7 -6
  119. package/lib/src/utils/cursors.js.map +1 -1
  120. package/lib/src/utils/deep-equal.js +1 -1
  121. package/lib/src/utils/deep-equal.js.map +1 -1
  122. package/lib/src/utils/drizzle-graphql.js +53 -21
  123. package/lib/src/utils/drizzle-graphql.js.map +1 -1
  124. package/lib/src/utils/loader-map.js +4 -5
  125. package/lib/src/utils/loader-map.js.map +1 -1
  126. package/lib/src/utils/map-query.js +2 -4
  127. package/lib/src/utils/map-query.js.map +1 -1
  128. package/lib/src/utils/refs.js.map +1 -1
  129. package/lib/src/utils/selections.js +4 -4
  130. package/lib/src/utils/selections.js.map +1 -1
  131. package/lib/src/utils/usage.js +0 -1
  132. package/lib/src/utils/usage.js.map +1 -1
  133. package/package.json +11 -11
  134. package/src/drizzle-field-builder.ts +38 -27
  135. package/src/field-builder.ts +12 -13
  136. package/src/global-types.ts +28 -20
  137. package/src/index.ts +29 -36
  138. package/src/interface-ref.ts +2 -2
  139. package/src/model-loader.ts +15 -17
  140. package/src/node-ref.ts +1 -1
  141. package/src/object-ref.ts +5 -3
  142. package/src/schema-builder.ts +26 -25
  143. package/src/types.ts +54 -48
  144. package/src/utils/config.ts +35 -5
  145. package/src/utils/cursors.ts +21 -22
  146. package/src/utils/deep-equal.ts +0 -1
  147. package/src/utils/drizzle-graphql.ts +53 -14
  148. package/src/utils/loader-map.ts +5 -7
  149. package/src/utils/map-query.ts +20 -23
  150. package/src/utils/refs.ts +2 -2
  151. package/src/utils/selections.ts +8 -9
  152. package/src/utils/usage.ts +0 -2
@@ -1,23 +1,24 @@
1
1
  import SchemaBuilder, {
2
2
  brandWithType,
3
3
  completeValue,
4
- InterfaceRef,
5
- ObjectRef,
6
- OutputType,
4
+ type InterfaceRef,
5
+ type ObjectRef,
6
+ type OutputType,
7
7
  PothosError,
8
- SchemaTypes,
9
- FieldRef,
10
- InputObjectRef,
8
+ type SchemaTypes,
9
+ type FieldRef,
10
+ type InputObjectRef,
11
11
  } from '@pothos/core';
12
+ import type { GraphQLInputObjectType, GraphQLResolveInfo } from 'graphql';
12
13
  import { DrizzleObjectFieldBuilder } from './drizzle-field-builder';
13
- import { getRefFromModel } from './utils/refs';
14
+ import { DrizzleInterfaceRef } from './interface-ref';
15
+ import { ModelLoader } from './model-loader';
16
+ import { DrizzleNodeRef } from './node-ref';
14
17
  import { DrizzleObjectRef } from './object-ref';
15
- import { DrizzleGraphQLInputExtensions, DrizzleNodeOptions } from './types';
18
+ import type { DrizzleGraphQLInputExtensions, DrizzleNodeOptions } from './types';
19
+ import { getSchemaConfig } from './utils/config';
16
20
  import { getColumnParser, getColumnSerializer } from './utils/cursors';
17
- import { DrizzleNodeRef } from './node-ref';
18
- import { GraphQLInputObjectType, GraphQLResolveInfo } from 'graphql';
19
- import { ModelLoader } from './model-loader';
20
- import { DrizzleInterfaceRef } from './interface-ref';
21
+ import { getRefFromModel } from './utils/refs';
21
22
 
22
23
  const schemaBuilderProto = SchemaBuilder.prototype as PothosSchemaTypes.SchemaBuilder<SchemaTypes>;
23
24
 
@@ -35,7 +36,7 @@ schemaBuilderProto.drizzleObject = function drizzleObject(table, { select, field
35
36
  extensions: {
36
37
  ...options.extensions,
37
38
  pothosDrizzleModel: table,
38
- pothosDrizzleTable: this.options.drizzle.client._.schema?.[table],
39
+ pothosDrizzleTable: getSchemaConfig(this).schema?.[table],
39
40
  pothosDrizzleSelect: select ?? {},
40
41
  pothosDrizzleLoader: ModelLoader.forModel(table, this),
41
42
  },
@@ -63,7 +64,7 @@ schemaBuilderProto.drizzleInterface = function drizzleInterface(
63
64
  extensions: {
64
65
  ...options.extensions,
65
66
  pothosDrizzleModel: table,
66
- pothosDrizzleTable: this.options.drizzle.client._.schema?.[table],
67
+ pothosDrizzleTable: getSchemaConfig(this).schema?.[table],
67
68
  pothosDrizzleSelect: select ?? {},
68
69
  pothosDrizzleLoader: ModelLoader.forModel(table, this),
69
70
  },
@@ -88,7 +89,7 @@ schemaBuilderProto.drizzleNode = function drizzleNode(
88
89
  ...options
89
90
  }: DrizzleNodeOptions<SchemaTypes, keyof SchemaTypes['DrizzleRelationSchema'], {}, {}, []>,
90
91
  ) {
91
- const tableConfig = this.options.drizzle.client._.schema![table];
92
+ const tableConfig = getSchemaConfig(this).schema![table];
92
93
  const idColumn = typeof column === 'function' ? column(tableConfig.columns) : column;
93
94
  const idColumns = Array.isArray(idColumn) ? idColumn : [idColumn];
94
95
  const interfaceRef = this.nodeInterfaceRef?.();
@@ -139,12 +140,12 @@ schemaBuilderProto.drizzleNode = function drizzleNode(
139
140
  globalID: (options: Record<string, unknown>) => FieldRef<SchemaTypes, unknown>;
140
141
  }
141
142
  ).globalID({
142
- ...(this.options as { relayOptions?: { idFieldOptions?: {} } }).relayOptions
143
+ ...(this.options as { relayOptions?: { idFieldOptions?: object } }).relayOptions
143
144
  ?.idFieldOptions,
144
145
  ...idOptions,
145
146
  nullable: false,
146
147
  args: {},
147
- resolve: (parent: never, args: object, context: object, info: GraphQLResolveInfo) =>
148
+ resolve: (parent: never) =>
148
149
  completeValue(resolve(parent), (id) => ({
149
150
  type: nodeConfig.name,
150
151
  id,
@@ -198,7 +199,7 @@ schemaBuilderProto.drizzleGraphQLOrderBy = function drizzleGraphQLOrderBy(
198
199
  this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
199
200
  table: string,
200
201
  type: GraphQLInputObjectType,
201
- options?: { extensions?: {} },
202
+ options?: { extensions?: object },
202
203
  ) {
203
204
  return (
204
205
  this as typeof this & {
@@ -214,7 +215,7 @@ schemaBuilderProto.drizzleGraphQLOrderBy = function drizzleGraphQLOrderBy(
214
215
  drizzleGraphQL: {
215
216
  inputType: 'orderBy',
216
217
  table,
217
- tableConfig: this.options.drizzle.client._.schema?.[table]!,
218
+ tableConfig: getSchemaConfig(this).schema?.[table]!,
218
219
  } satisfies DrizzleGraphQLInputExtensions,
219
220
  },
220
221
  });
@@ -224,7 +225,7 @@ schemaBuilderProto.drizzleGraphQLFilters = function drizzleGraphQLFilters(
224
225
  this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
225
226
  table: string,
226
227
  type: GraphQLInputObjectType,
227
- options?: { extensions?: {} },
228
+ options?: { extensions?: object },
228
229
  ) {
229
230
  return (
230
231
  this as typeof this & {
@@ -240,7 +241,7 @@ schemaBuilderProto.drizzleGraphQLFilters = function drizzleGraphQLFilters(
240
241
  drizzleGraphQL: {
241
242
  inputType: 'filters',
242
243
  table,
243
- tableConfig: this.options.drizzle.client._.schema?.[table]!,
244
+ tableConfig: getSchemaConfig(this).schema?.[table]!,
244
245
  } satisfies DrizzleGraphQLInputExtensions,
245
246
  },
246
247
  });
@@ -250,7 +251,7 @@ schemaBuilderProto.drizzleGraphQLInsert = function drizzleGraphQLInsert(
250
251
  this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
251
252
  table: string,
252
253
  type: GraphQLInputObjectType,
253
- options?: { extensions?: {} },
254
+ options?: { extensions?: object },
254
255
  ) {
255
256
  return (
256
257
  this as typeof this & {
@@ -266,7 +267,7 @@ schemaBuilderProto.drizzleGraphQLInsert = function drizzleGraphQLInsert(
266
267
  drizzleGraphQL: {
267
268
  inputType: 'insert',
268
269
  table,
269
- tableConfig: this.options.drizzle.client._.schema?.[table]!,
270
+ tableConfig: getSchemaConfig(this).schema?.[table]!,
270
271
  } satisfies DrizzleGraphQLInputExtensions,
271
272
  },
272
273
  });
@@ -276,7 +277,7 @@ schemaBuilderProto.drizzleGraphQLUpdate = function drizzleGraphQLUpdate(
276
277
  this: PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
277
278
  table: string,
278
279
  type: GraphQLInputObjectType,
279
- options?: { extensions?: {} },
280
+ options?: { extensions?: object },
280
281
  ) {
281
282
  return (
282
283
  this as typeof this & {
@@ -292,7 +293,7 @@ schemaBuilderProto.drizzleGraphQLUpdate = function drizzleGraphQLUpdate(
292
293
  drizzleGraphQL: {
293
294
  inputType: 'update',
294
295
  table,
295
- tableConfig: this.options.drizzle.client._.schema?.[table]!,
296
+ tableConfig: getSchemaConfig(this).schema?.[table]!,
296
297
  } satisfies DrizzleGraphQLInputExtensions,
297
298
  },
298
299
  });
package/src/types.ts CHANGED
@@ -1,4 +1,30 @@
1
1
  import {
2
+ type ArgumentRef,
3
+ type FieldKind,
4
+ type FieldMap,
5
+ type FieldNullability,
6
+ type FieldOptionsFromKind,
7
+ type InferredFieldOptionKeys,
8
+ type InferredFieldOptionsByKind,
9
+ type InputFieldMap,
10
+ type InputFieldsFromShape,
11
+ type InputShapeFromFields,
12
+ type InterfaceParam,
13
+ type InterfaceRef,
14
+ type InterfaceTypeOptions,
15
+ type ListResolveValue,
16
+ type MaybePromise,
17
+ type Normalize,
18
+ type ObjectRef,
19
+ type ObjectTypeOptions,
20
+ type OutputShape,
21
+ type OutputType,
22
+ type SchemaTypes,
23
+ type ShapeFromTypeParam,
24
+ type TypeParam,
25
+ typeBrandKey,
26
+ } from '@pothos/core';
27
+ import type {
2
28
  BuildQueryResult,
3
29
  Column,
4
30
  DBQueryConfig,
@@ -9,44 +35,30 @@ import {
9
35
  TableRelationalConfig,
10
36
  TablesRelationalConfig,
11
37
  } from 'drizzle-orm';
12
- import { FieldNode, GraphQLResolveInfo } from 'graphql';
13
- import {
14
- ArgumentRef,
15
- FieldKind,
16
- FieldMap,
17
- FieldNullability,
18
- FieldOptionsFromKind,
19
- InferredFieldOptionKeys,
20
- InferredFieldOptionsByKind,
21
- InputFieldMap,
22
- InputFieldsFromShape,
23
- InputShapeFromFields,
24
- InterfaceParam,
25
- InterfaceRef,
26
- InterfaceTypeOptions,
27
- ListResolveValue,
28
- MaybePromise,
29
- Normalize,
30
- ObjectRef,
31
- ObjectTypeOptions,
32
- OutputShape,
33
- OutputType,
34
- SchemaTypes,
35
- ShapeFromTypeParam,
36
- typeBrandKey,
37
- TypeParam,
38
- } from '@pothos/core';
38
+ import type { FieldNode, GraphQLResolveInfo } from 'graphql';
39
39
  import type { DrizzleObjectFieldBuilder } from './drizzle-field-builder';
40
- import { type DrizzleRef } from './interface-ref';
41
- import { IndirectInclude } from './utils/map-query';
42
- import { SelectionMap } from './utils/selections';
40
+ import type { DrizzleRef } from './interface-ref';
41
+ import type { IndirectInclude } from './utils/map-query';
42
+ import type { SelectionMap } from './utils/selections';
43
+
44
+ export type DrizzleClient = {
45
+ _: Partial<RelationalSchemaConfig<TablesRelationalConfig>>;
46
+ query: {};
47
+ };
43
48
 
44
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
- export interface DrizzlePluginOptions<Types extends SchemaTypes> {
46
- client: { _: Partial<RelationalSchemaConfig<TablesRelationalConfig>>; query: {} };
49
+ export type DrizzlePluginOptions<Types extends SchemaTypes> = {
47
50
  maxConnectionSize?: number;
48
51
  defaultConnectionSize?: number;
49
- }
52
+ } & (
53
+ | {
54
+ client: DrizzleClient;
55
+ schema?: Partial<RelationalSchemaConfig<TablesRelationalConfig>>;
56
+ }
57
+ | {
58
+ client: (ctx: Types['Context']) => DrizzleClient;
59
+ schema: Partial<RelationalSchemaConfig<TablesRelationalConfig>>;
60
+ }
61
+ );
50
62
 
51
63
  export const drizzleTableName = Symbol.for('Pothos.drizzleTableName');
52
64
 
@@ -238,6 +250,7 @@ export type DrizzleObjectFieldOptions<
238
250
  : BuildQueryResult<
239
251
  Types['DrizzleRelationSchema'],
240
252
  ExtractTable<Types, ParentShape>,
253
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
241
254
  Record<string, unknown> & (Select extends (...args: any[]) => infer R ? R : Select)
242
255
  > &
243
256
  ParentShape,
@@ -338,6 +351,7 @@ export type RelatedFieldOptions<
338
351
  export type VariantFieldOptions<
339
352
  Types extends SchemaTypes,
340
353
  Table extends keyof Types['DrizzleRelationSchema'],
354
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
341
355
  Variant extends DrizzleRef<any, Table> | Table,
342
356
  Args extends InputFieldMap,
343
357
  isNull,
@@ -348,6 +362,7 @@ export type VariantFieldOptions<
348
362
  FieldOptionsFromKind<
349
363
  Types,
350
364
  Shape,
365
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
351
366
  Variant extends DrizzleRef<any> ? Variant : DrizzleRef<any, Table>,
352
367
  unknown extends isNull ? false : true,
353
368
  Args,
@@ -367,6 +382,7 @@ export type VariantFieldOptions<
367
382
  Types['DrizzleRelationSchema'],
368
383
  ExtractTable<Types, Shape>,
369
384
  Record<string, unknown> &
385
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
370
386
  (ResolveShape extends (...args: any[]) => infer R ? R : ResolveShape)
371
387
  > &
372
388
  Shape,
@@ -465,16 +481,14 @@ export type ListRelation<T extends TableRelationalConfig> = {
465
481
  export type DrizzleConnectionFieldOptions<
466
482
  Types extends SchemaTypes,
467
483
  ParentShape,
468
- Type extends
469
- | DrizzleRef<any, keyof Types['DrizzleRelationSchema']>
470
- | keyof Types['DrizzleRelationSchema'],
484
+ Type extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
485
+ DrizzleRef<any, keyof Types['DrizzleRelationSchema']> | keyof Types['DrizzleRelationSchema'],
471
486
  TableConfig extends TableRelationalConfig,
472
487
  Param extends OutputType<Types>,
473
488
  Nullable extends boolean,
474
489
  Args extends InputFieldMap,
475
490
  ResolveReturnShape,
476
491
  Kind extends FieldKind,
477
- // eslint-disable-next-line @typescript-eslint/sort-type-constituents
478
492
  > = Omit<
479
493
  FieldOptionsFromKind<
480
494
  Types,
@@ -510,15 +524,7 @@ export type DrizzleConnectionFieldOptions<
510
524
  maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
511
525
 
512
526
  resolve: (
513
- query: <
514
- T extends QueryForRelatedConnection<
515
- Types,
516
- Types['DrizzleRelationSchema'][Type extends DrizzleRef<any, infer K>
517
- ? K
518
- : Type & keyof Types['DrizzleRelationSchema']],
519
- ConnectionArgs
520
- >,
521
- >(
527
+ query: <T extends QueryForRelatedConnection<Types, TableConfig, ConnectionArgs>>(
522
528
  selection?: T,
523
529
  ) => Omit<T, 'orderBy'> & { orderBy: SQL },
524
530
  parent: ParentShape,
@@ -542,7 +548,6 @@ export type RelatedConnectionOptions<
542
548
  Args extends InputFieldMap,
543
549
  NodeTable extends
544
550
  TableRelationalConfig = Types['DrizzleRelationSchema'][Table['relations'][Field]['referencedTable']['_']['name']],
545
- // eslint-disable-next-line @typescript-eslint/sort-type-constituents
546
551
  > = Omit<
547
552
  PothosSchemaTypes.ObjectFieldOptions<
548
553
  Types,
@@ -584,6 +589,7 @@ export type RelatedConnectionOptions<
584
589
  >
585
590
  >;
586
591
  query: QueryForRelatedConnection<Types, NodeTable, ConnectionArgs>;
592
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
587
593
  type?: DrizzleRef<any, Table['relations'][Field]['referencedTable']['_']['name']>;
588
594
 
589
595
  defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
@@ -1,11 +1,20 @@
1
- import { createContextCache, SchemaTypes } from '@pothos/core';
2
- import { RelationalSchemaConfig, TableRelationalConfig, TablesRelationalConfig } from 'drizzle-orm';
1
+ import { type SchemaTypes, createContextCache } from '@pothos/core';
2
+ import type {
3
+ RelationalSchemaConfig,
4
+ TableRelationalConfig,
5
+ TablesRelationalConfig,
6
+ } from 'drizzle-orm';
7
+ import type { DrizzleClient } from '../types';
3
8
 
4
9
  export interface PothosDrizzleSchemaConfig extends RelationalSchemaConfig<TablesRelationalConfig> {
5
10
  dbToSchema: Record<string, TableRelationalConfig>;
6
11
  }
7
- const cache = createContextCache(
8
- (config: RelationalSchemaConfig<TablesRelationalConfig>): PothosDrizzleSchemaConfig => {
12
+ const configCache = createContextCache(
13
+ (builder: PothosSchemaTypes.SchemaBuilder<SchemaTypes>): PothosDrizzleSchemaConfig => {
14
+ const config = (builder.options.drizzle.schema ??
15
+ (builder.options.drizzle.client as DrizzleClient)
16
+ ._) as RelationalSchemaConfig<TablesRelationalConfig>;
17
+
9
18
  const dbToSchema = Object.values(config.schema).reduce<Record<string, TableRelationalConfig>>(
10
19
  (acc, table) => {
11
20
  acc[table.dbName] = table;
@@ -21,8 +30,29 @@ const cache = createContextCache(
21
30
  },
22
31
  );
23
32
 
33
+ const clientCache = createContextCache((builder: PothosSchemaTypes.SchemaBuilder<SchemaTypes>) => {
34
+ const clientConfig = builder.options.drizzle.client;
35
+ const getClient =
36
+ typeof clientConfig === 'function'
37
+ ? createContextCache((ctx) => clientConfig(ctx))
38
+ : (_ctx: object) => clientConfig;
39
+
40
+ return createContextCache((context: object) => {
41
+ const client = getClient(context);
42
+
43
+ return client;
44
+ });
45
+ });
46
+
24
47
  export function getSchemaConfig<Types extends SchemaTypes>(
25
48
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
26
49
  ) {
27
- return cache(builder.options.drizzle.client._ as RelationalSchemaConfig<TablesRelationalConfig>);
50
+ return configCache(builder as never);
51
+ }
52
+
53
+ export function getClient<Types extends SchemaTypes>(
54
+ builder: PothosSchemaTypes.SchemaBuilder<Types>,
55
+ context: object,
56
+ ) {
57
+ return clientCache(builder as never)(context);
28
58
  }
@@ -1,25 +1,23 @@
1
- /* eslint-disable no-nested-ternary */
2
1
  import {
2
+ type MaybePromise,
3
+ PothosValidationError,
4
+ type SchemaTypes,
3
5
  decodeBase64,
4
6
  encodeBase64,
5
- MaybePromise,
6
- PothosValidationError,
7
- SchemaTypes,
8
7
  } from '@pothos/core';
9
8
  import {
10
- Column,
9
+ type Column,
10
+ type DBQueryConfig,
11
+ type SQL,
12
+ type TableRelationalConfig,
11
13
  getOperators,
12
14
  getOrderByOperators,
13
- RelationalSchemaConfig,
14
- SQL,
15
- TableRelationalConfig,
16
- TablesRelationalConfig,
17
15
  } from 'drizzle-orm';
18
- import { ConnectionOrderBy, QueryForDrizzleConnection } from '../types';
19
- import { SelectionMap } from './selections';
20
- import { GraphQLResolveInfo } from 'graphql';
16
+ import type { GraphQLResolveInfo } from 'graphql';
17
+ import type { ConnectionOrderBy, QueryForDrizzleConnection } from '../types';
18
+ import type { PothosDrizzleSchemaConfig } from './config';
21
19
  import { queryFromInfo } from './map-query';
22
- import { PothosDrizzleSchemaConfig } from './config';
20
+ import type { SelectionMap } from './selections';
23
21
 
24
22
  const DEFAULT_MAX_SIZE = 100;
25
23
  const DEFAULT_SIZE = 20;
@@ -224,7 +222,8 @@ function parseOrderBy(orderBy: ConnectionOrderBy, invert: boolean) {
224
222
  direction: asc,
225
223
  column: field.asc,
226
224
  };
227
- } else if (typeof field === 'object' && 'desc' in field) {
225
+ }
226
+ if (typeof field === 'object' && 'desc' in field) {
228
227
  return {
229
228
  direction: desc,
230
229
  column: field.desc,
@@ -297,11 +296,11 @@ export function drizzleCursorConnectionQuery({
297
296
 
298
297
  const columns: Record<string, boolean> = {};
299
298
 
300
- parsedOrderBy.columns.forEach((column) => {
299
+ for (const column of parsedOrderBy.columns) {
301
300
  columns[column.name] = true;
302
- });
301
+ }
303
302
 
304
- let whereClauses: (SQL | undefined)[] = where ? [where] : [];
303
+ const whereClauses: (SQL | undefined)[] = where ? [where] : [];
305
304
 
306
305
  if (cursor) {
307
306
  const cursorParser = getCursorParser(parsedOrderBy.columns);
@@ -345,7 +344,7 @@ export function wrapConnectionResult<T extends {}>(
345
344
  args: PothosSchemaTypes.DefaultConnectionArguments,
346
345
  limit: number,
347
346
  cursor: (node: T) => string,
348
- resolveNode?: (node: unknown) => unknown,
347
+ resolveNode?: (node: Record<string, unknown>) => unknown,
349
348
  ) {
350
349
  const gotFullResults = results.length === Math.abs(limit);
351
350
  const hasNextPage = args.before ? true : args.last ? false : gotFullResults;
@@ -365,7 +364,7 @@ export function wrapConnectionResult<T extends {}>(
365
364
  },
366
365
  };
367
366
 
368
- const edges = nodes.map((value, index) =>
367
+ const edges = nodes.map((value) =>
369
368
  value == null
370
369
  ? null
371
370
  : resolveNode
@@ -403,8 +402,8 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
403
402
  queryFn: (query: QueryForDrizzleConnection<SchemaTypes, TableRelationalConfig>) => SelectionMap,
404
403
  ) => MaybePromise<readonly T[]>,
405
404
  ) {
406
- let query;
407
- let formatter;
405
+ let query: DBQueryConfig<'many', false>;
406
+ let formatter: (node: Record<string, unknown>) => string;
408
407
  const results = await resolve((q) => {
409
408
  const { cursorColumns, ...connectionQuery } = drizzleCursorConnectionQuery({
410
409
  ...options,
@@ -442,5 +441,5 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
442
441
  return results;
443
442
  }
444
443
 
445
- return wrapConnectionResult(results, options.args, query!.limit, formatter!);
444
+ return wrapConnectionResult(results, options.args, query!.limit as number, formatter!);
446
445
  }
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-continue */
2
1
  export function deepEqual(left: unknown, right: unknown, ignore?: Set<string>) {
3
2
  if (left === right) {
4
3
  return true;
@@ -1,12 +1,22 @@
1
- import { asc, Column, desc, getOperators, SQL, Table, TableRelationalConfig } from 'drizzle-orm';
1
+ import {
2
+ type Column,
3
+ type SQL,
4
+ Table,
5
+ type TableRelationalConfig,
6
+ asc,
7
+ desc,
8
+ getOperators,
9
+ } from 'drizzle-orm';
2
10
  import { GraphQLError } from 'graphql';
3
11
 
12
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
4
13
  export const remapFromGraphQLCore = (value: any, column: Column, columnName: string) => {
5
14
  switch (column.dataType) {
6
15
  case 'date': {
7
16
  const formatted = new Date(value);
8
- if (Number.isNaN(formatted.getTime()))
17
+ if (Number.isNaN(formatted.getTime())) {
9
18
  throw new GraphQLError(`Field '${columnName}' is not a valid date!`);
19
+ }
10
20
 
11
21
  return formatted;
12
22
  }
@@ -20,7 +30,9 @@ export const remapFromGraphQLCore = (value: any, column: Column, columnName: str
20
30
  }
21
31
 
22
32
  case 'json': {
23
- if (column.columnType === 'PgGeometryObject') return value;
33
+ if (column.columnType === 'PgGeometryObject') {
34
+ return value;
35
+ }
24
36
 
25
37
  try {
26
38
  return JSON.parse(value);
@@ -48,7 +60,7 @@ export const remapFromGraphQLCore = (value: any, column: Column, columnName: str
48
60
  case 'bigint': {
49
61
  try {
50
62
  return BigInt(value);
51
- } catch (error) {
63
+ } catch (_error) {
52
64
  throw new GraphQLError(`Field '${columnName}' is not a BigInt!`);
53
65
  }
54
66
  }
@@ -60,6 +72,7 @@ export const remapFromGraphQLCore = (value: any, column: Column, columnName: str
60
72
  };
61
73
 
62
74
  export const remapFromGraphQLSingleInput = (
75
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
63
76
  queryInput: Record<string, any>,
64
77
  table: TableRelationalConfig,
65
78
  ) => {
@@ -68,7 +81,9 @@ export const remapFromGraphQLSingleInput = (
68
81
  delete queryInput[key];
69
82
  } else {
70
83
  const column = table.columns[key];
71
- if (!column) throw new GraphQLError(`Unknown column: ${key}`);
84
+ if (!column) {
85
+ throw new GraphQLError(`Unknown column: ${key}`);
86
+ }
72
87
 
73
88
  if (value === null && column.notNull) {
74
89
  delete queryInput[key];
@@ -83,10 +98,13 @@ export const remapFromGraphQLSingleInput = (
83
98
  };
84
99
 
85
100
  export const remapFromGraphQLArrayInput = (
101
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
86
102
  queryInput: Record<string, any>[],
87
103
  table: TableRelationalConfig,
88
104
  ) => {
89
- for (const entry of queryInput) remapFromGraphQLSingleInput(entry, table);
105
+ for (const entry of queryInput) {
106
+ remapFromGraphQLSingleInput(entry, table);
107
+ }
90
108
 
91
109
  return queryInput;
92
110
  };
@@ -100,6 +118,7 @@ export type OrderByArgs<TTable extends TableRelationalConfig> = {
100
118
 
101
119
  export const extractOrderBy = <
102
120
  TTable extends TableRelationalConfig,
121
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
103
122
  TArgs extends OrderByArgs<any> = OrderByArgs<TTable>,
104
123
  >(
105
124
  table: TTable,
@@ -110,7 +129,9 @@ export const extractOrderBy = <
110
129
  for (const [column, config] of Object.entries(orderArgs).sort(
111
130
  (a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0),
112
131
  )) {
113
- if (!config) continue;
132
+ if (!config) {
133
+ continue;
134
+ }
114
135
  const { direction } = config;
115
136
 
116
137
  res.push(direction === 'asc' ? asc(table.columns[column]!) : desc(table.columns[column]!));
@@ -126,7 +147,10 @@ export const extractFiltersColumn = <TColumn extends Column>(
126
147
  columnName: string,
127
148
  operators: Record<string, unknown> & { OR?: Record<string, unknown>[] },
128
149
  ): SQL | undefined => {
129
- if (!operators.OR?.length) delete operators.OR;
150
+ if (!operators.OR?.length) {
151
+ // biome-ignore lint/performance/noDelete: <explanation>
152
+ delete operators.OR;
153
+ }
130
154
 
131
155
  const entries = Object.entries(operators);
132
156
 
@@ -142,6 +166,7 @@ export const extractFiltersColumn = <TColumn extends Column>(
142
166
  for (const variant of operators.OR) {
143
167
  const extracted = extractFiltersColumn(column, columnName, variant);
144
168
 
169
+ // biome-ignore lint/style/useBlockStatements: <explanation>
145
170
  if (extracted) variants.push(extracted);
146
171
  }
147
172
 
@@ -150,6 +175,7 @@ export const extractFiltersColumn = <TColumn extends Column>(
150
175
 
151
176
  const variants = [] as SQL[];
152
177
  for (const [operatorName, operatorValue] of entries) {
178
+ // biome-ignore lint/style/useBlockStatements: <explanation>
153
179
  if (operatorValue === null || operatorValue === false) continue;
154
180
 
155
181
  switch (operatorName) {
@@ -158,11 +184,12 @@ export const extractFiltersColumn = <TColumn extends Column>(
158
184
  case 'gt':
159
185
  case 'gte':
160
186
  case 'lt':
161
- case 'lte':
187
+ case 'lte': {
162
188
  const singleValue = remapFromGraphQLCore(operatorValue, column, columnName);
163
189
  variants.push(ops[operatorName](column, singleValue));
164
190
 
165
191
  break;
192
+ }
166
193
  case 'like':
167
194
  case 'notLike':
168
195
  case 'ilike':
@@ -170,18 +197,21 @@ export const extractFiltersColumn = <TColumn extends Column>(
170
197
  variants.push(ops[operatorName](column, operatorValue as string));
171
198
  break;
172
199
  case 'inArray':
173
- case 'notInArray':
200
+ case 'notInArray': {
201
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
174
202
  if (!(operatorValue as any[]).length) {
175
203
  throw new GraphQLError(
176
204
  `WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`,
177
205
  );
178
206
  }
207
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
179
208
  const arrayValue = (operatorValue as any[]).map((val) =>
180
209
  remapFromGraphQLCore(val, column, columnName),
181
210
  );
182
211
 
183
212
  variants.push(ops[operatorName](column, arrayValue));
184
213
  break;
214
+ }
185
215
  case 'isNull':
186
216
  case 'isNotNull':
187
217
  variants.push(ops[operatorName](column));
@@ -201,10 +231,15 @@ export const extractFilters = <TTable extends TableRelationalConfig>(
201
231
  OR?: Record<string, unknown>[];
202
232
  },
203
233
  ): SQL | undefined => {
204
- if (!filters.OR?.length) delete filters.OR;
234
+ if (!filters.OR?.length) {
235
+ // biome-ignore lint/performance/noDelete: <explanation>
236
+ delete filters.OR;
237
+ }
205
238
 
206
239
  const entries = Object.entries(filters);
207
- if (!entries.length) return;
240
+ if (!entries.length) {
241
+ return;
242
+ }
208
243
 
209
244
  if (filters.OR) {
210
245
  if (entries.length > 1) {
@@ -217,7 +252,9 @@ export const extractFilters = <TTable extends TableRelationalConfig>(
217
252
 
218
253
  for (const variant of filters.OR) {
219
254
  const extracted = extractFilters(table, tableName, variant);
220
- if (extracted) variants.push(extracted);
255
+ if (extracted) {
256
+ variants.push(extracted);
257
+ }
221
258
  }
222
259
 
223
260
  return variants.length ? (variants.length > 1 ? ops.or(...variants) : variants[0]) : undefined;
@@ -225,7 +262,9 @@ export const extractFilters = <TTable extends TableRelationalConfig>(
225
262
 
226
263
  const variants = [] as SQL[];
227
264
  for (const [columnName, operators] of entries) {
228
- if (operators === null) continue;
265
+ if (operators === null) {
266
+ continue;
267
+ }
229
268
 
230
269
  const column = table.columns[columnName]!;
231
270
  variants.push(extractFiltersColumn(column, columnName, operators as Record<string, unknown>)!);