@pothos/plugin-prisma 4.1.0 → 4.2.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 (171) hide show
  1. package/CHANGELOG.md +16 -4
  2. package/dts/connection-helpers.d.ts +2 -2
  3. package/dts/connection-helpers.d.ts.map +1 -1
  4. package/dts/global-types.d.ts +8 -8
  5. package/dts/global-types.d.ts.map +1 -1
  6. package/dts/index.d.ts +2 -2
  7. package/dts/index.d.ts.map +1 -1
  8. package/dts/interface-ref.d.ts +2 -2
  9. package/dts/interface-ref.d.ts.map +1 -1
  10. package/dts/model-loader.d.ts +4 -4
  11. package/dts/model-loader.d.ts.map +1 -1
  12. package/dts/node-ref.d.ts +1 -1
  13. package/dts/node-ref.d.ts.map +1 -1
  14. package/dts/object-ref.d.ts +1 -1
  15. package/dts/object-ref.d.ts.map +1 -1
  16. package/dts/prisma-field-builder.d.ts +6 -6
  17. package/dts/prisma-field-builder.d.ts.map +1 -1
  18. package/dts/types.d.ts +10 -10
  19. package/dts/types.d.ts.map +1 -1
  20. package/dts/util/cursors.d.ts +3 -3
  21. package/dts/util/cursors.d.ts.map +1 -1
  22. package/dts/util/datamodel.d.ts +3 -3
  23. package/dts/util/datamodel.d.ts.map +1 -1
  24. package/dts/util/deep-equal.d.ts.map +1 -1
  25. package/dts/util/description.d.ts +1 -1
  26. package/dts/util/description.d.ts.map +1 -1
  27. package/dts/util/get-client.d.ts +2 -2
  28. package/dts/util/get-client.d.ts.map +1 -1
  29. package/dts/util/loader-map.d.ts +2 -2
  30. package/dts/util/loader-map.d.ts.map +1 -1
  31. package/dts/util/map-query.d.ts +3 -3
  32. package/dts/util/map-query.d.ts.map +1 -1
  33. package/dts/util/relation-map.d.ts +1 -1
  34. package/dts/util/relation-map.d.ts.map +1 -1
  35. package/dts/util/selections.d.ts +2 -2
  36. package/dts/util/selections.d.ts.map +1 -1
  37. package/dts/util/usage.d.ts.map +1 -1
  38. package/esm/connection-helpers.d.ts +2 -2
  39. package/esm/connection-helpers.d.ts.map +1 -1
  40. package/esm/field-builder.js +6 -6
  41. package/esm/field-builder.js.map +1 -1
  42. package/esm/generator.js +5 -5
  43. package/esm/generator.js.map +1 -1
  44. package/esm/global-types.d.ts +8 -8
  45. package/esm/global-types.d.ts.map +1 -1
  46. package/esm/global-types.js +1 -1
  47. package/esm/global-types.js.map +1 -1
  48. package/esm/index.d.ts +2 -2
  49. package/esm/index.d.ts.map +1 -1
  50. package/esm/index.js +4 -4
  51. package/esm/index.js.map +1 -1
  52. package/esm/interface-ref.d.ts +2 -2
  53. package/esm/interface-ref.d.ts.map +1 -1
  54. package/esm/interface-ref.js.map +1 -1
  55. package/esm/model-loader.d.ts +4 -4
  56. package/esm/model-loader.d.ts.map +1 -1
  57. package/esm/model-loader.js +13 -15
  58. package/esm/model-loader.js.map +1 -1
  59. package/esm/node-ref.d.ts +1 -1
  60. package/esm/node-ref.d.ts.map +1 -1
  61. package/esm/object-ref.d.ts +1 -1
  62. package/esm/object-ref.d.ts.map +1 -1
  63. package/esm/object-ref.js +4 -2
  64. package/esm/object-ref.js.map +1 -1
  65. package/esm/prisma-field-builder.d.ts +6 -6
  66. package/esm/prisma-field-builder.d.ts.map +1 -1
  67. package/esm/prisma-field-builder.js +7 -8
  68. package/esm/prisma-field-builder.js.map +1 -1
  69. package/esm/schema-builder.js +1 -1
  70. package/esm/schema-builder.js.map +1 -1
  71. package/esm/types.d.ts +10 -10
  72. package/esm/types.d.ts.map +1 -1
  73. package/esm/types.js.map +1 -1
  74. package/esm/util/cursors.d.ts +3 -3
  75. package/esm/util/cursors.d.ts.map +1 -1
  76. package/esm/util/cursors.js +2 -2
  77. package/esm/util/cursors.js.map +1 -1
  78. package/esm/util/datamodel.d.ts +3 -3
  79. package/esm/util/datamodel.d.ts.map +1 -1
  80. package/esm/util/datamodel.js.map +1 -1
  81. package/esm/util/deep-equal.d.ts.map +1 -1
  82. package/esm/util/deep-equal.js +1 -1
  83. package/esm/util/deep-equal.js.map +1 -1
  84. package/esm/util/description.d.ts +1 -1
  85. package/esm/util/description.d.ts.map +1 -1
  86. package/esm/util/description.js +1 -1
  87. package/esm/util/description.js.map +1 -1
  88. package/esm/util/get-client.d.ts +2 -2
  89. package/esm/util/get-client.d.ts.map +1 -1
  90. package/esm/util/get-client.js +1 -1
  91. package/esm/util/get-client.js.map +1 -1
  92. package/esm/util/loader-map.d.ts +2 -2
  93. package/esm/util/loader-map.d.ts.map +1 -1
  94. package/esm/util/loader-map.js +4 -5
  95. package/esm/util/loader-map.js.map +1 -1
  96. package/esm/util/map-query.d.ts +3 -3
  97. package/esm/util/map-query.d.ts.map +1 -1
  98. package/esm/util/map-query.js +2 -3
  99. package/esm/util/map-query.js.map +1 -1
  100. package/esm/util/relation-map.d.ts +1 -1
  101. package/esm/util/relation-map.d.ts.map +1 -1
  102. package/esm/util/relation-map.js +12 -12
  103. package/esm/util/relation-map.js.map +1 -1
  104. package/esm/util/selections.d.ts +2 -2
  105. package/esm/util/selections.d.ts.map +1 -1
  106. package/esm/util/selections.js +9 -9
  107. package/esm/util/selections.js.map +1 -1
  108. package/esm/util/usage.d.ts.map +1 -1
  109. package/esm/util/usage.js +0 -1
  110. package/esm/util/usage.js.map +1 -1
  111. package/generated.d.ts +1 -1
  112. package/lib/field-builder.js +7 -5
  113. package/lib/field-builder.js.map +1 -1
  114. package/lib/generator.js +4 -4
  115. package/lib/generator.js.map +1 -1
  116. package/lib/global-types.js +1 -1
  117. package/lib/global-types.js.map +1 -1
  118. package/lib/index.js +4 -4
  119. package/lib/index.js.map +1 -1
  120. package/lib/interface-ref.js.map +1 -1
  121. package/lib/model-loader.js +12 -14
  122. package/lib/model-loader.js.map +1 -1
  123. package/lib/object-ref.js +3 -1
  124. package/lib/object-ref.js.map +1 -1
  125. package/lib/prisma-field-builder.js +6 -7
  126. package/lib/prisma-field-builder.js.map +1 -1
  127. package/lib/schema-builder.js +1 -1
  128. package/lib/schema-builder.js.map +1 -1
  129. package/lib/types.js.map +1 -1
  130. package/lib/util/cursors.js +2 -2
  131. package/lib/util/cursors.js.map +1 -1
  132. package/lib/util/datamodel.js.map +1 -1
  133. package/lib/util/deep-equal.js +1 -1
  134. package/lib/util/deep-equal.js.map +1 -1
  135. package/lib/util/description.js +1 -1
  136. package/lib/util/description.js.map +1 -1
  137. package/lib/util/get-client.js +1 -1
  138. package/lib/util/get-client.js.map +1 -1
  139. package/lib/util/loader-map.js +4 -5
  140. package/lib/util/loader-map.js.map +1 -1
  141. package/lib/util/map-query.js +2 -3
  142. package/lib/util/map-query.js.map +1 -1
  143. package/lib/util/relation-map.js +12 -12
  144. package/lib/util/relation-map.js.map +1 -1
  145. package/lib/util/selections.js +9 -9
  146. package/lib/util/selections.js.map +1 -1
  147. package/lib/util/usage.js +0 -1
  148. package/lib/util/usage.js.map +1 -1
  149. package/package.json +12 -12
  150. package/src/connection-helpers.ts +2 -2
  151. package/src/field-builder.ts +21 -13
  152. package/src/generator.ts +5 -8
  153. package/src/global-types.ts +35 -28
  154. package/src/index.ts +12 -11
  155. package/src/interface-ref.ts +2 -2
  156. package/src/model-loader.ts +17 -19
  157. package/src/node-ref.ts +1 -1
  158. package/src/object-ref.ts +5 -3
  159. package/src/prisma-field-builder.ts +58 -51
  160. package/src/schema-builder.ts +8 -8
  161. package/src/types.ts +64 -62
  162. package/src/util/cursors.ts +7 -8
  163. package/src/util/datamodel.ts +3 -3
  164. package/src/util/deep-equal.ts +0 -1
  165. package/src/util/description.ts +1 -2
  166. package/src/util/get-client.ts +2 -3
  167. package/src/util/loader-map.ts +6 -8
  168. package/src/util/map-query.ts +16 -19
  169. package/src/util/relation-map.ts +13 -13
  170. package/src/util/selections.ts +10 -12
  171. package/src/util/usage.ts +0 -2
