@pothos/plugin-prisma 3.51.1 → 3.53.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 (90) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dts/global-types.d.ts.map +1 -1
  3. package/dts/prisma-field-builder.d.ts +25 -23
  4. package/dts/prisma-field-builder.d.ts.map +1 -1
  5. package/dts/types.d.ts +5 -1
  6. package/dts/types.d.ts.map +1 -1
  7. package/dts/util/map-query.d.ts +2 -1
  8. package/dts/util/map-query.d.ts.map +1 -1
  9. package/esm/connection-helpers.js +2 -1
  10. package/esm/connection-helpers.js.map +1 -1
  11. package/esm/field-builder.js +14 -9
  12. package/esm/field-builder.js.map +1 -1
  13. package/esm/generator.js +2 -2
  14. package/esm/generator.js.map +1 -1
  15. package/esm/global-types.d.ts.map +1 -1
  16. package/esm/global-types.js.map +1 -1
  17. package/esm/index.js.map +1 -1
  18. package/esm/model-loader.js +10 -12
  19. package/esm/model-loader.js.map +1 -1
  20. package/esm/node-ref.js.map +1 -1
  21. package/esm/object-ref.js +4 -4
  22. package/esm/object-ref.js.map +1 -1
  23. package/esm/prisma-field-builder.d.ts +85 -43
  24. package/esm/prisma-field-builder.d.ts.map +1 -1
  25. package/esm/prisma-field-builder.js +36 -27
  26. package/esm/prisma-field-builder.js.map +1 -1
  27. package/esm/schema-builder.js +1 -1
  28. package/esm/schema-builder.js.map +1 -1
  29. package/esm/types.d.ts +5 -1
  30. package/esm/types.d.ts.map +1 -1
  31. package/esm/util/cursors.js +2 -2
  32. package/esm/util/cursors.js.map +1 -1
  33. package/esm/util/datamodel.js.map +1 -1
  34. package/esm/util/deep-equal.js +2 -1
  35. package/esm/util/deep-equal.js.map +1 -1
  36. package/esm/util/description.js +4 -2
  37. package/esm/util/description.js.map +1 -1
  38. package/esm/util/get-client.js.map +1 -1
  39. package/esm/util/loader-map.js.map +1 -1
  40. package/esm/util/map-query.d.ts +2 -1
  41. package/esm/util/map-query.d.ts.map +1 -1
  42. package/esm/util/map-query.js +35 -13
  43. package/esm/util/map-query.js.map +1 -1
  44. package/esm/util/relation-map.js.map +1 -1
  45. package/esm/util/selections.js.map +1 -1
  46. package/lib/connection-helpers.js +13 -8
  47. package/lib/connection-helpers.js.map +1 -1
  48. package/lib/field-builder.js +23 -18
  49. package/lib/field-builder.js.map +1 -1
  50. package/lib/generator.js +11 -11
  51. package/lib/generator.js.map +1 -1
  52. package/lib/index.js +58 -34
  53. package/lib/index.js.map +1 -1
  54. package/lib/model-loader.js +14 -14
  55. package/lib/model-loader.js.map +1 -1
  56. package/lib/node-ref.js +5 -3
  57. package/lib/node-ref.js.map +1 -1
  58. package/lib/object-ref.js +10 -6
  59. package/lib/object-ref.js.map +1 -1
  60. package/lib/prisma-field-builder.js +48 -37
  61. package/lib/prisma-field-builder.js.map +1 -1
  62. package/lib/schema-builder.js +25 -25
  63. package/lib/schema-builder.js.map +1 -1
  64. package/lib/types.js +3 -1
  65. package/lib/types.js.map +1 -1
  66. package/lib/util/cursors.js +46 -18
  67. package/lib/util/cursors.js.map +1 -1
  68. package/lib/util/datamodel.js +28 -12
  69. package/lib/util/datamodel.js.map +1 -1
  70. package/lib/util/deep-equal.js +6 -3
  71. package/lib/util/deep-equal.js.map +1 -1
  72. package/lib/util/description.js +12 -6
  73. package/lib/util/description.js.map +1 -1
  74. package/lib/util/get-client.js +6 -2
  75. package/lib/util/get-client.js.map +1 -1
  76. package/lib/util/loader-map.js +9 -3
  77. package/lib/util/loader-map.js.map +1 -1
  78. package/lib/util/map-query.js +48 -21
  79. package/lib/util/map-query.js.map +1 -1
  80. package/lib/util/relation-map.js +7 -3
  81. package/lib/util/relation-map.js.map +1 -1
  82. package/lib/util/selections.js +24 -12
  83. package/lib/util/selections.js.map +1 -1
  84. package/package.json +9 -9
  85. package/src/field-builder.ts +1 -1
  86. package/src/generator.ts +2 -3
  87. package/src/global-types.ts +0 -2
  88. package/src/prisma-field-builder.ts +29 -19
  89. package/src/types.ts +2 -1
  90. package/src/util/map-query.ts +42 -14
