@pothos/plugin-prisma 4.0.5 → 4.2.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 (171) hide show
  1. package/CHANGELOG.md +17 -4
  2. package/dts/connection-helpers.d.ts +2 -2
  3. package/dts/connection-helpers.d.ts.map +1 -1
  4. package/dts/global-types.d.ts +9 -9
  5. package/dts/global-types.d.ts.map +1 -1
  6. package/dts/index.d.ts +2 -2
  7. package/dts/index.d.ts.map +1 -1
  8. package/dts/interface-ref.d.ts +2 -2
  9. package/dts/interface-ref.d.ts.map +1 -1
  10. package/dts/model-loader.d.ts +4 -4
  11. package/dts/model-loader.d.ts.map +1 -1
  12. package/dts/node-ref.d.ts +1 -1
  13. package/dts/node-ref.d.ts.map +1 -1
  14. package/dts/object-ref.d.ts +1 -1
  15. package/dts/object-ref.d.ts.map +1 -1
  16. package/dts/prisma-field-builder.d.ts +5 -5
  17. package/dts/prisma-field-builder.d.ts.map +1 -1
  18. package/dts/types.d.ts +8 -8
  19. package/dts/types.d.ts.map +1 -1
  20. package/dts/util/cursors.d.ts +3 -3
  21. package/dts/util/cursors.d.ts.map +1 -1
  22. package/dts/util/datamodel.d.ts +3 -3
  23. package/dts/util/datamodel.d.ts.map +1 -1
  24. package/dts/util/deep-equal.d.ts.map +1 -1
  25. package/dts/util/description.d.ts +1 -1
  26. package/dts/util/description.d.ts.map +1 -1
  27. package/dts/util/get-client.d.ts +2 -2
  28. package/dts/util/get-client.d.ts.map +1 -1
  29. package/dts/util/loader-map.d.ts +2 -2
  30. package/dts/util/loader-map.d.ts.map +1 -1
  31. package/dts/util/map-query.d.ts +13 -8
  32. package/dts/util/map-query.d.ts.map +1 -1
  33. package/dts/util/relation-map.d.ts +1 -1
  34. package/dts/util/relation-map.d.ts.map +1 -1
  35. package/dts/util/selections.d.ts +2 -2
  36. package/dts/util/selections.d.ts.map +1 -1
  37. package/dts/util/usage.d.ts.map +1 -1
  38. package/esm/connection-helpers.d.ts +2 -2
  39. package/esm/connection-helpers.d.ts.map +1 -1
  40. package/esm/field-builder.js +6 -6
  41. package/esm/field-builder.js.map +1 -1
  42. package/esm/generator.js +5 -5
  43. package/esm/generator.js.map +1 -1
  44. package/esm/global-types.d.ts +9 -9
  45. package/esm/global-types.d.ts.map +1 -1
  46. package/esm/global-types.js +1 -1
  47. package/esm/global-types.js.map +1 -1
  48. package/esm/index.d.ts +2 -2
  49. package/esm/index.d.ts.map +1 -1
  50. package/esm/index.js +4 -4
  51. package/esm/index.js.map +1 -1
  52. package/esm/interface-ref.d.ts +2 -2
  53. package/esm/interface-ref.d.ts.map +1 -1
  54. package/esm/interface-ref.js.map +1 -1
  55. package/esm/model-loader.d.ts +4 -4
  56. package/esm/model-loader.d.ts.map +1 -1
  57. package/esm/model-loader.js +13 -15
  58. package/esm/model-loader.js.map +1 -1
  59. package/esm/node-ref.d.ts +1 -1
  60. package/esm/node-ref.d.ts.map +1 -1
  61. package/esm/object-ref.d.ts +1 -1
  62. package/esm/object-ref.d.ts.map +1 -1
  63. package/esm/object-ref.js +4 -2
  64. package/esm/object-ref.js.map +1 -1
  65. package/esm/prisma-field-builder.d.ts +5 -5
  66. package/esm/prisma-field-builder.d.ts.map +1 -1
  67. package/esm/prisma-field-builder.js +7 -8
  68. package/esm/prisma-field-builder.js.map +1 -1
  69. package/esm/schema-builder.js +1 -1
  70. package/esm/schema-builder.js.map +1 -1
  71. package/esm/types.d.ts +8 -8
  72. package/esm/types.d.ts.map +1 -1
  73. package/esm/types.js.map +1 -1
  74. package/esm/util/cursors.d.ts +3 -3
  75. package/esm/util/cursors.d.ts.map +1 -1
  76. package/esm/util/cursors.js +2 -2
  77. package/esm/util/cursors.js.map +1 -1
  78. package/esm/util/datamodel.d.ts +3 -3
  79. package/esm/util/datamodel.d.ts.map +1 -1
  80. package/esm/util/datamodel.js.map +1 -1
  81. package/esm/util/deep-equal.d.ts.map +1 -1
  82. package/esm/util/deep-equal.js +1 -1
  83. package/esm/util/deep-equal.js.map +1 -1
  84. package/esm/util/description.d.ts +1 -1
  85. package/esm/util/description.d.ts.map +1 -1
  86. package/esm/util/description.js +1 -1
  87. package/esm/util/description.js.map +1 -1
  88. package/esm/util/get-client.d.ts +2 -2
  89. package/esm/util/get-client.d.ts.map +1 -1
  90. package/esm/util/get-client.js +1 -1
  91. package/esm/util/get-client.js.map +1 -1
  92. package/esm/util/loader-map.d.ts +2 -2
  93. package/esm/util/loader-map.d.ts.map +1 -1
  94. package/esm/util/loader-map.js +4 -5
  95. package/esm/util/loader-map.js.map +1 -1
  96. package/esm/util/map-query.d.ts +13 -8
  97. package/esm/util/map-query.d.ts.map +1 -1
  98. package/esm/util/map-query.js +20 -19
  99. package/esm/util/map-query.js.map +1 -1
  100. package/esm/util/relation-map.d.ts +1 -1
  101. package/esm/util/relation-map.d.ts.map +1 -1
  102. package/esm/util/relation-map.js +12 -12
  103. package/esm/util/relation-map.js.map +1 -1
  104. package/esm/util/selections.d.ts +2 -2
  105. package/esm/util/selections.d.ts.map +1 -1
  106. package/esm/util/selections.js +9 -9
  107. package/esm/util/selections.js.map +1 -1
  108. package/esm/util/usage.d.ts.map +1 -1
  109. package/esm/util/usage.js +0 -1
  110. package/esm/util/usage.js.map +1 -1
  111. package/generated.d.ts +1 -1
  112. package/lib/field-builder.js +7 -5
  113. package/lib/field-builder.js.map +1 -1
  114. package/lib/generator.js +4 -4
  115. package/lib/generator.js.map +1 -1
  116. package/lib/global-types.js +1 -1
  117. package/lib/global-types.js.map +1 -1
  118. package/lib/index.js +4 -4
  119. package/lib/index.js.map +1 -1
  120. package/lib/interface-ref.js.map +1 -1
  121. package/lib/model-loader.js +12 -14
  122. package/lib/model-loader.js.map +1 -1
  123. package/lib/object-ref.js +3 -1
  124. package/lib/object-ref.js.map +1 -1
  125. package/lib/prisma-field-builder.js +6 -7
  126. package/lib/prisma-field-builder.js.map +1 -1
  127. package/lib/schema-builder.js +1 -1
  128. package/lib/schema-builder.js.map +1 -1
  129. package/lib/types.js.map +1 -1
  130. package/lib/util/cursors.js +2 -2
  131. package/lib/util/cursors.js.map +1 -1
  132. package/lib/util/datamodel.js.map +1 -1
  133. package/lib/util/deep-equal.js +1 -1
  134. package/lib/util/deep-equal.js.map +1 -1
  135. package/lib/util/description.js +1 -1
  136. package/lib/util/description.js.map +1 -1
  137. package/lib/util/get-client.js +1 -1
  138. package/lib/util/get-client.js.map +1 -1
  139. package/lib/util/loader-map.js +4 -5
  140. package/lib/util/loader-map.js.map +1 -1
  141. package/lib/util/map-query.js +20 -19
  142. package/lib/util/map-query.js.map +1 -1
  143. package/lib/util/relation-map.js +12 -12
  144. package/lib/util/relation-map.js.map +1 -1
  145. package/lib/util/selections.js +9 -9
  146. package/lib/util/selections.js.map +1 -1
  147. package/lib/util/usage.js +0 -1
  148. package/lib/util/usage.js.map +1 -1
  149. package/package.json +12 -12
  150. package/src/connection-helpers.ts +2 -2
  151. package/src/field-builder.ts +30 -19
  152. package/src/generator.ts +5 -8
  153. package/src/global-types.ts +33 -28
  154. package/src/index.ts +12 -11
  155. package/src/interface-ref.ts +2 -2
  156. package/src/model-loader.ts +17 -19
  157. package/src/node-ref.ts +1 -1
  158. package/src/object-ref.ts +5 -3
  159. package/src/prisma-field-builder.ts +54 -53
  160. package/src/schema-builder.ts +8 -8
  161. package/src/types.ts +59 -60
  162. package/src/util/cursors.ts +7 -8
  163. package/src/util/datamodel.ts +3 -3
  164. package/src/util/deep-equal.ts +0 -1
  165. package/src/util/description.ts +1 -2
  166. package/src/util/get-client.ts +2 -3
  167. package/src/util/loader-map.ts +6 -8
  168. package/src/util/map-query.ts +49 -46
  169. package/src/util/relation-map.ts +13 -13
  170. package/src/util/selections.ts +10 -12
  171. package/src/util/usage.ts +0 -2
