@pothos/plugin-prisma 3.58.0 → 3.59.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 (70) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dts/connection-helpers.d.ts +6 -6
  3. package/dts/connection-helpers.d.ts.map +1 -1
  4. package/dts/global-types.d.ts +13 -13
  5. package/dts/global-types.d.ts.map +1 -1
  6. package/dts/index.d.ts.map +1 -1
  7. package/dts/interface-ref.d.ts +1 -1
  8. package/dts/interface-ref.d.ts.map +1 -1
  9. package/dts/model-loader.d.ts +32 -13
  10. package/dts/model-loader.d.ts.map +1 -1
  11. package/dts/object-ref.d.ts.map +1 -1
  12. package/dts/prisma-field-builder.d.ts +18 -18
  13. package/dts/prisma-field-builder.d.ts.map +1 -1
  14. package/dts/types.d.ts +30 -30
  15. package/dts/types.d.ts.map +1 -1
  16. package/dts/util/loader-map.d.ts +1 -1
  17. package/dts/util/loader-map.d.ts.map +1 -1
  18. package/dts/util/map-query.d.ts +2 -2
  19. package/dts/util/map-query.d.ts.map +1 -1
  20. package/esm/connection-helpers.d.ts +6 -6
  21. package/esm/connection-helpers.d.ts.map +1 -1
  22. package/esm/global-types.d.ts +13 -13
  23. package/esm/global-types.d.ts.map +1 -1
  24. package/esm/index.d.ts.map +1 -1
  25. package/esm/index.js +2 -9
  26. package/esm/index.js.map +1 -1
  27. package/esm/interface-ref.d.ts +1 -1
  28. package/esm/interface-ref.d.ts.map +1 -1
  29. package/esm/interface-ref.js.map +1 -1
  30. package/esm/model-loader.d.ts +32 -13
  31. package/esm/model-loader.d.ts.map +1 -1
  32. package/esm/model-loader.js +82 -27
  33. package/esm/model-loader.js.map +1 -1
  34. package/esm/object-ref.d.ts.map +1 -1
  35. package/esm/object-ref.js.map +1 -1
  36. package/esm/prisma-field-builder.d.ts +28 -28
  37. package/esm/prisma-field-builder.d.ts.map +1 -1
  38. package/esm/prisma-field-builder.js.map +1 -1
  39. package/esm/types.d.ts +30 -30
  40. package/esm/types.d.ts.map +1 -1
  41. package/esm/util/loader-map.d.ts +1 -1
  42. package/esm/util/loader-map.d.ts.map +1 -1
  43. package/esm/util/loader-map.js +1 -1
  44. package/esm/util/loader-map.js.map +1 -1
  45. package/esm/util/map-query.d.ts +2 -2
  46. package/esm/util/map-query.d.ts.map +1 -1
  47. package/esm/util/map-query.js +10 -2
  48. package/esm/util/map-query.js.map +1 -1
  49. package/lib/index.js +1 -8
  50. package/lib/index.js.map +1 -1
  51. package/lib/interface-ref.js.map +1 -1
  52. package/lib/model-loader.js +81 -27
  53. package/lib/model-loader.js.map +1 -1
  54. package/lib/object-ref.js.map +1 -1
  55. package/lib/prisma-field-builder.js.map +1 -1
  56. package/lib/util/loader-map.js +1 -1
  57. package/lib/util/loader-map.js.map +1 -1
  58. package/lib/util/map-query.js +9 -1
  59. package/lib/util/map-query.js.map +1 -1
  60. package/package.json +6 -6
  61. package/src/connection-helpers.ts +5 -5
  62. package/src/global-types.ts +11 -11
  63. package/src/index.ts +8 -18
  64. package/src/interface-ref.ts +3 -2
  65. package/src/model-loader.ts +118 -41
  66. package/src/object-ref.ts +2 -0
  67. package/src/prisma-field-builder.ts +42 -32
  68. package/src/types.ts +52 -50
  69. package/src/util/loader-map.ts +1 -1
  70. package/src/util/map-query.ts +16 -3