@@ -3,6 +3,7 @@
3
3
  import { FieldNode, GraphQLResolveInfo } from 'graphql';
4
4
  import {
5
5
  CompatibleTypes,
6
+ ExposeNullability,
6
7
  FieldKind,
7
8
  FieldRef,
8
9
  InputFieldMap,
@@ -261,7 +262,7 @@ export class PrismaObjectFieldBuilder<
261
262
  }
262
263
  return typeName;
263
264
  },
264
- path: [{ name: 'edges' }, { name: 'node' }],
265
+ paths: [[{ name: 'nodes' }], [{ name: 'edges' }, { name: 'node' }]],
265
266
  }) as SelectionMap;
266
267
 
267
268
  const hasTotalCount = totalCount && !!getSelection(['totalCount']);
@@ -525,7 +526,7 @@ export class PrismaObjectFieldBuilder<
525
526
  Type extends TypeParam<Types>,
526
527
  Nullable extends boolean,
527
528
  ResolveReturnShape,
528
- Name extends CompatibleTypes<Types, Model['Shape'], Type, Nullable>,
529
+ Name extends CompatibleTypes<Types, Model['Shape'], Type, true>,
529
530
  >(
530
531
  ...args: NormalizeArgs<
531
532
  [
@@ -539,8 +540,11 @@ export class PrismaObjectFieldBuilder<
539
540
  {},
540
541
  ResolveReturnShape
541
542
  >,
542
- 'resolve' | 'select'
543
- >,
543
+ 'resolve' | 'select' | 'description' | 'nullable'
544
+ > &
545
+ ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> & {
546
+ description?: string | false;
547
+ },
544
548
  ]
545
549
  >
546
550
  ) {
@@ -549,13 +553,19 @@ export class PrismaObjectFieldBuilder<
549
553
  const typeConfig = this.builder.configStore.getTypeConfig(this.typename, 'Object');
550
554
  const usingSelect = !!typeConfig.extensions?.pothosPrismaSelect;
551
555
 
552
- return this.exposeField(name as never, {
556
+ return this.exposeField<Type, Nullable, never>(name as never, {
553
557
  ...options,
558
+ description: getFieldDescription(
559
+ this.model,
560
+ this.builder,
561
+ name as string,
562
+ options.description,
563
+ ) as never,
554
564
  extensions: {
555
565
  ...options.extensions,
556
566
  pothosPrismaVariant: name,
557
567
  pothosPrismaSelect: usingSelect && {
558
- [name]: true,
568
+ [name as string]: true,
559
569
  },
560
570
  },
561
571
  });
@@ -565,7 +575,7 @@ export class PrismaObjectFieldBuilder<
565
575
  return <
566
576
  Nullable extends boolean,
567
577
  ResolveReturnShape,
568
- Name extends CompatibleTypes<Types, Model['Shape'], Type, Nullable>,
578
+ Name extends CompatibleTypes<Types, Model['Shape'], Type, true>,
569
579
  >(
570
580
  ...args: NormalizeArgs<
571
581
  [
@@ -579,23 +589,23 @@ export class PrismaObjectFieldBuilder<
579
589
  {},
580
590
  ResolveReturnShape
581
591
  >,
582
- 'resolve' | 'type' | 'select' | 'description'
583
- > & { description?: string | false },
592
+ 'resolve' | 'type' | 'select' | 'description' | 'nullable'
593
+ > &
594
+ ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> & {
595
+ description?: string | false;
596
+ },
584
597
  ]
585
598
  >
586
599
  ): FieldRef<ShapeFromTypeParam<Types, Type, Nullable>, 'PrismaObject'> => {
587
600
  const [name, { description, ...options } = {} as never] = args;
588
601
 
589
- return this.expose(name as never, {
590
- ...options,
591
- description: getFieldDescription(
592
- this.model,
593
- this.builder,
594
- name as string,
595
- description,
596
- ) as never,
597
- type,
598
- });
602
+ return this.expose<Type, Nullable, ResolveReturnShape, never>(
603
+ name as never,
604
+ {
605
+ ...options,
606
+ type,
607
+ } as never,
608
+ );
599
609
  };
600
610
  }
601
611
  }
package/src/types.ts CHANGED
@@ -747,7 +747,8 @@ export type LoaderMappings = Record<
747
747
 
748
748
  export interface IndirectInclude {
749
749
  getType: () => string;
750
- path: { type?: string; name: string }[];
750
+ path?: { type?: string; name: string }[];
751
+ paths?: { type?: string; name: string }[][];
751
752
  }
752
753
 
753
754
  export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
@@ -56,12 +56,16 @@ function addTypeSelectionsForField(
56
56
  pothosPrismaIndirectInclude?: IndirectInclude;
57
57
  };
58
58
 
59
- if (pothosPrismaIndirectInclude && pothosPrismaIndirectInclude.path.length > 0) {
60
- resolveIndirectInclude(
59
+ if (
60
+ (pothosPrismaIndirectInclude?.path && pothosPrismaIndirectInclude.path.length > 0) ||
61
+ (pothosPrismaIndirectInclude?.paths && pothosPrismaIndirectInclude.paths.length === 0)
62
+ ) {
63
+ resolveIndirectIncludePaths(
61
64
  type,
62
65
  info,
63
66
  selection,
64
- pothosPrismaIndirectInclude.path,
67
+ [],
68
+ pothosPrismaIndirectInclude.paths ?? [pothosPrismaIndirectInclude.path!],
65
69
  indirectPath,
66
70
  (resolvedType, field, path) => {
67
71
  addTypeSelectionsForField(resolvedType, context, info, state, field, path);
@@ -99,11 +103,29 @@ function addTypeSelectionsForField(
99
103
  }
100
104
  }
101
105
 
106
+ function resolveIndirectIncludePaths(
107
+ type: GraphQLNamedType,
108
+ info: GraphQLResolveInfo,
109
+ selection: FieldNode | FragmentDefinitionNode | InlineFragmentNode,
110
+ pathPrefix: { type?: string; name: string }[],
111
+ includePaths: { type?: string; name: string }[][],
112
+ path: string[],
113
+ resolve: (type: GraphQLNamedType, field: FieldNode, path: string[]) => void,
114
+ ) {
115
+ for (const includePath of includePaths) {
116
+ if (pathPrefix.length > 0) {
117
+ resolveIndirectInclude(type, info, selection, [...pathPrefix, ...includePath], path, resolve);
118
+ } else {
119
+ resolveIndirectInclude(type, info, selection, includePath, path, resolve);
120
+ }
121
+ }
122
+ }
123
+
102
124
  function resolveIndirectInclude(
103
125
  type: GraphQLNamedType,
104
126
  info: GraphQLResolveInfo,
105
127
  selection: FieldNode | FragmentDefinitionNode | InlineFragmentNode,
106
- includePath: IndirectInclude['path'],
128
+ includePath: { type?: string; name: string }[],
107
129
  path: string[],
108
130
  resolve: (type: GraphQLNamedType, field: FieldNode, path: string[]) => void,
109
131
  ) {
@@ -275,15 +297,16 @@ function addFieldSelection(
275
297
  mergeSelection(fieldState, { select: {}, ...query });
276
298
  }
277
299
 
278
- if (normalizedIndirectInclude && normalizedIndirectInclude.path.length > 0) {
279
- resolveIndirectInclude(
300
+ if (
301
+ (normalizedIndirectInclude?.path && normalizedIndirectInclude.path.length > 0) ||
302
+ (normalizedIndirectInclude?.paths && normalizedIndirectInclude.paths.length > 0)
303
+ ) {
304
+ resolveIndirectIncludePaths(
280
305
  returnType,
281
306
  info,
282
307
  selection,
283
- [
284
- ...((returnType.extensions?.pothosPrismaIndirectInclude as { path: [] })?.path ?? []),
285
- ...normalizedIndirectInclude.path,
286
- ],
308
+ (returnType.extensions?.pothosPrismaIndirectInclude as { path: [] })?.path ?? [],
309
+ normalizedIndirectInclude.paths ?? [normalizedIndirectInclude.path!],
287
310
  [],
288
311
  (resolvedType, resolvedField, path) => {
289
312
  addTypeSelectionsForField(
@@ -346,12 +369,14 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
346
369
  typeName,
347
370
  select,
348
371
  path = [],
372
+ paths = [],
349
373
  }: {
350
374
  context: object;
351
375
  info: GraphQLResolveInfo;
352
376
  typeName?: string;
353
377
  select?: T;
354
378
  path?: string[];
379
+ paths?: string[][];
355
380
  }): { select: T } | { include?: {} } {
356
381
  const returnType = getNamedType(info.returnType);
357
382
  const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
@@ -359,7 +384,7 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
359
384
  let state: SelectionState | undefined;
360
385
  const initialSelection = select ? { select } : undefined;
361
386
 
362
- if (path.length > 0) {
387
+ if (path.length > 0 || paths.length > 0) {
363
388
  const { pothosPrismaIndirectInclude } = (returnType.extensions ?? {}) as {
364
389
  pothosPrismaIndirectInclude?: IndirectInclude;
365
390
  };
@@ -371,11 +396,14 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
371
396
  pothosPrismaIndirectInclude?.path ?? [],
372
397
  [],
373
398
  (indirectType, indirectField, subPath) => {
374
- resolveIndirectInclude(
399
+ resolveIndirectIncludePaths(
375
400
  indirectType,
376
401
  info,
377
402
  indirectField,
378
- path.map((n) => (typeof n === 'string' ? { name: n } : n)),
403
+ [],
404
+ paths.length > 0
405
+ ? paths.map((p) => p.map((n) => (typeof n === 'string' ? { name: n } : n)))
406
+ : [path.map((n) => (typeof n === 'string' ? { name: n } : n))],
379
407
  subPath,
380
408
  (resolvedType, resolvedField, nested) => {
381
409
  state = createStateForType(
@@ -465,7 +493,7 @@ export function getIndirectType(type: GraphQLNamedType, info: GraphQLResolveInfo
465
493
  return targetType;
466
494
  }
467
495
 
468
- function normalizeInclude(path: string[], type: GraphQLNamedType) {
496
+ function normalizeInclude(path: string[], type: GraphQLNamedType): IndirectInclude {
469
497
  let currentType = type;
470
498
 
471
499
  const normalized: { name: string; type: string }[] = [];