@pothos/plugin-prisma 4.0.5 → 4.1.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.
@@ -353,7 +353,7 @@ declare global {
353
353
  >
354
354
  : '@pothos/plugin-relay is required to use this method';
355
355
 
356
- prismaFieldWithInput: 'prisma' extends PluginName
356
+ prismaFieldWithInput: 'withInput' extends PluginName
357
357
  ? <
358
358
  Fields extends InputFieldMap,
359
359
  TypeParam extends
@@ -399,7 +399,7 @@ declare global {
399
399
  : ArgRequired
400
400
  >,
401
401
  ) => FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>>
402
- : '@pothos/plugin-prisma is required to use this method';
402
+ : '@pothos/plugin-with-input is required to use this method';
403
403
  }
404
404
 
405
405
  export interface ConnectionFieldOptions<
@@ -137,10 +137,6 @@ export class PrismaObjectFieldBuilder<
137
137
  >
138
138
  >
139
139
  >
140
- | ObjectRef<
141
- Types,
142
- ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, false>>
143
- >
144
140
  | PothosSchemaTypes.ConnectionObjectOptions<
145
141
  Types,
146
142
  ObjectRef<
package/src/types.ts CHANGED
@@ -618,7 +618,7 @@ export type PrismaConnectionFieldOptions<
618
618
  Types extends SchemaTypes,
619
619
  ParentShape,
620
620
  Type extends
621
- | PrismaInterfaceRef<Types, PrismaModelTypes>
621
+ | PrismaInterfaceRef<any, PrismaModelTypes>
622
622
  | PrismaRef<any, PrismaModelTypes>
623
623
  | keyof Types['PrismaTypes'],
624
624
  Model extends PrismaModelTypes,
@@ -49,36 +49,32 @@ function addTypeSelectionsForField(
49
49
  return;
50
50
  }
51
51
 
52
- const {
53
- pothosPrismaInclude,
54
- pothosPrismaSelect,
55
- pothosPrismaIndirectInclude,
56
- pothosPrismaModel,
57
- } = (type.extensions ?? {}) as {
58
- pothosPrismaModel?: string;
59
- pothosPrismaInclude?: IncludeMap;
60
- pothosPrismaSelect?: IncludeMap;
61
- pothosPrismaIndirectInclude?: IndirectInclude;
62
- };
52
+ const { pothosPrismaInclude, pothosPrismaSelect, pothosIndirectInclude, pothosPrismaModel } =
53
+ (type.extensions ?? {}) as {
54
+ pothosPrismaModel?: string;
55
+ pothosPrismaInclude?: IncludeMap;
56
+ pothosPrismaSelect?: IncludeMap;
57
+ pothosIndirectInclude?: IndirectInclude;
58
+ };
63
59
 