@@ -1,3 +1,4 @@
1
+ import { GraphQLResolveInfo } from 'graphql';
1
2
  import {
2
3
  createContextCache,
3
4
  InterfaceRef,
@@ -5,8 +6,11 @@ import {
5
6
  PothosSchemaError,
6
7
  SchemaTypes,
7
8
  } from '@pothos/core';
9
+ import { PrismaDelegate, SelectionMap } from './types';
8
10
  import { getDelegateFromModel, getModel } from './util/datamodel';
9
11
  import { getClient } from './util/get-client';
12
+ import { cacheKey, setLoaderMappings } from './util/loader-map';
13
+ import { selectionStateFromInfo } from './util/map-query';
10
14
  import {
11
15
  mergeSelection,
12
16
  selectionCompatible,
@@ -14,31 +18,49 @@ import {
14
18
  selectionToQuery,
15
19
  } from './util/selections';
16
20
 
21
+ interface ResolvablePromise<T> {
22
+ promise: Promise<T>;
23
+ resolve: (value: T) => void;
24
+ reject: (err: unknown) => void;
25
+ }
17
26
  export class ModelLoader {
18
- model: object;
27
+ context: object;
28
+
19
29
  builder: PothosSchemaTypes.SchemaBuilder<never>;
30
+
20
31
  findUnique: (model: Record<string, unknown>, ctx: {}) => unknown;
32
+
21
33
  modelName: string;
22
34
 
35
+ queryCache = new Map<string, { selection: SelectionState; query: SelectionMap }>();
36
+
23
37
  staged = new Set<{
24
- promise: Promise<Record<string, unknown>>;
25
38
  state: SelectionState;
39
+ models: Map<object, ResolvablePromise<Record<string, unknown> | null>>;
26
40
  }>();
27
41
 
42
+ delegate: PrismaDelegate;
43
+
44
+ tick = Promise.resolve();
45
+
28
46
  constructor(
29
- model: object,
47
+ context: object,
30
48
  builder: PothosSchemaTypes.SchemaBuilder<never>,
31
49
  modelName: string,
32
50
  findUnique: (model: Record<string, unknown>, ctx: {}) => unknown,
33
51
  ) {
34
- this.model = model;
52
+ this.context = context;
35
53
  this.builder = builder;
36
54
  this.findUnique = findUnique;
37
55
  this.modelName = modelName;
56
+ this.delegate = getDelegateFromModel(
57
+ getClient(this.builder, this.context as never),
58
+ this.modelName,
59
+ );
38
60
  }
39
61
 
40
62
  static forRef<Types extends SchemaTypes>(
41
- ref: ObjectRef<unknown> | InterfaceRef<unknown>,
63
+ ref: InterfaceRef<unknown> | ObjectRef<unknown>,
42
64
  modelName: string,
43
65
  findUnique: ((model: Record<string, unknown>, ctx: {}) => unknown) | undefined,
44
66
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
@@ -60,11 +82,11 @@ export class ModelLoader {
60
82
 
61
83
  static getFindUnique(
62
84
  findBy:
85
+ | string
63
86
  | {
64
87
  name: string | null;
65
88
  fields: string[];
66
- }
67
- | string,
89
+ },
68
90
  ): (model: Record<string, unknown>) => {} {
69
91
  if (typeof findBy === 'string') {
70
92
  return (parent) => ({ [findBy]: parent[findBy] });
@@ -84,7 +106,7 @@ export class ModelLoader {
84
106
  }
85
107
 
86
108
  static getDefaultFindBy<Types extends SchemaTypes>(
87
- ref: ObjectRef<unknown> | InterfaceRef<unknown>,
109
+ ref: InterfaceRef<unknown> | ObjectRef<unknown>,
88
110
  modelName: string,
89
111
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
90
112
  ) {
@@ -96,11 +118,11 @@ export class ModelLoader {
96
118
  );
97
119
 
98
120
  let findBy:
121
+ | string
99
122
  | {
100
123
  name: string | null;
101
124
  fields: string[];
102
125
  }
103
- | string
104
126
  | undefined;
105
127
 
106
128
  if (model.primaryKey) {
@@ -121,7 +143,7 @@ export class ModelLoader {
121
143
  }
122
144
 
123
145
  static getDefaultFindUnique<Types extends SchemaTypes>(
124
- ref: ObjectRef<unknown> | InterfaceRef<unknown>,
146
+ ref: InterfaceRef<unknown> | ObjectRef<unknown>,
125
147
  modelName: string,
126
148
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
127
149
  ): (model: Record<string, unknown>) => {} {
@@ -131,7 +153,7 @@ export class ModelLoader {
131
153
  }
132
154
 
133
155
  static getDefaultIDSelection<Types extends SchemaTypes>(
134
- ref: ObjectRef<unknown> | InterfaceRef<unknown>,
156
+ ref: InterfaceRef<unknown> | ObjectRef<unknown>,
135
157
  modelName: string,
136
158
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
137
159
  ): Record<string, boolean> {
@@ -151,7 +173,7 @@ export class ModelLoader {
151
173
  }
152
174
 
153
175
  static getCursorSelection<Types extends SchemaTypes>(
154
- ref: ObjectRef<unknown> | InterfaceRef<unknown>,
176
+ ref: InterfaceRef<unknown> | ObjectRef<unknown>,
155
177
  modelName: string,
156
178
  cursor: string,
157
179
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
@@ -180,7 +202,7 @@ export class ModelLoader {
180
202
  }
181
203
 
182
204
  static getFindUniqueForField<Types extends SchemaTypes>(
183
- ref: ObjectRef<unknown> | InterfaceRef<unknown>,
205
+ ref: InterfaceRef<unknown> | ObjectRef<unknown>,
184
206
  modelName: string,
185
207
  fieldName: string,
186
208
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
@@ -192,11 +214,11 @@ export class ModelLoader {
192
214
  );
193
215
 
194
216
  let findBy:
217
+ | string
195
218
  | {
196
219
  name: string | null;
197
220
  fields: string[];
198
221
  }
199
- | string
200
222
  | undefined;
201
223
 
202
224
  if (model.fields.some((field) => field.name === fieldName)) {
@@ -217,48 +239,103 @@ export class ModelLoader {
217
239
  return this.getFindUnique(findBy);
218
240
  }
219
241
 
220
- async loadSelection(selection: SelectionState, context: object) {
221
- const query = selectionToQuery(selection);
242
+ getSelection(info: GraphQLResolveInfo) {
243
+ const key = cacheKey(info.parentType.name, info.path);
244
+ if (!this.queryCache.has(key)) {
245
+ const selection = selectionStateFromInfo(this.context, info);
246
+ this.queryCache.set(key, {
247
+ selection,
248
+ query: selectionToQuery(selection),
249
+ });
250
+ }
251
+
252
+ return this.queryCache.get(key)!;
253
+ }
254
+
255
+ async loadSelection(info: GraphQLResolveInfo, model: object) {
256
+ const { selection, query } = this.getSelection(info);
257
+
258
+ const result = await this.stageQuery(selection, query, model);
222
259
 
260
+ if (result) {
261
+ const mappings = selection.mappings[info.path.key];
262
+
263
+ if (mappings) {
264
+ setLoaderMappings(this.context, info, mappings.mappings);
265
+ }
266
+ }
267
+
268
+ return result;
269
+ }
270
+
271
+ async stageQuery(selection: SelectionState, query: SelectionMap, model: object) {
223
272
  for (const entry of this.staged) {
224
273
  if (selectionCompatible(entry.state, query)) {
225
274
  mergeSelection(entry.state, query);
226
275
 
227
- return entry.promise;
276
+ if (!entry.models.has(model)) {
277
+ entry.models.set(model, createResolvablePromise<Record<string, unknown> | null>());
278
+ }
279
+
280
+ return entry.models.get(model)!.promise;
228
281
  }
229
282
  }
230
283
 
231
- return this.initLoad(selection, context);
284
+ return this.initLoad(selection, model);
232
285
  }
233
286
 
234
- async initLoad(state: SelectionState, context: {}) {
235
- const entry = {
236
- promise: Promise.resolve().then(() => {
237
- this.staged.delete(entry);
238
-
239
- const delegate = getDelegateFromModel(
240
- getClient(this.builder, context as never),
241
- this.modelName,
242
- );
243
-
244
- if (delegate.findUniqueOrThrow) {
245
- return delegate.findUniqueOrThrow({
246
- ...selectionToQuery(state),
247
- where: { ...(this.findUnique(this.model as Record<string, unknown>, context) as {}) },
248
- } as never) as Promise<Record<string, unknown>>;
249
- }
287
+ async initLoad(state: SelectionState, initialModel: {}) {
288
+ const models = new Map<object, ResolvablePromise<Record<string, unknown> | null>>();
289
+
290
+ const promise = createResolvablePromise<Record<string, unknown> | null>();
291
+ models.set(initialModel, promise);
250
292
 
251
- return delegate.findUnique({
252
- rejectOnNotFound: true,
253
- ...selectionToQuery(state),
254
- where: { ...(this.findUnique(this.model as Record<string, unknown>, context) as {}) },
255
- } as never) as Promise<Record<string, unknown>>;
256
- }),
293
+ const entry = {
294
+ models,
257
295
  state,
258
296
  };
259
297
 
260
298
  this.staged.add(entry);
261
299
 
262
- return entry.promise;
300
+ const nextTick = createResolvablePromise<void>();
301
+ void this.tick.then(() => {
302
+ this.staged.delete(entry);
303
+
304
+ for (const [model, { resolve, reject }] of entry.models) {
305
+ if (this.delegate.findUniqueOrThrow) {
306
+ void this.delegate
307
+ .findUniqueOrThrow({
308
+ ...selectionToQuery(state),
309
+ where: { ...(this.findUnique(model as Record<string, unknown>, this.context) as {}) },
310
+ } as never)
311
+ // eslint-disable-next-line promise/no-nesting
312
+ .then(resolve as () => {}, reject);
313
+ } else {
314
+ void this.delegate
315
+ .findUnique({
316
+ rejectOnNotFound: true,
317
+ ...selectionToQuery(state),
318
+ where: { ...(this.findUnique(model as Record<string, unknown>, this.context) as {}) },
319
+ } as never)
320
+ // eslint-disable-next-line promise/no-nesting
321
+ .then(resolve as () => {}, reject);
322
+ }
323
+ }
324
+ });
325
+ setTimeout(() => void nextTick.resolve(), 0);
326
+ this.tick = nextTick.promise;
327
+
328
+ return promise.promise;
263
329
  }
264
330
  }
331
+
332
+ function createResolvablePromise<T = unknown>(): ResolvablePromise<T> {
333
+ let resolveFn!: (value: T) => void;
334
+ let rejectFn!: (reason?: unknown) => void;
335
+ const promise = new Promise<T>((resolve, reject) => {
336
+ resolveFn = resolve;
337
+ rejectFn = reject;
338
+ });
339
+
340
+ return { promise, resolve: resolveFn, reject: rejectFn };
341
+ }
package/src/object-ref.ts CHANGED
@@ -5,7 +5,9 @@ export const prismaModelKey = Symbol.for('Pothos.prismaModelKey');
5
5
 
6
6
  export class PrismaObjectRef<Model extends PrismaModelTypes, T = {}> extends ObjectRef<T> {
7
7
  [prismaModelKey]!: Model;
8
+
8
9
  [abstractReturnShapeKey]!: WithBrand<T>;
10
+
9
11
  modelName: string;
10
12
 
11
13
  constructor(name: string, modelName: string) {
@@ -80,17 +80,27 @@ export class PrismaObjectFieldBuilder<
80
80
  Shape extends object = Model['Shape'],
81
81
  > extends RootBuilder<Types, Shape, 'PrismaObject'> {
82
82
  model: string;
83
+
83
84
  prismaFieldMap: FieldMap;
84
85
 
85
86
  exposeBoolean = this.createExpose('Boolean');
87
+
86
88
  exposeFloat = this.createExpose('Float');
89
+
87
90
  exposeInt = this.createExpose('Int');
91
+
88
92
  exposeID = this.createExpose('ID');
93
+
89
94
  exposeString = this.createExpose('String');
95
+
90
96
  exposeBooleanList = this.createExpose(['Boolean']);
97
+
91
98
  exposeFloatList = this.createExpose(['Float']);
99
+
92
100
  exposeIntList = this.createExpose(['Int']);
101
+
93
102
  exposeIDList = this.createExpose(['ID']);
103
+
94
104
  exposeStringList = this.createExpose(['String']);
95
105
 
96
106
  withAuth: 'scopeAuth' extends PluginName
@@ -117,6 +127,9 @@ export class PrismaObjectFieldBuilder<
117
127
  ...args: NormalizeArgs<
118
128
  [
119
129
  connectionOptions:
130
+ | ObjectRef<
131
+ ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, false>>
132
+ >
120
133
  | PothosSchemaTypes.ConnectionObjectOptions<
121
134
  Types,
122
135
  ObjectRef<
@@ -139,11 +152,12 @@ export class PrismaObjectFieldBuilder<
139
152
  Args
140
153
  >,
141
154
  ConnectionInterfaces
142
- >
143
- | ObjectRef<
144
- ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, false>>
145
155
  >,
146
156
  edgeOptions:
157
+ | ObjectRef<{
158
+ cursor: string;
159
+ node?: ShapeFromTypeParam<Types, Model['Shape'], false>;
160
+ }>
147
161
  | PothosSchemaTypes.ConnectionEdgeObjectOptions<
148
162
  Types,
149
163
  ObjectRef<
@@ -165,11 +179,7 @@ export class PrismaObjectFieldBuilder<
165
179
  Args
166
180
  >,
167
181
  EdgeInterfaces
168
- >
169
- | ObjectRef<{
170
- cursor: string;
171
- node?: ShapeFromTypeParam<Types, Model['Shape'], false>;
172
- }>,
182
+ >,
173
183
  ],
174
184
  0
175
185
  >
@@ -528,18 +538,18 @@ export class PrismaObjectFieldBuilder<
528
538
  name: Name,
529
539
  ...args: NormalizeArgs<
530
540
  [
531
- options: Omit<
532
- PothosSchemaTypes.ObjectFieldOptions<
533
- Types,
534
- Shape,
535
- Type,
536
- Nullable,
537
- {},
538
- ResolveReturnShape
539
- >,
540
- 'resolve' | 'select' | 'description' | 'nullable'
541
- > &
542
- ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> & {
541
+ options: ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> &
542
+ Omit<
543
+ PothosSchemaTypes.ObjectFieldOptions<
544
+ Types,
545
+ Shape,
546
+ Type,
547
+ Nullable,
548
+ {},
549
+ ResolveReturnShape
550
+ >,
551
+ 'description' | 'nullable' | 'resolve' | 'select'
552
+ > & {
543
553
  description?: string | false;
544
554
  },
545
555
  ]
@@ -577,18 +587,18 @@ export class PrismaObjectFieldBuilder<
577
587
  name: Name,
578
588
  ...args: NormalizeArgs<
579
589
  [
580
- options: Omit<
581
- PothosSchemaTypes.ObjectFieldOptions<
582
- Types,
583
- Shape,
584
- Type,
585
- Nullable,
586
- {},
587
- ResolveReturnShape
588
- >,
589
- 'resolve' | 'type' | 'select' | 'description' | 'nullable'
590
- > &
591
- ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> & {
590
+ options: ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> &
591
+ Omit<
592
+ PothosSchemaTypes.ObjectFieldOptions<
593
+ Types,
594
+ Shape,
595
+ Type,
596
+ Nullable,
597
+ {},
598
+ ResolveReturnShape
599
+ >,
600
+ 'description' | 'nullable' | 'resolve' | 'select' | 'type'
601
+ > & {
592
602
  description?: string | false;
593
603
  },
594
604
  ]
package/src/types.ts CHANGED
@@ -155,7 +155,7 @@ export type TypesForRelation<
155
155
  Relation extends keyof Model['Relations'],
156
156
  > = Model['Relations'][Relation]['Name'] extends infer Name
157
157
  ? Name extends keyof Types['PrismaTypes']
158
- ? Types['PrismaTypes'][Name] & PrismaModelTypes
158
+ ? PrismaModelTypes & Types['PrismaTypes'][Name]
159
159
  : never
160
160
  : never;
161
161
 
@@ -205,7 +205,7 @@ export type PrismaObjectImplementationOptions<
205
205
  > = Omit<
206
206
  | PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
207
207
  | PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
208
- 'fields' | 'description'
208
+ 'description' | 'fields'
209
209
  > & {
210
210
  description?: string | false;
211
211
  fields?: PrismaObjectFieldsShape<
@@ -225,8 +225,8 @@ export type PrismaObjectTypeOptions<
225
225
  Include,
226
226
  Select,
227
227
  Shape extends object,
228
- > = PrismaObjectRefOptions<Types, Model, FindUnique, Include, Select, Shape> &
229
- PrismaObjectImplementationOptions<Types, Model, Interfaces, FindUnique, Select, Shape>;
228
+ > = PrismaObjectImplementationOptions<Types, Model, Interfaces, FindUnique, Select, Shape> &
229
+ PrismaObjectRefOptions<Types, Model, FindUnique, Include, Select, Shape>;
230
230
 
231
231
  export type PrismaInterfaceRefOptions<
232
232
  Types extends SchemaTypes,
@@ -259,7 +259,7 @@ export type PrismaInterfaceImplementationOptions<
259
259
  Shape extends object,
260
260
  > = Omit<
261
261
  PothosSchemaTypes.InterfaceTypeOptions<Types, Shape, Interfaces>,
262
- 'fields' | 'description'
262
+ 'description' | 'fields'
263
263
  > & {
264
264
  description?: string | false;
265
265
  fields?: PrismaObjectFieldsShape<
@@ -279,8 +279,8 @@ export type PrismaInterfaceTypeOptions<
279
279
  Include,
280
280
  Select,
281
281
  Shape extends object,
282
- > = PrismaInterfaceRefOptions<Types, Model, FindUnique, Include, Select, Shape> &
283
- PrismaInterfaceImplementationOptions<Types, Model, Interfaces, FindUnique, Select, Shape>;
282
+ > = PrismaInterfaceImplementationOptions<Types, Model, Interfaces, FindUnique, Select, Shape> &
283
+ PrismaInterfaceRefOptions<Types, Model, FindUnique, Include, Select, Shape>;
284
284
 
285
285
  type NameOrVariant =
286
286
  | {
@@ -305,7 +305,14 @@ export type PrismaNodeOptions<
305
305
  | PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
306
306
  | PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
307
307
  'fields' | 'isTypeOf'
308
- > & {
308
+ > &
309
+ (UniqueField extends string
310
+ ? {
311
+ findUnique?: (id: string, context: Types['Context']) => Model['WhereUnique'];
312
+ }
313
+ : {
314
+ findUnique: (id: string, context: Types['Context']) => Model['WhereUnique'];
315
+ }) & {
309
316
  id: Omit<
310
317
  FieldOptionsFromKind<
311
318
  Types,
@@ -341,14 +348,9 @@ export type PrismaNodeOptions<
341
348
  Shape & { [prismaModelName]?: Model['Name'] },
342
349
  Select
343
350
  >;
344
- } & (UniqueField extends string
345
- ? {
346
- findUnique?: (id: string, context: Types['Context']) => Model['WhereUnique'];
347
- }
348
- : {
349
- findUnique: (id: string, context: Types['Context']) => Model['WhereUnique'];
350
- }) &
351
- (
351
+ } & {
352
+ nullable?: boolean;
353
+ } & (
352
354
  | {
353
355
  include?: Include & Model['Include'];
354
356
  select?: never;
@@ -357,9 +359,7 @@ export type PrismaNodeOptions<
357
359
  select: Model['Select'] & Select;
358
360
  include?: never;
359
361
  }
360
- ) & {
361
- nullable?: boolean;
362
- };
362
+ );
363
363
 
364
364
  type QueryForField<
365
365
  Types extends SchemaTypes,
@@ -425,7 +425,7 @@ export type RelatedFieldOptions<
425
425
  Args,
426
426
  ResolveReturnShape
427
427
  >,
428
- 'resolve' | 'type' | 'description'
428
+ 'description' | 'resolve' | 'type'
429
429
  > &
430
430
  (NeedsResolve extends false
431
431
  ? {
@@ -569,11 +569,11 @@ export type PrismaFieldWithInputOptions<
569
569
  Type,
570
570
  Model,
571
571
  Param,
572
- {
572
+ Args & {
573
573
  [K in InputName]: InputFieldRef<
574
574
  InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
575
575
  >;
576
- } & Args,
576
+ },
577
577
  Nullable,
578
578
  ResolveShape,
579
579
  ResolveReturnShape,
@@ -583,11 +583,11 @@ export type PrismaFieldWithInputOptions<
583
583
  > &
584
584
  PothosSchemaTypes.FieldWithInputBaseOptions<
585
585
  Types,
586
- {
586
+ Args & {
587
587
  [K in InputName]: InputFieldRef<
588
588
  InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
589
589
  >;
590
- } & Args,
590
+ },
591
591
  Fields,
592
592
  InputName,
593
593
  ArgRequired
@@ -620,8 +620,8 @@ export type PrismaConnectionFieldOptions<
620
620
  Types extends SchemaTypes,
621
621
  ParentShape,
622
622
  Type extends
623
- | PrismaRef<PrismaModelTypes>
624
623
  | PrismaInterfaceRef<PrismaModelTypes>
624
+ | PrismaRef<PrismaModelTypes>
625
625
  | keyof Types['PrismaTypes'],
626
626
  Model extends PrismaModelTypes,
627
627
  Param extends OutputType<Types>,
@@ -629,32 +629,33 @@ export type PrismaConnectionFieldOptions<
629
629
  Args extends InputFieldMap,
630
630
  ResolveReturnShape,
631
631
  Kind extends FieldKind,
632
+ // eslint-disable-next-line @typescript-eslint/sort-type-constituents
632
633
  > = Omit<
633
- PothosSchemaTypes.ConnectionFieldOptions<
634
+ FieldOptionsFromKind<
634
635
  Types,
635
636
  ParentShape,
636
637
  Param,
637
638
  Nullable,
638
- false,
639
- false,
640
- Args,
639
+ InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments> &
640
+ (InputFieldMap extends Args ? {} : Args),
641
+ Kind,
642
+ ParentShape,
641
643
  ResolveReturnShape
642
644
  >,
643
- 'resolve' | 'type'
645
+ 'args' | 'resolve' | 'type'
644
646
  > &
645
647
  Omit<
646
- FieldOptionsFromKind<
648
+ PothosSchemaTypes.ConnectionFieldOptions<
647
649
  Types,
648
650
  ParentShape,
649
651
  Param,
650
652
  Nullable,
651
- (InputFieldMap extends Args ? {} : Args) &
652
- InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments>,
653
- Kind,
654
- ParentShape,
653
+ false,
654
+ false,
655
+ Args,
655
656
  ResolveReturnShape
656
657
  >,
657
- 'args' | 'resolve' | 'type'
658
+ 'resolve' | 'type'
658
659
  > &
659
660
  (InputShapeFromFields<Args> &
660
661
  PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
@@ -695,17 +696,18 @@ export type RelatedConnectionOptions<
695
696
  Nullable extends boolean,
696
697
  Args extends InputFieldMap,
697
698
  NeedsResolve extends boolean,
699
+ // eslint-disable-next-line @typescript-eslint/sort-type-constituents
698
700
  > = Omit<
699
701
  PothosSchemaTypes.ObjectFieldOptions<
700
702
  Types,
701
703
  Model['Shape'],
702
704
  ObjectRef<unknown>,
703
705
  Nullable,
704
- (InputFieldMap extends Args ? {} : Args) &
705
- InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments>,
706
+ InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments> &
707
+ (InputFieldMap extends Args ? {} : Args),
706
708
  unknown
707
709
  >,
708
- 'resolve' | 'type' | 'args' | 'description'
710
+ 'args' | 'description' | 'resolve' | 'type'
709
711
  > &
710
712
  Omit<
711
713
  PothosSchemaTypes.ConnectionFieldOptions<
@@ -722,15 +724,7 @@ export type RelatedConnectionOptions<
722
724
  > &
723
725
  (InputShapeFromFields<Args> &
724
726
  PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
725
- ? {
726
- description?: string | false;
727
- query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
728
- type?: PrismaRef<TypesForRelation<Types, Model, Field>>;
729
- cursor: CursorFromRelation<Model, Field>;
730
- defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
731
- maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
732
- totalCount?: NeedsResolve extends false ? boolean : false;
733
- } & (NeedsResolve extends false
727
+ ? (NeedsResolve extends false
734
728
  ? {
735
729
  resolve?: (
736
730
  query: {
@@ -770,7 +764,15 @@ export type RelatedConnectionOptions<
770
764
  Nullable
771
765
  >
772
766
  >;
773
- })
767
+ }) & {
768
+ description?: string | false;
769
+ query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
770
+ type?: PrismaRef<TypesForRelation<Types, Model, Field>>;
771
+ cursor: CursorFromRelation<Model, Field>;
772
+ defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
773
+ maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
774
+ totalCount?: NeedsResolve extends false ? boolean : false;
775
+ }
774
776
  : never);
775
777
 
776
778
  export type WithBrand<T> = T & { [typeBrandKey]: string };
@@ -790,7 +792,7 @@ export type FieldSelection =
790
792
  context: object,
791
793
  mergeNestedSelection: (
792
794
  selection: SelectionMap | boolean | ((args: object, context: object) => SelectionMap),
793
- path?: string[] | IndirectInclude,
795
+ path?: IndirectInclude | string[],
794
796
  ) => SelectionMap | boolean,
795
797
  resolveSelection: (path: string[]) => FieldNode | null,
796
798
  ) => SelectionMap);
@@ -4,7 +4,7 @@ import { LoaderMappings } from '../types';
4
4
 
5
5
  const cache = createContextCache((ctx) => new Map<string, LoaderMappings>());
6
6
 
7
- export function cacheKey(type: string, path: GraphQLResolveInfo['path'], subPath: string[]) {
7
+ export function cacheKey(type: string, path: GraphQLResolveInfo['path'], subPath: string[] = []) {
8
8
  let key = '';
9
9
  let current: GraphQLResolveInfo['path'] | undefined = path;
10
10