@pothos/plugin-prisma 3.40.2 → 3.41.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 (58) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dts/model-loader.d.ts.map +1 -1
  3. package/dts/util/cursors.d.ts.map +1 -1
  4. package/dts/util/datamodel.d.ts.map +1 -1
  5. package/dts/util/map-query.d.ts.map +1 -1
  6. package/esm/generator.js.map +1 -1
  7. package/esm/model-loader.d.ts.map +1 -1
  8. package/esm/model-loader.js +5 -5
  9. package/esm/model-loader.js.map +1 -1
  10. package/esm/prisma-field-builder.js.map +1 -1
  11. package/esm/schema-builder.js +2 -2
  12. package/esm/schema-builder.js.map +1 -1
  13. package/esm/util/cursors.d.ts.map +1 -1
  14. package/esm/util/cursors.js +17 -17
  15. package/esm/util/cursors.js.map +1 -1
  16. package/esm/util/datamodel.d.ts.map +1 -1
  17. package/esm/util/datamodel.js +5 -4
  18. package/esm/util/datamodel.js.map +1 -1
  19. package/esm/util/description.js.map +1 -1
  20. package/esm/util/map-query.d.ts.map +1 -1
  21. package/esm/util/map-query.js +13 -8
  22. package/esm/util/map-query.js.map +1 -1
  23. package/esm/util/selections.js +2 -2
  24. package/esm/util/selections.js.map +1 -1
  25. package/generated.ts +1 -1
  26. package/lib/connection-helpers.js.map +1 -1
  27. package/lib/field-builder.js.map +1 -1
  28. package/lib/generator.js.map +1 -1
  29. package/lib/global-types.js.map +1 -1
  30. package/lib/index.js.map +1 -1
  31. package/lib/model-loader.js +4 -4
  32. package/lib/model-loader.js.map +1 -1
  33. package/lib/node-ref.js.map +1 -1
  34. package/lib/object-ref.js.map +1 -1
  35. package/lib/prisma-field-builder.js.map +1 -1
  36. package/lib/schema-builder.js +1 -1
  37. package/lib/schema-builder.js.map +1 -1
  38. package/lib/types.js.map +1 -1
  39. package/lib/util/cursors.js +16 -16
  40. package/lib/util/cursors.js.map +1 -1
  41. package/lib/util/datamodel.js +5 -4
  42. package/lib/util/datamodel.js.map +1 -1
  43. package/lib/util/deep-equal.js.map +1 -1
  44. package/lib/util/description.js.map +1 -1
  45. package/lib/util/get-client.js.map +1 -1
  46. package/lib/util/loader-map.js.map +1 -1
  47. package/lib/util/map-query.js +12 -8
  48. package/lib/util/map-query.js.map +1 -1
  49. package/lib/util/relation-map.js.map +1 -1
  50. package/lib/util/selections.js +2 -2
  51. package/lib/util/selections.js.map +1 -1
  52. package/package.json +8 -8
  53. package/src/generator.ts +1 -1
  54. package/src/model-loader.ts +5 -5
  55. package/src/schema-builder.ts +2 -1
  56. package/src/util/cursors.ts +29 -15
  57. package/src/util/datamodel.ts +7 -5
  58. package/src/util/map-query.ts +23 -8
@@ -14,6 +14,7 @@ import {
14
14
  Kind,
15
15
  SelectionSetNode,
16
16
  } from 'graphql';
17
+ import { PothosValidationError } from '@pothos/core';
17
18
  import {
18
19
  FieldSelection,
19
20
  IncludeMap,
@@ -55,7 +56,7 @@ function addTypeSelectionsForField(
55
56
  pothosPrismaIndirectInclude?: IndirectInclude;
56
57
  };
57
58
 
58
- if (pothosPrismaIndirectInclude) {
59
+ if (pothosPrismaIndirectInclude && pothosPrismaIndirectInclude.path.length > 0) {
59
60
  resolveIndirectInclude(
60
61
  type,
61
62
  info,
@@ -66,6 +67,16 @@ function addTypeSelectionsForField(
66
67
  addTypeSelectionsForField(resolvedType, context, info, state, field, path);
67
68
  },
68
69
  );
70
+ } else if (pothosPrismaIndirectInclude) {
71
+ addTypeSelectionsForField(
72
+ info.schema.getType(pothosPrismaIndirectInclude.getType())!,
73
+ context,
74
+ info,
75
+ state,
76
+ selection,
77
+ indirectPath,
78
+ );
79
+ return;
69
80
  }
70
81
 
71
82
  if (!isObjectType(type)) {
@@ -151,7 +162,9 @@ function resolveIndirectInclude(
151
162
  continue;
152
163
 
153
164
  default:
154
- throw new Error(`Unsupported selection kind ${(selection as { kind: string }).kind}`);
165
+ throw new PothosValidationError(
166
+ `Unsupported selection kind ${(selection as { kind: string }).kind}`,
167
+ );
155
168
  }
156
169
  }
157
170
  }
@@ -196,7 +209,9 @@ function addNestedSelections(
196
209
  continue;
197
210
 
198
211
  default:
199
- throw new Error(`Unsupported selection kind ${(selection as { kind: string }).kind}`);
212
+ throw new PothosValidationError(
213
+ `Unsupported selection kind ${(selection as { kind: string }).kind}`,
214
+ );
200
215
  }
201
216
  }
202
217
  }
@@ -216,7 +231,7 @@ function addFieldSelection(
216
231
  const field = type.getFields()[selection.name.value];
217
232
 
218
233
  if (!field) {
219
- throw new Error(`Unknown field ${selection.name.value} on ${type.name}`);
234
+ throw new PothosValidationError(`Unknown field ${selection.name.value} on ${type.name}`);
220
235
  }
221
236
 
222
237
  const fieldSelect = field.extensions?.pothosPrismaSelect as FieldSelection | undefined;
@@ -393,7 +408,7 @@ export function selectionStateFromInfo(
393
408
  const state = createStateForType(type, info);
394
409
 
395
410
  if (!isObjectType(type)) {
396
- throw new Error('Prisma plugin can only resolve includes for object types');
411
+ throw new PothosValidationError('Prisma plugin can only resolve includes for object types');
397
412
  }
398
413
 
399
414
  addFieldSelection(type, context, info, state, info.fieldNodes[0], []);
@@ -435,20 +450,20 @@ function normalizeInclude(path: string[], type: GraphQLNamedType) {
435
450
  const normalized: { name: string; type: string }[] = [];
436
451
 
437
452
  if (!isObjectType(currentType)) {
438
- throw new Error(`Expected ${currentType} to be an Object type`);
453
+ throw new PothosValidationError(`Expected ${currentType} to be an Object type`);
439
454
  }
440
455
 
441
456
  for (const fieldName of path) {
442
457
  const field: GraphQLField<unknown, unknown> = currentType.getFields()[fieldName];
443
458
 
444
459
  if (!field) {
445
- throw new Error(`Expected ${currentType} to have a field ${fieldName}`);
460
+ throw new PothosValidationError(`Expected ${currentType} to have a field ${fieldName}`);
446
461
  }
447
462
 
448
463
  currentType = getNamedType(field.type);
449
464
 
450
465
  if (!isObjectType(currentType)) {
451
- throw new Error(`Expected ${currentType} to be an Object type`);
466
+ throw new PothosValidationError(`Expected ${currentType} to be an Object type`);
452
467
  }
453
468
 
454
469
  normalized.push({ name: fieldName, type: currentType.name });