@@ -1,25 +1,23 @@
1
- /* eslint-disable no-param-reassign */
2
- /* eslint-disable no-continue */
1
+ import { PothosValidationError, getMappedArgumentValues } from '@pothos/core';
3
2
  import {
4
- FieldNode,
5
- FragmentDefinitionNode,
6
- getDirectiveValues,
7
- getNamedType,
8
- GraphQLField,
3
+ type FieldNode,
4
+ type FragmentDefinitionNode,
5
+ type GraphQLField,
9
6
  GraphQLIncludeDirective,
10
- GraphQLInterfaceType,
11
- GraphQLNamedType,
12
- GraphQLObjectType,
13
- GraphQLResolveInfo,
7
+ type GraphQLInterfaceType,
8
+ type GraphQLNamedType,
9
+ type GraphQLObjectType,
10
+ type GraphQLResolveInfo,
14
11
  GraphQLSkipDirective,
15
- InlineFragmentNode,
12
+ type InlineFragmentNode,
13
+ Kind,
14
+ type SelectionSetNode,
15
+ getDirectiveValues,
16
+ getNamedType,
16
17
  isInterfaceType,
17
18
  isObjectType,
18
- Kind,
19
- SelectionSetNode,
20
19
  } from 'graphql';
21
- import { getMappedArgumentValues, PothosValidationError } from '@pothos/core';
22
- import {
20
+ import type {
23
21
  FieldSelection,
24
22
  IncludeMap,
25
23
  IndirectInclude,
@@ -27,12 +25,12 @@ import {
27
25
  SelectionMap,
28
26
  } from '../types';
29
27
  import { setLoaderMappings } from './loader-map';
30
- import { FieldMap } from './relation-map';
28
+ import type { FieldMap } from './relation-map';
31
29
  import {
30
+ type SelectionState,
32
31
  createState,
33
32
  mergeSelection,
34
33
  selectionCompatible,
35
- SelectionState,
36
34
  selectionToQuery,
37
35
  } from './selections';
38
36
  import { wrapWithUsageCheck } from './usage';
@@ -49,36 +47,32 @@ function addTypeSelectionsForField(
49
47
  return;
50
48
  }
51
49
 
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
- };
50
+ const { pothosPrismaInclude, pothosPrismaSelect, pothosIndirectInclude, pothosPrismaModel } =
51
+ (type.extensions ?? {}) as {
52
+ pothosPrismaModel?: string;
53
+ pothosPrismaInclude?: IncludeMap;
54
+ pothosPrismaSelect?: IncludeMap;
55
+ pothosIndirectInclude?: IndirectInclude;
56
+ };
63
57
 
64
58
  if (
65
- (!!pothosPrismaIndirectInclude?.path && pothosPrismaIndirectInclude.path.length > 0) ||
66
- (!!pothosPrismaIndirectInclude?.paths && pothosPrismaIndirectInclude.paths.length === 0)
59
+ (!!pothosIndirectInclude?.path && pothosIndirectInclude.path.length > 0) ||
60
+ (!!pothosIndirectInclude?.paths && pothosIndirectInclude.paths.length === 0)
67
61
  ) {
68
62
  resolveIndirectIncludePaths(
69
63
  type,
70
64
  info,
71
65
  selection,
72
66
  [],
73
- pothosPrismaIndirectInclude.paths ?? [pothosPrismaIndirectInclude.path!],
67
+ pothosIndirectInclude.paths ?? [pothosIndirectInclude.path!],
74
68
  indirectPath,
75
69
  (resolvedType, field, path) => {
76
70
  addTypeSelectionsForField(resolvedType, context, info, state, field, path);
77
71
  },
78
72
  );
79
- } else if (pothosPrismaIndirectInclude) {
73
+ } else if (pothosIndirectInclude) {
80
74
  addTypeSelectionsForField(
81
- info.schema.getType(pothosPrismaIndirectInclude.getType())!,
75
+ info.schema.getType(pothosIndirectInclude.getType())!,
82
76
  context,
83
77
  info,
84
78
  state,
@@ -335,7 +329,7 @@ function addFieldSelection(
335
329
  returnType,
336
330
  info,
337
331
  selection,
338
- (returnType.extensions?.pothosPrismaIndirectInclude as { path: [] })?.path ?? [],
332
+ (returnType.extensions?.pothosIndirectInclude as { path: [] })?.path ?? [],
339
333
  normalizedIndirectInclude?.paths ??
340
334
  (normalizedIndirectInclude?.path ? [normalizedIndirectInclude.path] : []),
341
335
  [],
@@ -359,7 +353,6 @@ function addFieldSelection(
359
353
 
360
354
  addTypeSelectionsForField(returnType, context, info, fieldState, selection, []);
361
355
 
362
- // eslint-disable-next-line prefer-destructuring
363
356
  mappings = fieldState.mappings;
364
357
 
365
358
  return selectionToQuery(fieldState);
@@ -403,11 +396,15 @@ function addFieldSelection(
403
396
  }
404
397
  }
405
398
 
406
- export function queryFromInfo<T extends SelectionMap['select'] | undefined = undefined>({
399
+ export function queryFromInfo<
400
+ Select extends SelectionMap['select'] | undefined = undefined,
401
+ Include extends SelectionMap['select'] | undefined = undefined,
402
+ >({
407
403
  context,
408
404
  info,
409
405
  typeName,
410
406
  select,
407
+ include,
411
408
  path = [],
412
409
  paths = [],
413
410
  withUsageCheck = false,
@@ -415,27 +412,33 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
415
412
  context: object;
416
413
  info: GraphQLResolveInfo;
417
414
  typeName?: string;
418
- select?: T;
419
415
  path?: string[];
420
416
  paths?: string[][];
421
417
  withUsageCheck?: boolean;
422
- }): { include?: {} } | { select: T } {
418
+ } & (
419
+ | { include?: Include; select?: never }
420
+ | { select?: Select; include?: never }
421
+ )): undefined extends Include
422
+ ? {
423
+ select: Select;
424
+ }
425
+ : { include: Include } {
423
426
  const returnType = getNamedType(info.returnType);
424
427
  const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
425
428
 
426
429
  let state: SelectionState | undefined;
427
- const initialSelection = select ? { select } : undefined;
430
+ const initialSelection = select ? { select } : include ? { include } : undefined;
428
431
 
429
432
  if (path.length > 0 || paths.length > 0) {
430
- const { pothosPrismaIndirectInclude } = (returnType.extensions ?? {}) as {
431
- pothosPrismaIndirectInclude?: IndirectInclude;
433
+ const { pothosIndirectInclude } = (returnType.extensions ?? {}) as {
434
+ pothosIndirectInclude?: IndirectInclude;
432
435
  };
433
436
 
434
437
  resolveIndirectInclude(
435
438
  returnType,
436
439
  info,
437
440
  info.fieldNodes[0],
438
- pothosPrismaIndirectInclude?.path ?? [],
441
+ pothosIndirectInclude?.path ?? [],
439
442
  [],
440
443
  (indirectType, indirectField, subPath) => {
441
444
  resolveIndirectIncludePaths(
@@ -479,7 +482,7 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
479
482
 
480
483
  setLoaderMappings(context, info, state.mappings);
481
484
 
482
- const query = selectionToQuery(state) as { select: T };
485
+ const query = selectionToQuery(state) as { select: Select; include: Include };
483
486
 
484
487
  return withUsageCheck ? wrapWithUsageCheck(query) : query;
485
488
  }
@@ -530,9 +533,9 @@ function createStateForType(
530
533
  export function getIndirectType(type: GraphQLNamedType, info: GraphQLResolveInfo) {
531
534
  let targetType = type;
532
535
 
533
- while (targetType.extensions?.pothosPrismaIndirectInclude) {
536
+ while (targetType.extensions?.pothosIndirectInclude) {
534
537
  targetType = info.schema.getType(
535
- (targetType.extensions?.pothosPrismaIndirectInclude as IndirectInclude).getType(),
538
+ (targetType.extensions?.pothosIndirectInclude as IndirectInclude).getType(),
536
539
  )!;
537
540
  }
538
541
 
@@ -1,5 +1,5 @@
1
1
  import { createContextCache } from '@pothos/core';
2
- import { DMMF, RuntimeDataModel } from './get-client';
2
+ import type { DMMF, RuntimeDataModel } from './get-client';
3
3
 
4
4
  export interface FieldMap {
5
5
  model: string;
@@ -16,33 +16,33 @@ export function createRelationMap({ models }: DMMF['datamodel'] | RuntimeDataMod
16
16
  const relationMap: RelationMap = new Map();
17
17
 
18
18
  if (Array.isArray(models)) {
19
- models.forEach((model) => {
19
+ for (const model of models) {
20
20
  relationMap.set(model.name, { model: model.name, relations: new Map() });
21
- });
21
+ }
22
22
 
23
- models.forEach((model) => {
23
+ for (const model of models) {
24
24
  const map = relationMap.get(model.name)!.relations;
25
25
 
26
- model.fields.forEach((field) => {
26
+ for (const field of model.fields) {
27
27
  if (field.kind === 'object' && relationMap.has(field.type)) {
28
28
  map.set(field.name, relationMap.get(field.type)!);
29
29
  }
30
- });
31
- });
30
+ }
31
+ }
32
32
  } else {
33
- Object.keys(models).forEach((name) => {
33
+ for (const name of Object.keys(models)) {
34
34
  relationMap.set(name, { model: name, relations: new Map() });
35
- });
35
+ }
36
36
 
37
- Object.entries(models).forEach(([name, model]) => {
37
+ for (const [name, model] of Object.entries(models)) {
38
38
  const map = relationMap.get(name)!.relations;
39
39
 
40
- model.fields.forEach((field) => {
40
+ for (const field of model.fields) {
41
41
  if (field.kind === 'object' && relationMap.has(field.type)) {
42
42
  map.set(field.name, relationMap.get(field.type)!);
43
43
  }
44
- });
45
- });
44
+ }
45
+ }
46
46
  }
47
47
 
48
48
  return relationMap;
@@ -1,8 +1,6 @@
1
- /* eslint-disable no-param-reassign */
2
- /* eslint-disable no-underscore-dangle */
3
- import { LoaderMappings, SelectionMap } from '../types';
1
+ import type { LoaderMappings, SelectionMap } from '../types';
4
2
  import { deepEqual } from './deep-equal';
5
- import { FieldMap } from './relation-map';
3
+ import type { FieldMap } from './relation-map';
6
4
 
7
5
  export type SelectionMode = 'include' | 'select';
8
6
 
@@ -114,15 +112,15 @@ export function mergeSelection(state: SelectionState, { select, include, ...quer
114
112
  }
115
113
 
116
114
  if (include) {
117
- Object.keys(include).forEach((key) => {
115
+ for (const key of Object.keys(include)) {
118
116
  merge(key, include[key]);
119
- });
117
+ }
120
118
  }
121
119
 
122
120
  if (select) {
123
- Object.keys(select).forEach((key) => {
121
+ for (const key of Object.keys(select)) {
124
122
  merge(key, select[key]);
125
- });
123
+ }
126
124
  }
127
125
 
128
126
  if (Object.keys(query).length > 0) {
@@ -136,9 +134,9 @@ export function mergeSelection(state: SelectionState, { select, include, ...quer
136
134
 
137
135
  if (key === '_count') {
138
136
  const counts = (value as { select?: Record<string, boolean> }).select ?? {};
139
- Object.keys(counts).forEach((count) => {
137
+ for (const count of Object.keys(counts)) {
140
138
  state.counts.set(count, counts[count]);
141
- });
139
+ }
142
140
 
143
141
  return;
144
142
  }
@@ -184,10 +182,10 @@ export function selectionToQuery(state: SelectionState): SelectionMap {
184
182
  }
185
183
 
186
184
  if (state.mode === 'select') {
187
- state.fields.forEach((field) => {
185
+ for (const field of state.fields) {
188
186
  hasSelection = true;
189
187
  nestedIncludes[field] = true;
190
- });
188
+ }
191
189
 
192
190
  return {
193
191
  ...(state.query as SelectionMap),
package/src/util/usage.ts CHANGED
@@ -20,7 +20,6 @@ export function wrapWithUsageCheck<T extends Object>(obj: T): T {
20
20
  Object.defineProperty(result, key, {
21
21
  enumerable: true,
22
22
  configurable: true,
23
- // eslint-disable-next-line @typescript-eslint/no-loop-func
24
23
  get() {
25
24
  used = true;
26
25
  return obj[key as keyof T];
@@ -47,7 +46,6 @@ export function extendWithUsage<T extends object, U extends object>(
47
46
 
48
47
  for (const key of [usageSymbol, ...Object.keys(original)]) {
49
48
  if (key in result) {
50
- // eslint-disable-next-line no-continue
51
49
  continue;
52
50
  }
53
51