@@ -1,17 +1,23 @@
1
- import { getNamedType, GraphQLResolveInfo, isInterfaceType, isObjectType, Kind } from 'graphql';
2
1
  import {
3
- FieldKind,
4
- FieldRef,
5
- InputFieldMap,
6
- isThenable,
7
- MaybePromise,
2
+ type FieldKind,
3
+ type FieldRef,
4
+ type InputFieldMap,
5
+ type MaybePromise,
8
6
  ObjectRef,
9
7
  PothosError,
10
8
  RootFieldBuilder,
11
- SchemaTypes,
9
+ type SchemaTypes,
10
+ isThenable,
12
11
  } from '@pothos/core';
12
+ import {
13
+ type GraphQLResolveInfo,
14
+ Kind,
15
+ getNamedType,
16
+ isInterfaceType,
17
+ isObjectType,
18
+ } from 'graphql';
13
19
  import { ModelLoader } from './model-loader';
14
- import { PrismaConnectionFieldOptions, PrismaModelTypes } from './types';
20
+ import type { PrismaConnectionFieldOptions, PrismaModelTypes } from './types';
15
21
  import { getCursorFormatter, getCursorParser, resolvePrismaCursorConnection } from './util/cursors';
16
22
  import { getRefFromModel } from './util/datamodel';
