@pothos/plugin-prisma 3.59.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 (53) hide show
  1. package/CHANGELOG.md +6 -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/interface-ref.d.ts +1 -1
  7. package/dts/interface-ref.d.ts.map +1 -1
  8. package/dts/model-loader.d.ts +8 -8
  9. package/dts/model-loader.d.ts.map +1 -1
  10. package/dts/object-ref.d.ts.map +1 -1
  11. package/dts/prisma-field-builder.d.ts +18 -18
  12. package/dts/prisma-field-builder.d.ts.map +1 -1
  13. package/dts/types.d.ts +30 -30
  14. package/dts/types.d.ts.map +1 -1
  15. package/dts/util/map-query.d.ts +2 -2
  16. package/dts/util/map-query.d.ts.map +1 -1
  17. package/esm/connection-helpers.d.ts +6 -6
  18. package/esm/connection-helpers.d.ts.map +1 -1
  19. package/esm/global-types.d.ts +13 -13
  20. package/esm/global-types.d.ts.map +1 -1
  21. package/esm/interface-ref.d.ts +1 -1
  22. package/esm/interface-ref.d.ts.map +1 -1
  23. package/esm/interface-ref.js.map +1 -1
  24. package/esm/model-loader.d.ts +8 -8
  25. package/esm/model-loader.d.ts.map +1 -1
  26. package/esm/model-loader.js.map +1 -1
  27. package/esm/object-ref.d.ts.map +1 -1
  28. package/esm/object-ref.js.map +1 -1
  29. package/esm/prisma-field-builder.d.ts +28 -28
  30. package/esm/prisma-field-builder.d.ts.map +1 -1
  31. package/esm/prisma-field-builder.js.map +1 -1
  32. package/esm/types.d.ts +30 -30
  33. package/esm/types.d.ts.map +1 -1
  34. package/esm/util/map-query.d.ts +2 -2
  35. package/esm/util/map-query.d.ts.map +1 -1
  36. package/esm/util/map-query.js +10 -2
  37. package/esm/util/map-query.js.map +1 -1
  38. package/lib/interface-ref.js.map +1 -1
  39. package/lib/model-loader.js.map +1 -1
  40. package/lib/object-ref.js.map +1 -1
  41. package/lib/prisma-field-builder.js.map +1 -1
  42. package/lib/util/map-query.js +9 -1
  43. package/lib/util/map-query.js.map +1 -1
  44. package/package.json +5 -5
  45. package/src/connection-helpers.ts +5 -5
  46. package/src/global-types.ts +11 -11
  47. package/src/index.ts +4 -4
  48. package/src/interface-ref.ts +3 -2
  49. package/src/model-loader.ts +17 -10
  50. package/src/object-ref.ts +2 -0
  51. package/src/prisma-field-builder.ts +42 -32
  52. package/src/types.ts +52 -50
  53. package/src/util/map-query.ts +16 -3
@@ -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,12 +4,15 @@ import {
4
4
  FieldNode,
5
5
  FragmentDefinitionNode,
6
6
  getArgumentValues,
7
+ getDirectiveValues,
7
8
  getNamedType,
8
9
  GraphQLField,
10
+ GraphQLIncludeDirective,
9
11
  GraphQLInterfaceType,
10
12
  GraphQLNamedType,
11
13
  GraphQLObjectType,
12
14
  GraphQLResolveInfo,
15
+ GraphQLSkipDirective,
13
16
  InlineFragmentNode,
14
17
  isInterfaceType,
15
18
  isObjectType,
@@ -198,7 +201,7 @@ function resolveIndirectInclude(
198
201
  }
199
202
 
200
203
  function addNestedSelections(
201
- type: GraphQLObjectType | GraphQLInterfaceType,
204
+ type: GraphQLInterfaceType | GraphQLObjectType,
202
205
  context: object,
203
206
  info: GraphQLResolveInfo,
204
207
  state: SelectionState,
@@ -260,7 +263,7 @@ function addNestedSelections(
260
263
  }
261
264
 
262
265
  function addFieldSelection(
263
- type: GraphQLObjectType | GraphQLInterfaceType,
266
+ type: GraphQLInterfaceType | GraphQLObjectType,
264
267
  context: object,
265
268
  info: GraphQLResolveInfo,
266
269
  state: SelectionState,
@@ -271,6 +274,16 @@ function addFieldSelection(
271
274
  return;
272
275
  }
273
276
 
277
+ const skip = getDirectiveValues(GraphQLSkipDirective, selection, info.variableValues);
278
+ if (skip?.if === true) {
279
+ return;
280
+ }
281
+
282
+ const include = getDirectiveValues(GraphQLIncludeDirective, selection, info.variableValues);
283
+ if (include?.if === false) {
284
+ return;
285
+ }
286
+
274
287
  const field = type.getFields()[selection.name.value];
275
288
 
276
289
  if (!field) {
@@ -397,7 +410,7 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
397
410
  path?: string[];
398
411
  paths?: string[][];
399
412
  withUsageCheck?: boolean;
400
- }): { select: T } | { include?: {} } {
413
+ }): { include?: {} } | { select: T } {
401
414
  const returnType = getNamedType(info.returnType);
402
415
  const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
403
416