64
60
  if (
65
- (!!pothosPrismaIndirectInclude?.path && pothosPrismaIndirectInclude.path.length > 0) ||
66
- (!!pothosPrismaIndirectInclude?.paths && pothosPrismaIndirectInclude.paths.length === 0)
61
+ (!!pothosIndirectInclude?.path && pothosIndirectInclude.path.length > 0) ||
62
+ (!!pothosIndirectInclude?.paths && pothosIndirectInclude.paths.length === 0)
67
63
  ) {
68
64
  resolveIndirectIncludePaths(
69
65
  type,
70
66
  info,
71
67
  selection,
72
68
  [],
73
- pothosPrismaIndirectInclude.paths ?? [pothosPrismaIndirectInclude.path!],
69
+ pothosIndirectInclude.paths ?? [pothosIndirectInclude.path!],
74
70
  indirectPath,
75
71
  (resolvedType, field, path) => {
76
72
  addTypeSelectionsForField(resolvedType, context, info, state, field, path);
77
73
  },
78
74
  );
79
- } else if (pothosPrismaIndirectInclude) {
75
+ } else if (pothosIndirectInclude) {
80
76
  addTypeSelectionsForField(
81
- info.schema.getType(pothosPrismaIndirectInclude.getType())!,
77
+ info.schema.getType(pothosIndirectInclude.getType())!,
82
78
  context,
83
79
  info,
84
80
  state,
@@ -335,7 +331,7 @@ function addFieldSelection(
335
331
  returnType,
336
332
  info,
337
333
  selection,
338
- (returnType.extensions?.pothosPrismaIndirectInclude as { path: [] })?.path ?? [],
334
+ (returnType.extensions?.pothosIndirectInclude as { path: [] })?.path ?? [],
339
335
  normalizedIndirectInclude?.paths ??
340
336
  (normalizedIndirectInclude?.path ? [normalizedIndirectInclude.path] : []),
341
337
  [],
@@ -403,11 +399,15 @@ function addFieldSelection(
403
399
  }
404
400
  }
405
401
 
406
- export function queryFromInfo<T extends SelectionMap['select'] | undefined = undefined>({
402
+ export function queryFromInfo<
403
+ Select extends SelectionMap['select'] | undefined = undefined,
404
+ Include extends SelectionMap['select'] | undefined = undefined,
405
+ >({
407
406
  context,
408
407
  info,
409
408
  typeName,
410
409
  select,
410
+ include,
411
411
  path = [],
412
412
  paths = [],
413
413
  withUsageCheck = false,
@@ -415,27 +415,33 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
415
415
  context: object;
416
416
  info: GraphQLResolveInfo;
417
417
  typeName?: string;
418
- select?: T;
419
418
  path?: string[];
420
419
  paths?: string[][];
421
420
  withUsageCheck?: boolean;
422
- }): { include?: {} } | { select: T } {
421
+ } & (
422
+ | { include?: Include; select?: never }
423
+ | { select?: Select; include?: never }
424
+ )): undefined extends Include
425
+ ? {
426
+ select: Select;
427
+ }
428
+ : { include: Include } {
423
429
  const returnType = getNamedType(info.returnType);
424
430
  const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
425
431
 
426
432
  let state: SelectionState | undefined;
427
- const initialSelection = select ? { select } : undefined;
433
+ const initialSelection = select ? { select } : include ? { include } : undefined;
428
434
 
429
435
  if (path.length > 0 || paths.length > 0) {
430
- const { pothosPrismaIndirectInclude } = (returnType.extensions ?? {}) as {
431
- pothosPrismaIndirectInclude?: IndirectInclude;
436
+ const { pothosIndirectInclude } = (returnType.extensions ?? {}) as {
437
+ pothosIndirectInclude?: IndirectInclude;
432
438
  };
433
439
 
434
440
  resolveIndirectInclude(
435
441
  returnType,
436
442
  info,
437
443
  info.fieldNodes[0],
438
- pothosPrismaIndirectInclude?.path ?? [],
444
+ pothosIndirectInclude?.path ?? [],
439
445
  [],
440
446
  (indirectType, indirectField, subPath) => {
441
447
  resolveIndirectIncludePaths(
@@ -479,7 +485,7 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
479
485
 
480
486
  setLoaderMappings(context, info, state.mappings);
481
487
 
482
- const query = selectionToQuery(state) as { select: T };
488
+ const query = selectionToQuery(state) as { select: Select; include: Include };
483
489
 
484
490
  return withUsageCheck ? wrapWithUsageCheck(query) : query;
485
491
  }
@@ -530,9 +536,9 @@ function createStateForType(
530
536
  export function getIndirectType(type: GraphQLNamedType, info: GraphQLResolveInfo) {
531
537
  let targetType = type;
532
538
 
533
- while (targetType.extensions?.pothosPrismaIndirectInclude) {
539
+ while (targetType.extensions?.pothosIndirectInclude) {
534
540
  targetType = info.schema.getType(
535
- (targetType.extensions?.pothosPrismaIndirectInclude as IndirectInclude).getType(),
541
+ (targetType.extensions?.pothosIndirectInclude as IndirectInclude).getType(),
536
542
  )!;
537
543
  }
538
544