17
23
  import { queryFromInfo } from './util/map-query';
@@ -177,7 +183,9 @@ fieldBuilderProto.prismaConnection = function prismaConnection<
177
183
  },
178
184
  formatCursor,
179
185
  (q) => {
180
- if (totalCountOnly) return [];
186
+ if (totalCountOnly) {
187
+ return [];
188
+ }
181
189
 
182
190
  return checkIfQueryIsUsed(
183
191
  this.builder,
@@ -205,13 +213,13 @@ fieldBuilderProto.prismaConnection = function prismaConnection<
205
213
  extensions: {
206
214
  pothosPrismaTotalCount: true,
207
215
  },
208
- resolve: (parent, args, context) => parent.totalCount?.(),
216
+ resolve: (parent) => parent.totalCount?.(),
209
217
  }),
210
218
  ...(connectionOptions as { fields?: (t: unknown) => {} }).fields?.(t),
211
219
  })
212
220
  : (connectionOptions as { fields: undefined }).fields,
213
221
  extensions: {
214
- ...(connectionOptions as Record<string, {}> | undefined)?.extensions,
222
+ ...(connectionOptions as Record<string, object> | undefined)?.extensions,
215
223
  },
216
224
  },
217
225
  edgeOptions,
@@ -257,8 +265,8 @@ function checkIfQueryIsUsed<Types extends SchemaTypes, T>(
257
265
 
258
266
  if (onUnusedQuery === 'error') {
259
267
  throw new PothosError(message);
260
- } else if (onUnusedQuery === 'warn') {
261
- // eslint-disable-next-line no-console
268
+ }
269
+ if (onUnusedQuery === 'warn') {
262
270
  console.warn(message);
263
271
  }
264
272
  }
package/src/generator.ts CHANGED
@@ -1,11 +1,8 @@
1
- /* eslint-disable unicorn/prefer-module */
2
- /* eslint-disable no-magic-numbers */
3
- /* eslint-disable no-nested-ternary */
4
1
  import { mkdirSync, writeFileSync } from 'node:fs';
5
- import { dirname, join, resolve as resolvePath, posix } from 'node:path';
2
+ import { dirname, join, posix, resolve as resolvePath } from 'node:path';
3
+ import { type DMMF, generatorHandler } from '@prisma/generator-helper';
6
4
  import ts, { ListFormat, ScriptKind, ScriptTarget, SyntaxKind, version } from 'typescript';
7
- import { DMMF, generatorHandler } from '@prisma/generator-helper';
8
- import { PothosPrismaDatamodel } from './types';
5
+ import type { PothosPrismaDatamodel } from './types';
9
6
 
10
7
  const MIN_TS_VERSION = [4, 5, 2];
11
8
 
@@ -83,7 +80,7 @@ function trimDmmf(dmmf: DMMF.Document, documentation = false): PothosPrismaDatam
83
80
  },
84
81
  };
85
82
 
86
- dmmf.datamodel.models.forEach((model) => {
83
+ for (const model of dmmf.datamodel.models) {
87
84
  trimmed.datamodel.models[model.name] = {
88
85
  fields: model.fields.map((field) => ({
89
86
  type: field.type,
@@ -108,7 +105,7 @@ function trimDmmf(dmmf: DMMF.Document, documentation = false): PothosPrismaDatam
108
105
  })),
109
106
  documentation: documentation ? model.documentation : undefined,
110
107
  };
111
- });
108
+ }
112
109
 
113
110
  return trimmed;
114
111
  }
@@ -1,7 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /* eslint-disable @typescript-eslint/no-empty-interface */
3
- import { GraphQLResolveInfo } from 'graphql';
4
- import {
1
+ import type {
5
2
  FieldKind,
6
3
  FieldMap,
7
4
  FieldNullability,
@@ -15,24 +12,25 @@ import {
15
12
  ShapeFromTypeParam,
16
13
  TypeParam,
17
14
  } from '@pothos/core';
18
- import { PrismaInterfaceRef, PrismaRef } from './interface-ref';
19
- import { PrismaNodeRef } from './node-ref';
20
- import { prismaModelKey, PrismaObjectRef } from './object-ref';
21
- import { PrismaObjectFieldBuilder as InternalPrismaObjectFieldBuilder } from './prisma-field-builder';
15
+ import type { GraphQLResolveInfo } from 'graphql';
16
+ import type { PrismaInterfaceRef, PrismaRef } from './interface-ref';
17
+ import type { PrismaNodeRef } from './node-ref';
18
+ import type { PrismaObjectRef, prismaModelKey } from './object-ref';
19
+ import type { PrismaObjectFieldBuilder as InternalPrismaObjectFieldBuilder } from './prisma-field-builder';
22
20
  import {
23
- PrismaClient,
24
- PrismaConnectionFieldOptions,
25
- PrismaConnectionShape,
26
- PrismaFieldOptions,
27
- PrismaFieldWithInputOptions,
28
- PrismaInterfaceTypeOptions,
21
+ type PrismaClient,
22
+ type PrismaConnectionFieldOptions,
23
+ type PrismaConnectionShape,
24
+ type PrismaFieldOptions,
25
+ type PrismaFieldWithInputOptions,
26
+ type PrismaInterfaceTypeOptions,
27
+ type PrismaModelTypes,
28
+ type PrismaNodeOptions,
29
+ type PrismaObjectFieldOptions,
30
+ type PrismaObjectTypeOptions,
31
+ type ShapeFromConnection,
32
+ type ShapeFromSelection,
29
33
  prismaModelName,
30
- PrismaModelTypes,
31
- PrismaNodeOptions,
32
- PrismaObjectFieldOptions,
33
- PrismaObjectTypeOptions,
34
- ShapeFromConnection,
35
- ShapeFromSelection,
36
34
  } from './types';
37
35
 
38
36
  import type { PothosPrismaPlugin } from '.';
@@ -254,10 +252,11 @@ declare global {
254
252
  > {
255
253
  prismaField: <
256
254
  Args extends InputFieldMap,
257
- TypeParam extends
255
+ TypeParam extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
258
256
  | PrismaRef<any, PrismaModelTypes>
259
257
  | keyof Types['PrismaTypes']
260
258
  | [keyof Types['PrismaTypes']]
259
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
261
260
  | [PrismaRef<any, PrismaModelTypes>],
262
261
  Nullable extends FieldNullability<Type>,
263
262
  ResolveShape,
@@ -268,9 +267,11 @@ declare global {
268
267
  Model extends PrismaModelTypes = PrismaModelTypes &
269
268
  (TypeParam extends [keyof Types['PrismaTypes']]
270
269
  ? Types['PrismaTypes'][TypeParam[0]]
271
- : TypeParam extends [PrismaRef<any, PrismaModelTypes>]
270
+ : // biome-ignore lint/suspicious/noExplicitAny: <explanation>
271
+ TypeParam extends [PrismaRef<any, PrismaModelTypes>]
272
272
  ? TypeParam[0][typeof prismaModelKey]
273
- : TypeParam extends PrismaRef<any, PrismaModelTypes>
273
+ : // biome-ignore lint/suspicious/noExplicitAny: <explanation>
274
+ TypeParam extends PrismaRef<any, PrismaModelTypes>
274
275
  ? TypeParam[typeof prismaModelKey]
275
276
  : TypeParam extends keyof Types['PrismaTypes']
276
277
  ? Types['PrismaTypes'][TypeParam]
@@ -292,14 +293,17 @@ declare global {
292
293
 
293
294
  prismaConnection: 'relay' extends PluginName
294
295
  ? <
296
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
295
297
  Type extends PrismaRef<any, PrismaModelTypes> | keyof Types['PrismaTypes'],
296
298
  Nullable extends boolean,
297
299
  ResolveReturnShape,
298
300
  Args extends InputFieldMap = {},
299
- Model extends PrismaModelTypes = Type extends PrismaRef<Types, infer T>
301
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
302
+ Model extends PrismaModelTypes = Type extends PrismaRef<any, infer T>
300
303
  ? T
301
304
  : PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
302
- Shape = Type extends PrismaRef<Types, PrismaModelTypes, infer S> ? S : Model['Shape'],
305
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
306
+ Shape = Type extends PrismaRef<any, PrismaModelTypes, infer S> ? S : Model['Shape'],
303
307
  ConnectionInterfaces extends InterfaceParam<Types>[] = [],
304
308
  EdgeInterfaces extends InterfaceParam<Types>[] = [],
305
309
  >(
@@ -356,10 +360,11 @@ declare global {
356
360
  prismaFieldWithInput: 'withInput' extends PluginName
357
361
  ? <
358
362
  Fields extends InputFieldMap,
359
- TypeParam extends
363
+ TypeParam extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
360
364
  | PrismaRef<any, PrismaModelTypes>
361
365
  | keyof Types['PrismaTypes']
362
366
  | [keyof Types['PrismaTypes']]
367
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
363
368
  | [PrismaRef<any, PrismaModelTypes>],
364
369
  Type extends TypeParam extends [unknown]
365
370
  ? [ObjectRef<Types, Model['Shape']>]
@@ -373,9 +378,11 @@ declare global {
373
378
  Model extends PrismaModelTypes = PrismaModelTypes &
374
379
  (TypeParam extends [keyof Types['PrismaTypes']]
375
380
  ? Types['PrismaTypes'][TypeParam[0]]
376
- : TypeParam extends [PrismaRef<any, PrismaModelTypes>]
381
+ : // biome-ignore lint/suspicious/noExplicitAny: <explanation>
382
+ TypeParam extends [PrismaRef<any, PrismaModelTypes>]
377
383
  ? TypeParam[0][typeof prismaModelKey]
378
- : TypeParam extends PrismaRef<any, PrismaModelTypes>
384
+ : // biome-ignore lint/suspicious/noExplicitAny: <explanation>
385
+ TypeParam extends PrismaRef<any, PrismaModelTypes>
379
386
  ? TypeParam[typeof prismaModelKey]
380
387
  : TypeParam extends keyof Types['PrismaTypes']
381
388
  ? Types['PrismaTypes'][TypeParam]
package/src/index.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  import './global-types';
2
2
  import './schema-builder';
3
3
  import './field-builder';
4
- import { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql';
5
4
  import SchemaBuilder, {
6
5
  BasePlugin,
7
- BuildCache,
8
- PothosOutputFieldConfig,
6
+ type BuildCache,
7
+ type PothosOutputFieldConfig,
9
8
  PothosSchemaError,
10
- PothosTypeConfig,
11
- SchemaTypes,
9
+ type PothosTypeConfig,
10
+ type SchemaTypes,
12
11
  } from '@pothos/core';
13
- import { ModelLoader } from './model-loader';
12
+ // biome-ignore lint/style/useImportType: <explanation>
13
+ import { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql';
14
+ import type { ModelLoader } from './model-loader';
14
15
  import { PrismaObjectFieldBuilder as InternalPrismaObjectFieldBuilder } from './prisma-field-builder';
15
- import { PrismaModelTypes } from './types';
16
+ import type { PrismaModelTypes } from './types';
16
17
  import { formatPrismaCursor, parsePrismaCursor } from './util/cursors';
17
18
  import { getModel, getRefFromModel } from './util/datamodel';
18
19
  import { getLoaderMapping, setLoaderMappings } from './util/loader-map';
@@ -56,7 +57,7 @@ export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Ty
56
57
 
57
58
  let model = typeConfig.extensions?.pothosPrismaModel as string | undefined;
58
59
 
59
- typeConfig.interfaces.forEach((iface) => {
60
+ for (const iface of typeConfig.interfaces) {
60
61
  const interfaceModel = this.buildCache.getTypeConfig(iface, 'Interface').extensions
61
62
  ?.pothosPrismaModel as string | undefined;
62
63
 
@@ -69,7 +70,7 @@ export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Ty
69
70
 
70
71
  model = interfaceModel;
71
72
  }
72
- });
73
+ }
73
74
 
74
75
  return {
75
76
  ...typeConfig,
@@ -133,12 +134,12 @@ export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Ty
133
134
  const parentTypes = new Set([fieldConfig.parentType]);
134
135
 
135
136
  if (parentConfig.kind === 'Interface' || parentConfig.kind === 'Object') {
136
- parentConfig.interfaces.forEach((iface) => {
137
+ for (const iface of parentConfig.interfaces) {
137
138
  const interfaceConfig = this.buildCache.getTypeConfig(iface, 'Interface');
138
139
  if (interfaceConfig.extensions?.pothosPrismaModel) {
139
140
  parentTypes.add(interfaceConfig.name);
140
141
  }
141
- });
142
+ }
142
143
  }
143
144
 
144
145
  return (parent, args, context, info) => {
@@ -1,5 +1,5 @@
1
- import { InterfaceRef, SchemaTypes } from '@pothos/core';
2
- import { prismaModelKey, PrismaObjectRef } from './object-ref';
1
+ import { InterfaceRef, type SchemaTypes } from '@pothos/core';
2
+ import { type PrismaObjectRef, prismaModelKey } from './object-ref';
3
3
  import type { PrismaModelTypes } from './types';
4
4
 
5
5
  export type PrismaRef<Types extends SchemaTypes, Model extends PrismaModelTypes, T = {}> =
@@ -1,20 +1,20 @@
1
- import { GraphQLResolveInfo } from 'graphql';
2
1
  import {
3
- createContextCache,
4
- InterfaceRef,
5
- ObjectRef,
2
+ type InterfaceRef,
3
+ type ObjectRef,
6
4
  PothosSchemaError,
7
- SchemaTypes,
5
+ type SchemaTypes,
6
+ createContextCache,
8
7
  } from '@pothos/core';
9
- import { PrismaDelegate, SelectionMap } from './types';
8
+ import type { GraphQLResolveInfo } from 'graphql';
9
+ import type { PrismaDelegate, SelectionMap } from './types';
10
10
  import { getDelegateFromModel, getModel } from './util/datamodel';
11
11
  import { getClient } from './util/get-client';
12
12
  import { cacheKey, setLoaderMappings } from './util/loader-map';
13
13
  import { selectionStateFromInfo } from './util/map-query';
14
14
  import {
15
+ type SelectionState,
15
16
  mergeSelection,
16
17
  selectionCompatible,
17
- SelectionState,
18
18
  selectionToQuery,
19
19
  } from './util/selections';
20
20
 
@@ -75,7 +75,7 @@ export class ModelLoader {
75
75
  ? () => {
76
76
  throw new PothosSchemaError(`Missing findUnique for ${ref.name}`);
77
77
  }
78
- : findUnique ?? this.getDefaultFindUnique(ref, modelName, builder),
78
+ : findUnique ?? ModelLoader.getDefaultFindUnique(ref, modelName, builder),
79
79
  ),
80
80
  );
81
81
  }
@@ -147,9 +147,9 @@ export class ModelLoader {
147
147
  modelName: string,
148
148
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
149
149
  ): (model: Record<string, unknown>) => {} {
150
- const findBy = this.getDefaultFindBy(ref, modelName, builder);
150
+ const findBy = ModelLoader.getDefaultFindBy(ref, modelName, builder);
151
151
 
152
- return this.getFindUnique(findBy);
152
+ return ModelLoader.getFindUnique(findBy);
153
153
  }
154
154
 
155
155
  static getDefaultIDSelection<Types extends SchemaTypes>(
@@ -157,7 +157,7 @@ export class ModelLoader {
157
157
  modelName: string,
158
158
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
159
159
  ): Record<string, boolean> {
160
- const findBy = this.getDefaultFindBy(ref, modelName, builder);
160
+ const findBy = ModelLoader.getDefaultFindBy(ref, modelName, builder);
161
161
 
162
162
  if (typeof findBy === 'string') {
163
163
  return { [findBy]: true };
@@ -236,7 +236,7 @@ export class ModelLoader {
236
236
  throw new PothosSchemaError(`Unable to find field or index for ${fieldName} of ${ref.name}`);
237
237
  }
238
238
 
239
- return this.getFindUnique(findBy);
239
+ return ModelLoader.getFindUnique(findBy);
240
240
  }
241
241
 
242
242
  getSelection(info: GraphQLResolveInfo) {
@@ -277,7 +277,7 @@ export class ModelLoader {
277
277
  entry.models.set(model, createResolvablePromise<Record<string, unknown> | null>());
278
278
  }
279
279
 
280
- return entry.models.get(model)!.promise;
280
+ return await entry.models.get(model)!.promise;
281
281
  }
282
282
  }
283
283
 
@@ -298,31 +298,29 @@ export class ModelLoader {
298
298
  this.staged.add(entry);
299
299
 
300
300
  const nextTick = createResolvablePromise<void>();
301
- void this.tick.then(() => {
301
+ this.tick.then(() => {
302
302
  this.staged.delete(entry);
303
303
 
304
304
  for (const [model, { resolve, reject }] of entry.models) {
305
305
  if (this.delegate.findUniqueOrThrow) {
306
- void this.delegate
306
+ this.delegate
307
307
  .findUniqueOrThrow({
308
308
  ...selectionToQuery(state),
309
309
  where: { ...(this.findUnique(model as Record<string, unknown>, this.context) as {}) },
310
310
  } as never)
311
- // eslint-disable-next-line promise/no-nesting
312
311
  .then(resolve as () => {}, reject);
313
312
  } else {
314
- void this.delegate
313
+ this.delegate
315
314
  .findUnique({
316
315
  rejectOnNotFound: true,
317
316
  ...selectionToQuery(state),
318
317
  where: { ...(this.findUnique(model as Record<string, unknown>, this.context) as {}) },
319
318
  } as never)
320
- // eslint-disable-next-line promise/no-nesting
321
319
  .then(resolve as () => {}, reject);
322
320
  }
323
321
  }
324
322
  });
325
- setTimeout(() => void nextTick.resolve(), 0);
323
+ setTimeout(() => nextTick.resolve(), 0);
326
324
  this.tick = nextTick.promise;
327
325
 
328
326
  return promise.promise;
package/src/node-ref.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SchemaTypes } from '@pothos/core';
1
+ import type { SchemaTypes } from '@pothos/core';
2
2
  import { PrismaObjectRef } from './object-ref';
3
3
  import type { PrismaModelTypes } from './types';
4
4
 
package/src/object-ref.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
+ ObjectRef,
3
+ type SchemaTypes,
2
4
  abstractReturnShapeKey,
3
5
  brandWithType,
4
- ObjectRef,
5
- SchemaTypes,
6
6
  typeBrandKey,
7
7
  } from '@pothos/core';
8
8
  import type { PrismaModelTypes, WithBrand } from './types';
@@ -30,7 +30,9 @@ export class PrismaObjectRef<
30
30
  value: V,
31
31
  ): V extends T[] ? { [K in keyof V]: WithBrand<V[K]> } : WithBrand<V> {
32
32
  if (Array.isArray(value)) {
33
- value.forEach((val) => void brandWithType(val, this.name as never));
33
+ for (const val of value) {
34
+ brandWithType(val, this.name as never);
35
+ }
34
36
 
35
37
  return value as never;
36
38
  }
@@ -1,34 +1,32 @@
1
- /* eslint-disable no-nested-ternary */
2
- /* eslint-disable no-underscore-dangle */
3
1
  import {
4
- FieldNode,
2
+ type CompatibleTypes,
3
+ type ExposeNullability,
4
+ type FieldKind,
5
+ type FieldRef,
6
+ type InferredFieldOptionKeys,
7
+ type InputFieldMap,
8
+ type InterfaceParam,
9
+ type MaybePromise,
10
+ type NormalizeArgs,
11
+ ObjectRef,
12
+ type PluginName,
13
+ RootFieldBuilder,
14
+ type SchemaTypes,
15
+ type ShapeFromTypeParam,
16
+ type TypeParam,
17
+ isThenable,
18
+ } from '@pothos/core';
19
+ import {
20
+ type FieldNode,
21
+ type GraphQLResolveInfo,
22
+ Kind,
5
23
  getNamedType,
6
- GraphQLResolveInfo,
7
24
  isInterfaceType,
8
25
  isObjectType,
9
- Kind,
10
26
  } from 'graphql';
11
- import {
12
- CompatibleTypes,
13
- ExposeNullability,
14
- FieldKind,
15
- FieldRef,
16
- InferredFieldOptionKeys,
17
- InputFieldMap,
18
- InterfaceParam,
19
- isThenable,
20
- MaybePromise,
21
- NormalizeArgs,
22
- ObjectRef,
23
- PluginName,
24
- RootFieldBuilder,
25
- SchemaTypes,
26
- ShapeFromTypeParam,
27
- TypeParam,
28
- } from '@pothos/core';
29
- import { PrismaRef } from './interface-ref';
27
+ import type { PrismaRef } from './interface-ref';
30
28
  import { ModelLoader } from './model-loader';
31
- import {
29
+ import type {
32
30
  PrismaConnectionShape,
33
31
  PrismaModelTypes,
34
32
  RelatedConnectionOptions,
@@ -47,11 +45,11 @@ import {
47
45
  } from './util/cursors';
48
46
  import { getRefFromModel, getRelation } from './util/datamodel';
49
47
  import { getFieldDescription } from './util/description';
50
- import { FieldMap } from './util/relation-map';
48
+ import type { FieldMap } from './util/relation-map';
51
49
 
52
50
  // Workaround for FieldKind not being extended on Builder classes
53
51
  const RootBuilder: {
54
- // eslint-disable-next-line @typescript-eslint/prefer-function-type
52
+ // biome-ignore lint/suspicious/noRedeclare: <explanation>
55
53
  new <Types extends SchemaTypes, Shape, Kind extends FieldKind>(
56
54
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
57
55
  kind: FieldKind,
@@ -59,21 +57,26 @@ const RootBuilder: {
59
57
  ): PothosSchemaTypes.RootFieldBuilder<Types, Shape, Kind>;
60
58
  } = RootFieldBuilder as never;
61
59
 
62
- type ContextForAuth<Types extends SchemaTypes, Scopes extends {} = {}> =
63
- PothosSchemaTypes.ScopeAuthContextForAuth<Types, Scopes> extends {
64
- Context: infer T;
65
- }
66
- ? T extends object
67
- ? T
68
- : object
69
- : object;
70
-
71
- type FieldAuthScopes<Types extends SchemaTypes, Parent, Args extends {} = {}> =
72
- PothosSchemaTypes.ScopeAuthFieldAuthScopes<Types, Parent, Args> extends {
73
- Scopes: infer T;
74
- }
60
+ type ContextForAuth<
61
+ Types extends SchemaTypes,
62
+ Scopes extends {} = {},
63
+ > = PothosSchemaTypes.ScopeAuthContextForAuth<Types, Scopes> extends {
64
+ Context: infer T;
65
+ }
66
+ ? T extends object
75
67
  ? T
76
- : never;
68
+ : object
69
+ : object;
70
+
71
+ type FieldAuthScopes<
72
+ Types extends SchemaTypes,
73
+ Parent,
74
+ Args extends {} = {},
75
+ > = PothosSchemaTypes.ScopeAuthFieldAuthScopes<Types, Parent, Args> extends {
76
+ Scopes: infer T;
77
+ }
78
+ ? T
79
+ : never;
77
80
 
78
81
  export class PrismaObjectFieldBuilder<
79
82
  Types extends SchemaTypes,
@@ -285,7 +288,7 @@ export class PrismaObjectFieldBuilder<
285
288
  const relationSelect = (
286
289
  args: object,
287
290
  context: object,
288
- nestedQuery: (query: unknown, path?: unknown) => { select?: {} },
291
+ nestedQuery: (query: unknown, path?: unknown) => { select?: object },
289
292
  getSelection: (path: string[]) => FieldNode | null,
290
293
  ) => {
291
294
  typeName ??= this.builder.configStore.getTypeConfig(ref).name;
@@ -407,7 +410,7 @@ export class PrismaObjectFieldBuilder<
407
410
  extensions: {
408
411
  pothosPrismaTotalCount: true,
409
412
  },
410
- resolve: (parent, args, context) => parent.totalCount,
413
+ resolve: (parent, _args, _context) => parent.totalCount,
411
414
  }),
412
415
  ...(connectionOptions as { fields?: (t: unknown) => {} }).fields?.(t),
413
416
  })
@@ -454,8 +457,8 @@ export class PrismaObjectFieldBuilder<
454
457
  const { query = {}, resolve, extensions, onNull, ...rest } = options;
455
458
 
456
459
  const relationSelect = (
457
- args: object,
458
- context: object,
460
+ _args: object,
461
+ _context: object,
459
462
  nestedQuery: (query: unknown) => unknown,
460
463
  ) => ({ select: { [name]: nestedQuery(query) } });
461
464
 
@@ -527,13 +530,14 @@ export class PrismaObjectFieldBuilder<
527
530
  type: 'Int',
528
531
  nullable: false,
529
532
  select: countSelect as never,
530
- resolve: (parent, args, context, info) =>
533
+ resolve: (parent, _args, _context, _info) =>
531
534
  (parent as unknown as { _count: Record<string, never> })._count?.[name],
532
535
  }) as FieldRef<Types, number, 'Object'>;
533
536
  }
534
537
 
535
538
  variant<
536
- Variant extends Model['Name'] | PrismaRef<Types, Model>,
539
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
540
+ Variant extends Model['Name'] | PrismaRef<any, Model>,
537
541
  Args extends InputFieldMap,
538
542
  Nullable,
539
543
  >(
@@ -543,7 +547,8 @@ export class PrismaObjectFieldBuilder<
543
547
  options: VariantFieldOptions<
544
548
  Types,
545
549
  Model,
546
- Variant extends PrismaRef<Types, Model> ? Variant : PrismaRef<Types, Model>,
550
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
551
+ Variant extends PrismaRef<any, Model> ? Variant : PrismaRef<Types, Model>,
547
552
  Args,
548
553
  Nullable,
549
554
  Shape
@@ -555,8 +560,11 @@ export class PrismaObjectFieldBuilder<
555
560
  const ref: PrismaRef<Types, PrismaModelTypes> =
556
561
  typeof variant === 'string' ? getRefFromModel(variant, this.builder) : variant;
557
562
 
558
- const selfSelect = (args: object, context: object, nestedQuery: (query: unknown) => unknown) =>
559
- nestedQuery({});
563
+ const selfSelect = (
564
+ _args: object,
565
+ _context: object,
566
+ nestedQuery: (query: unknown) => unknown,
567
+ ) => nestedQuery({});
560
568
 
561
569
  return this.field({
562
570
  ...(options as {}),
@@ -680,7 +688,6 @@ function addScopes(
680
688
  ) {
681
689
  const originalCreateField = builder.createField;
682
690
 
683
- // eslint-disable-next-line no-param-reassign
684
691
  builder.createField = function createField(options) {
685
692
  return originalCreateField.call(this, {
686
693
  authScopes: scopes,
@@ -1,20 +1,20 @@
1
1
  import './global-types';
2
- import { GraphQLResolveInfo } from 'graphql';
3
2
  import SchemaBuilder, {
4
3
  brandWithType,
5
4
  completeValue,
6
- FieldRef,
7
- InterfaceRef,
8
- OutputType,
5
+ type FieldRef,
6
+ type InterfaceRef,
7
+ type OutputType,
9
8
  PothosError,
10
- SchemaTypes,
9
+ type SchemaTypes,
11
10
  } from '@pothos/core';
11
+ import type { GraphQLResolveInfo } from 'graphql';
12
12
  import { PrismaInterfaceRef } from './interface-ref';
13
13
  import { ModelLoader } from './model-loader';
14
14
  import { PrismaNodeRef } from './node-ref';
15
15
  import { PrismaObjectRef } from './object-ref';
16
16
  import { PrismaObjectFieldBuilder } from './prisma-field-builder';
17
- import { PrismaModelTypes, PrismaNodeOptions } from './types';
17
+ import type { PrismaModelTypes, PrismaNodeOptions } from './types';
18
18
  import { getDefaultIDParser, getDefaultIDSerializer } from './util/cursors';
19
19
  import { getDelegateFromModel, getRefFromModel } from './util/datamodel';
20
20
  import { getModelDescription } from './util/description';
@@ -187,12 +187,12 @@ schemaBuilderProto.prismaNode = function prismaNode(
187
187
  globalID: (options: Record<string, unknown>) => FieldRef<SchemaTypes, unknown>;
188
188
  }
189
189
  ).globalID({
190
- ...(this.options as { relayOptions?: { idFieldOptions?: {} } }).relayOptions
190
+ ...(this.options as { relayOptions?: { idFieldOptions?: object } }).relayOptions
191
191
  ?.idFieldOptions,
192
192
  ...idOptions,
193
193
  nullable: false,
194
194
  args: {},
195
- resolve: (parent: never, args: object, context: object, info: GraphQLResolveInfo) =>
195
+ resolve: (parent: never, _args: object, context: object) =>
196
196
  completeValue(resolve(parent, context), (id) => ({
197
197
  type: nodeConfig.name,
198
198
  id,