@pothos/plugin-prisma 3.65.2 → 4.0.0-next.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 (119) hide show
  1. package/CHANGELOG.md +21 -4
  2. package/README.md +3 -5
  3. package/dts/connection-helpers.d.ts +10 -10
  4. package/dts/connection-helpers.d.ts.map +1 -1
  5. package/dts/global-types.d.ts +25 -25
  6. package/dts/global-types.d.ts.map +1 -1
  7. package/dts/index.d.ts +2 -2
  8. package/dts/index.d.ts.map +1 -1
  9. package/dts/interface-ref.d.ts +3 -3
  10. package/dts/interface-ref.d.ts.map +1 -1
  11. package/dts/model-loader.d.ts +6 -6
  12. package/dts/model-loader.d.ts.map +1 -1
  13. package/dts/node-ref.d.ts +2 -1
  14. package/dts/node-ref.d.ts.map +1 -1
  15. package/dts/object-ref.d.ts +2 -2
  16. package/dts/object-ref.d.ts.map +1 -1
  17. package/dts/prisma-field-builder.d.ts +64 -48
  18. package/dts/prisma-field-builder.d.ts.map +1 -1
  19. package/dts/types.d.ts +81 -55
  20. package/dts/types.d.ts.map +1 -1
  21. package/dts/util/cursors.d.ts.map +1 -1
  22. package/dts/util/datamodel.d.ts +5 -5
  23. package/dts/util/datamodel.d.ts.map +1 -1
  24. package/dts/util/map-query.d.ts.map +1 -1
  25. package/dts/util/relation-map.d.ts +1 -1
  26. package/dts/util/relation-map.d.ts.map +1 -1
  27. package/esm/connection-helpers.d.ts +7 -7
  28. package/esm/connection-helpers.d.ts.map +1 -1
  29. package/esm/connection-helpers.js.map +1 -1
  30. package/esm/field-builder.js.map +1 -1
  31. package/esm/generator.js +58 -6
  32. package/esm/generator.js.map +1 -1
  33. package/esm/global-types.d.ts +36 -36
  34. package/esm/global-types.d.ts.map +1 -1
  35. package/esm/global-types.js.map +1 -1
  36. package/esm/index.d.ts +2 -2
  37. package/esm/index.d.ts.map +1 -1
  38. package/esm/index.js +13 -2
  39. package/esm/index.js.map +1 -1
  40. package/esm/interface-ref.d.ts +3 -3
  41. package/esm/interface-ref.d.ts.map +1 -1
  42. package/esm/interface-ref.js.map +1 -1
  43. package/esm/model-loader.d.ts +6 -6
  44. package/esm/model-loader.d.ts.map +1 -1
  45. package/esm/model-loader.js.map +1 -1
  46. package/esm/node-ref.d.ts +2 -1
  47. package/esm/node-ref.d.ts.map +1 -1
  48. package/esm/node-ref.js.map +1 -1
  49. package/esm/object-ref.d.ts +2 -2
  50. package/esm/object-ref.d.ts.map +1 -1
  51. package/esm/object-ref.js.map +1 -1
  52. package/esm/prisma-field-builder.d.ts +64 -48
  53. package/esm/prisma-field-builder.d.ts.map +1 -1
  54. package/esm/prisma-field-builder.js +14 -5
  55. package/esm/prisma-field-builder.js.map +1 -1
  56. package/esm/schema-builder.js +3 -3
  57. package/esm/schema-builder.js.map +1 -1
  58. package/esm/types.d.ts +82 -58
  59. package/esm/types.d.ts.map +1 -1
  60. package/esm/types.js.map +1 -1
  61. package/esm/util/cursors.d.ts.map +1 -1
  62. package/esm/util/cursors.js.map +1 -1
  63. package/esm/util/datamodel.d.ts +5 -5
  64. package/esm/util/datamodel.d.ts.map +1 -1
  65. package/esm/util/datamodel.js.map +1 -1
  66. package/esm/util/deep-equal.js.map +1 -1
  67. package/esm/util/description.js.map +1 -1
  68. package/esm/util/get-client.js.map +1 -1
  69. package/esm/util/loader-map.js.map +1 -1
  70. package/esm/util/map-query.d.ts.map +1 -1
  71. package/esm/util/map-query.js +3 -3
  72. package/esm/util/map-query.js.map +1 -1
  73. package/esm/util/relation-map.d.ts +1 -1
  74. package/esm/util/relation-map.d.ts.map +1 -1
  75. package/esm/util/relation-map.js.map +1 -1
  76. package/esm/util/selections.js.map +1 -1
  77. package/esm/util/usage.js.map +1 -1
  78. package/lib/connection-helpers.js.map +1 -1
  79. package/lib/field-builder.js.map +1 -1
  80. package/lib/generator.js +58 -6
  81. package/lib/generator.js.map +1 -1
  82. package/lib/global-types.js.map +1 -1
  83. package/lib/index.js +16 -5
  84. package/lib/index.js.map +1 -1
  85. package/lib/interface-ref.js.map +1 -1
  86. package/lib/model-loader.js.map +1 -1
  87. package/lib/node-ref.js.map +1 -1
  88. package/lib/object-ref.js.map +1 -1
  89. package/lib/prisma-field-builder.js +14 -5
  90. package/lib/prisma-field-builder.js.map +1 -1
  91. package/lib/schema-builder.js +3 -3
  92. package/lib/schema-builder.js.map +1 -1
  93. package/lib/types.js.map +1 -1
  94. package/lib/util/cursors.js.map +1 -1
  95. package/lib/util/datamodel.js.map +1 -1
  96. package/lib/util/deep-equal.js.map +1 -1
  97. package/lib/util/description.js.map +1 -1
  98. package/lib/util/get-client.js.map +1 -1
  99. package/lib/util/loader-map.js.map +1 -1
  100. package/lib/util/map-query.js +1 -1
  101. package/lib/util/map-query.js.map +1 -1
  102. package/lib/util/relation-map.js.map +1 -1
  103. package/lib/util/selections.js.map +1 -1
  104. package/lib/util/usage.js.map +1 -1
  105. package/package.json +15 -15
  106. package/src/connection-helpers.ts +7 -6
  107. package/src/field-builder.ts +12 -11
  108. package/src/generator.ts +93 -4
  109. package/src/global-types.ts +62 -54
  110. package/src/index.ts +11 -5
  111. package/src/interface-ref.ts +9 -5
  112. package/src/model-loader.ts +6 -6
  113. package/src/node-ref.ts +6 -1
  114. package/src/object-ref.ts +12 -2
  115. package/src/prisma-field-builder.ts +101 -74
  116. package/src/schema-builder.ts +10 -7
  117. package/src/types.ts +186 -183
  118. package/src/util/datamodel.ts +5 -5
  119. package/src/util/map-query.ts +2 -3
package/src/generator.ts CHANGED
@@ -5,6 +5,7 @@ import { mkdir, writeFile } from 'node:fs';
5
5
  import { dirname, join, resolve as resolvePath, posix } from 'node:path';
6
6
  import ts, { ListFormat, ScriptKind, ScriptTarget, SyntaxKind, version } from 'typescript';
7
7
  import { DMMF, generatorHandler } from '@prisma/generator-helper';
8
+ import { PothosPrismaDatamodel } from './types';
8
9
 
9
10
  const MIN_TS_VERSION = [4, 5, 2];
10
11
 
@@ -28,6 +29,14 @@ function checkTSVersion() {
28
29
 
29
30
  const defaultOutput = resolvePath(__dirname, '../generated.ts');
30
31
 
32
+ interface GeneratorConfig {
33
+ clientOutput?: string;
34
+ prismaUtils?: string;
35
+ pluginPath?: string;
36
+ generateDatamodel?: string;
37
+ documentation?: string;
38
+ }
39
+
31
40
  generatorHandler({
32
41
  onManifest: () => ({
33
42
  prettyName: 'Pothos integration',
@@ -36,7 +45,7 @@ generatorHandler({
36
45
  }),
37
46
  onGenerate: async (options) => {
38
47
  checkTSVersion();
39
- const config = options.generator.config as { clientOutput?: string; prismaUtils?: string };
48
+ const config = options.generator.config as GeneratorConfig;
40
49
  const prismaLocation =
41
50
  config.clientOutput ??
42
51
  options.otherGenerators.find((gen) => gen.provider.value === 'prisma-client-js')!.output!
@@ -45,7 +54,7 @@ generatorHandler({
45
54
  const outputLocation = options.generator.output?.value ?? defaultOutput;
46
55
  const prismaTypes = buildTypes(options.dmmf, config);
47
56
 
48
- await generateOutput(options.dmmf, prismaTypes, prismaLocation, outputLocation);
57
+ await generateOutput(options.dmmf, prismaTypes, prismaLocation, outputLocation, config);
49
58
 
50
59
  if (outputLocation === defaultOutput) {
51
60
  await generateOutput(
@@ -53,18 +62,57 @@ generatorHandler({
53
62
  prismaTypes,
54
63
  prismaLocation.startsWith('@') ? prismaLocation : posix.join(prismaLocation, 'index.js'),
55
64
  join(outputLocation, '../esm/generated.ts'),
65
+ config,
56
66
  );
57
67
  }
58
68
  },
59
69
  });
60
70
 
71
+ function trimDmmf(dmmf: DMMF.Document, documentation = false): PothosPrismaDatamodel {
72
+ const trimmed: PothosPrismaDatamodel = {
73
+ datamodel: {
74
+ models: {},
75
+ },
76
+ };
77
+
78
+ dmmf.datamodel.models.forEach((model) => {
79
+ trimmed.datamodel.models[model.name] = {
80
+ fields: model.fields.map((field) => ({
81
+ type: field.type,
82
+ kind: field.kind,
83
+ name: field.name,
84
+ isRequired: field.isRequired,
85
+ isList: field.isList,
86
+ hasDefaultValue: field.hasDefaultValue,
87
+ isUnique: field.isUnique,
88
+ isId: field.isId,
89
+ relationName: field.relationName,
90
+ relationFromFields: field.relationFromFields,
91
+ isUpdatedAt: field.isUpdatedAt,
92
+ documentation: documentation ? field.documentation : undefined,
93
+ })),
94
+ primaryKey: model.primaryKey
95
+ ? { name: model.primaryKey.name, fields: model.primaryKey.fields }
96
+ : null,
97
+ uniqueIndexes: model.uniqueIndexes.map((index) => ({
98
+ name: index.name,
99
+ fields: index.fields,
100
+ })),
101
+ documentation: documentation ? model.documentation : undefined,
102
+ };
103
+ });
104
+
105
+ return trimmed;
106
+ }
107
+
61
108
  async function generateOutput(
62
109
  dmmf: DMMF.Document,
63
110
  prismaTypes: ts.InterfaceDeclaration,
64
111
  prismaLocation: string,
65
112
  outputLocation: string,
113
+ config: GeneratorConfig,
66
114
  ) {
67
- const importStatement = ts.factory.createImportDeclaration(
115
+ const prismaImportStatement = ts.factory.createImportDeclaration(
68
116
  ...modifiersArg,
69
117
  [],
70
118
  ts.factory.createImportClause(
@@ -84,6 +132,23 @@ async function generateOutput(
84
132
  ts.factory.createStringLiteral(prismaLocation),
85
133
  );
86
134
 
135
+ const dmmfImportStatement = ts.factory.createImportDeclaration(
136
+ ...modifiersArg,
137
+ [],
138
+ ts.factory.createImportClause(
139
+ true,
140
+ undefined,
141
+ ts.factory.createNamedImports([
142
+ ts.factory.createImportSpecifier(
143
+ false,
144
+ undefined,
145
+ ts.factory.createIdentifier('PothosPrismaDatamodel'),
146
+ ),
147
+ ]),
148
+ ),
149
+ ts.factory.createStringLiteral(config.pluginPath ?? '@pothos/plugin-prisma'),
150
+ );
151
+
87
152
  const printer = ts.createPrinter({});
88
153
 
89
154
  const sourcefile = ts.createSourceFile(
@@ -94,7 +159,31 @@ async function generateOutput(
94
159
  ScriptKind.TS,
95
160
  );
96
161
 
97
- const nodes = ts.factory.createNodeArray([importStatement, prismaTypes]);
162
+ const trimmedDatamodel = trimDmmf(dmmf, config.documentation === 'true');
163
+
164
+ const dmmfExport = ts.factory.createFunctionDeclaration(
165
+ [ts.factory.createModifier(SyntaxKind.ExportKeyword)],
166
+ undefined,
167
+ 'getDatamodel',
168
+ [],
169
+ [],
170
+ ts.factory.createTypeReferenceNode('PothosPrismaDatamodel'),
171
+ ts.factory.createBlock([
172
+ ts.factory.createReturnStatement(
173
+ ts.factory.createCallExpression(
174
+ ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('JSON'), 'parse'),
175
+ [],
176
+ [ts.factory.createStringLiteral(JSON.stringify(trimmedDatamodel))],
177
+ ),
178
+ ),
179
+ ]),
180
+ );
181
+
182
+ const nodes = ts.factory.createNodeArray(
183
+ config.generateDatamodel === 'true'
184
+ ? [prismaImportStatement, dmmfImportStatement, prismaTypes, dmmfExport]
185
+ : [prismaImportStatement, prismaTypes],
186
+ );
98
187
 
99
188
  const result = printer.printList(ListFormat.SourceFileStatements, nodes, sourcefile);
100
189
 
@@ -2,6 +2,7 @@
2
2
  /* eslint-disable @typescript-eslint/no-empty-interface */
3
3
  import { GraphQLResolveInfo } from 'graphql';
4
4
  import {
5
+ ArgumentRef,
5
6
  FieldKind,
6
7
  FieldMap,
7
8
  FieldNullability,
@@ -36,12 +37,12 @@ import {
36
37
  ShapeFromSelection,
37
38
  } from './types';
38
39
 
39
- import type { PrismaPlugin } from '.';
40
+ import type { PothosPrismaPlugin } from '.';
40
41
 
41
42
  declare global {
42
43
  export namespace PothosSchemaTypes {
43
44
  export interface Plugins<Types extends SchemaTypes> {
44
- prisma: PrismaPlugin<Types>;
45
+ prisma: PothosPrismaPlugin<Types>;
45
46
  }
46
47
 
47
48
  export interface SchemaBuilderOptions<Types extends SchemaTypes> {
@@ -111,7 +112,6 @@ declare global {
111
112
  prismaObject: <
112
113
  Name extends keyof Types['PrismaTypes'],
113
114
  Interfaces extends InterfaceParam<Types>[],
114
- FindUnique,
115
115
  Model extends PrismaModelTypes & Types['PrismaTypes'][Name],
116
116
  Include = unknown,
117
117
  Select = unknown,
@@ -121,12 +121,12 @@ declare global {
121
121
  Types,
122
122
  Model,
123
123
  Interfaces,
124
- FindUnique,
125
124
  Include,
126
125
  Select,
127
126
  ShapeFromSelection<Types, Model, { select: Select; include: Include }>
128
127
  >,
129
128
  ) => PrismaObjectRef<
129
+ Types,
130
130
  Model,
131
131
  ShapeFromSelection<Types, Model, { select: Select; include: Include }>
132
132
  >;
@@ -134,7 +134,6 @@ declare global {
134
134
  prismaInterface: <
135
135
  Name extends keyof Types['PrismaTypes'],
136
136
  Interfaces extends InterfaceParam<Types>[],
137
- FindUnique,
138
137
  Model extends PrismaModelTypes & Types['PrismaTypes'][Name],
139
138
  Include = unknown,
140
139
  Select = unknown,
@@ -144,22 +143,22 @@ declare global {
144
143
  Types,
145
144
  Model,
146
145
  Interfaces,
147
- FindUnique,
148
146
  Include,
149
147
  Select,
150
148
  ShapeFromSelection<Types, Model, { select: Select; include: Include }>
151
149
  >,
152
150
  ) => PrismaInterfaceRef<
151
+ Types,
153
152
  Model,
154
153
  ShapeFromSelection<Types, Model, { select: Select; include: Include }>
155
154
  >;
156
155
 
157
156
  prismaObjectField: <
158
- Type extends PrismaObjectRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
159
- Model extends PrismaModelTypes = Type extends PrismaObjectRef<infer M, {}>
157
+ Type extends PrismaObjectRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
158
+ Model extends PrismaModelTypes = Type extends PrismaObjectRef<Types, infer M, {}>
160
159
  ? M
161
160
  : PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
162
- Shape extends {} = Type extends PrismaObjectRef<PrismaModelTypes, infer S>
161
+ Shape extends {} = Type extends PrismaObjectRef<Types, PrismaModelTypes, infer S>
163
162
  ? S & { [prismaModelName]?: Model['Name'] }
164
163
  : Model['Shape'] & {
165
164
  [prismaModelName]?: Type;
@@ -167,15 +166,15 @@ declare global {
167
166
  >(
168
167
  type: Type,
169
168
  fieldName: string,
170
- field: (t: PrismaObjectFieldBuilder<Types, Model, false, Shape>) => FieldRef,
169
+ field: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldRef<Types>,
171
170
  ) => void;
172
171
 
173
172
  prismaInterfaceField: <
174
- Type extends PrismaInterfaceRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
175
- Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<infer M, {}>
173
+ Type extends PrismaInterfaceRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
174
+ Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<Types, infer M, {}>
176
175
  ? M
177
176
  : PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
178
- Shape extends {} = Type extends PrismaInterfaceRef<PrismaModelTypes, infer S>
177
+ Shape extends {} = Type extends PrismaInterfaceRef<Types, PrismaModelTypes, infer S>
179
178
  ? S & { [prismaModelName]?: Model['Name'] }
180
179
  : Model['Shape'] & {
181
180
  [prismaModelName]?: Type;
@@ -183,37 +182,37 @@ declare global {
183
182
  >(
184
183
  type: Type,
185
184
  fieldName: string,
186
- field: (t: PrismaObjectFieldBuilder<Types, Model, false, Shape>) => FieldRef,
185
+ field: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldRef<Types>,
187
186
  ) => void;
188
187
 
189
188
  prismaObjectFields: <
190
- Type extends PrismaObjectRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
191
- Model extends PrismaModelTypes = Type extends PrismaObjectRef<infer M, {}>
189
+ Type extends PrismaObjectRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
190
+ Model extends PrismaModelTypes = Type extends PrismaObjectRef<Types, infer M, {}>
192
191
  ? M
193
192
  : PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
194
- Shape extends {} = Type extends PrismaObjectRef<PrismaModelTypes, infer S>
193
+ Shape extends {} = Type extends PrismaObjectRef<Types, PrismaModelTypes, infer S>
195
194
  ? S & { [prismaModelName]?: Model['Name'] }
196
195
  : Model['Shape'] & {
197
196
  [prismaModelName]?: Type;
198
197
  },
199
198
  >(
200
199
  type: Type,
201
- fields: (t: PrismaObjectFieldBuilder<Types, Model, false, Shape>) => FieldMap,
200
+ fields: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldMap,
202
201
  ) => void;
203
202
 
204
203
  prismaInterfaceFields: <
205
- Type extends PrismaInterfaceRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
206
- Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<infer M, {}>
204
+ Type extends PrismaInterfaceRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
205
+ Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<Types, infer M, {}>
207
206
  ? M
208
207
  : PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
209
- Shape extends {} = Type extends PrismaInterfaceRef<PrismaModelTypes, infer S>
208
+ Shape extends {} = Type extends PrismaInterfaceRef<Types, PrismaModelTypes, infer S>
210
209
  ? S & { [prismaModelName]?: Model['Name'] }
211
210
  : Model['Shape'] & {
212
211
  [prismaModelName]?: Type;
213
212
  },
214
213
  >(
215
214
  type: Type,
216
- fields: (t: PrismaObjectFieldBuilder<Types, Model, false, Shape>) => FieldMap,
215
+ fields: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldMap,
217
216
  ) => void;
218
217
 
219
218
  prismaNode: 'relay' extends PluginName
@@ -239,6 +238,7 @@ declare global {
239
238
  UniqueField
240
239
  >,
241
240
  ) => PrismaNodeRef<
241
+ Types,
242
242
  PrismaModelTypes & Types['PrismaTypes'][Name],
243
243
  ShapeFromSelection<
244
244
  Types,
@@ -257,22 +257,22 @@ declare global {
257
257
  prismaField: <
258
258
  Args extends InputFieldMap,
259
259
  TypeParam extends
260
- | PrismaRef<PrismaModelTypes>
260
+ | PrismaRef<Types, PrismaModelTypes>
261
261
  | keyof Types['PrismaTypes']
262
262
  | [keyof Types['PrismaTypes']]
263
- | [PrismaRef<PrismaModelTypes>],
263
+ | [PrismaRef<Types, PrismaModelTypes>],
264
264
  Nullable extends FieldNullability<Type>,
265
265
  ResolveShape,
266
266
  ResolveReturnShape,
267
267
  Type extends TypeParam extends [unknown]
268
- ? [ObjectRef<Model['Shape']>]
269
- : ObjectRef<Model['Shape']>,
268
+ ? [ObjectRef<Types, Model['Shape']>]
269
+ : ObjectRef<Types, Model['Shape']>,
270
270
  Model extends PrismaModelTypes = PrismaModelTypes &
271
271
  (TypeParam extends [keyof Types['PrismaTypes']]
272
272
  ? Types['PrismaTypes'][TypeParam[0]]
273
- : TypeParam extends [PrismaRef<PrismaModelTypes>]
273
+ : TypeParam extends [PrismaRef<Types, PrismaModelTypes>]
274
274
  ? TypeParam[0][typeof prismaModelKey]
275
- : TypeParam extends PrismaRef<PrismaModelTypes>
275
+ : TypeParam extends PrismaRef<Types, PrismaModelTypes>
276
276
  ? TypeParam[typeof prismaModelKey]
277
277
  : TypeParam extends keyof Types['PrismaTypes']
278
278
  ? Types['PrismaTypes'][TypeParam]
@@ -290,18 +290,18 @@ declare global {
290
290
  ResolveReturnShape,
291
291
  Kind
292
292
  >,
293
- ) => FieldRef<ShapeFromTypeParam<Types, Type, Nullable>>;
293
+ ) => FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>>;
294
294
 
295
295
  prismaConnection: 'relay' extends PluginName
296
296
  ? <
297
- Type extends PrismaRef<PrismaModelTypes> | keyof Types['PrismaTypes'],
297
+ Type extends PrismaRef<Types, PrismaModelTypes> | keyof Types['PrismaTypes'],
298
298
  Nullable extends boolean,
299
299
  ResolveReturnShape,
300
300
  Args extends InputFieldMap = {},
301
- Model extends PrismaModelTypes = Type extends PrismaRef<infer T>
301
+ Model extends PrismaModelTypes = Type extends PrismaRef<Types, infer T>
302
302
  ? T
303
303
  : PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
304
- Shape = Type extends PrismaRef<PrismaModelTypes, infer S> ? S : Model['Shape'],
304
+ Shape = Type extends PrismaRef<Types, PrismaModelTypes, infer S> ? S : Model['Shape'],
305
305
  ConnectionInterfaces extends InterfaceParam<Types>[] = [],
306
306
  EdgeInterfaces extends InterfaceParam<Types>[] = [],
307
307
  >(
@@ -310,7 +310,7 @@ declare global {
310
310
  ParentShape,
311
311
  Type,
312
312
  Model,
313
- ObjectRef<Model['Shape']>,
313
+ ObjectRef<Types, Model['Shape']>,
314
314
  Nullable,
315
315
  Args,
316
316
  ResolveReturnShape,
@@ -321,54 +321,63 @@ declare global {
321
321
  connectionOptions:
322
322
  | ConnectionObjectOptions<
323
323
  Types,
324
- ObjectRef<Shape>,
324
+ ObjectRef<Types, Shape>,
325
325
  false,
326
326
  false,
327
327
  PrismaConnectionShape<Types, Shape, ParentShape, Args>,
328
328
  ConnectionInterfaces
329
329
  >
330
- | ObjectRef<ShapeFromConnection<ConnectionShapeHelper<Types, Shape, false>>>,
330
+ | ObjectRef<
331
+ Types,
332
+ ShapeFromConnection<ConnectionShapeHelper<Types, Shape, false>>
333
+ >,
331
334
  edgeOptions:
332
335
  | ConnectionEdgeObjectOptions<
333
336
  Types,
334
- ObjectRef<Shape>,
337
+ ObjectRef<Types, Shape>,
335
338
  false,
336
339
  PrismaConnectionShape<Types, Shape, ParentShape, Args>,
337
340
  EdgeInterfaces
338
341
  >
339
- | ObjectRef<{
340
- cursor: string;
341
- node?: Shape | null | undefined;
342
- }>,
342
+ | ObjectRef<
343
+ Types,
344
+ {
345
+ cursor: string;
346
+ node?: Shape | null | undefined;
347
+ }
348
+ >,
343
349
  ],
344
350
  0
345
351
  >
346
- ) => FieldRef<ShapeFromConnection<ConnectionShapeHelper<Types, Model['Shape'], Nullable>>>
352
+ ) => FieldRef<
353
+ Types,
354
+ ShapeFromConnection<ConnectionShapeHelper<Types, Model['Shape'], Nullable>>
355
+ >
347
356
  : '@pothos/plugin-relay is required to use this method';
348
357
 
349
358
  prismaFieldWithInput: 'prisma' extends PluginName
350
359
  ? <
351
- Fields extends Record<string, InputFieldRef<unknown, 'InputObject'>>,
360
+ Fields extends Record<string, InputFieldRef<Types, unknown>>,
352
361
  TypeParam extends
353
- | PrismaRef<PrismaModelTypes>
362
+ | PrismaRef<Types, PrismaModelTypes>
354
363
  | keyof Types['PrismaTypes']
355
364
  | [keyof Types['PrismaTypes']]
356
- | [PrismaRef<PrismaModelTypes>],
365
+ | [PrismaRef<Types, PrismaModelTypes>],
357
366
  Type extends TypeParam extends [unknown]
358
- ? [ObjectRef<Model['Shape']>]
359
- : ObjectRef<Model['Shape']>,
367
+ ? [ObjectRef<Types, Model['Shape']>]
368
+ : ObjectRef<Types, Model['Shape']>,
360
369
  ResolveShape,
361
370
  ResolveReturnShape,
362
371
  ArgRequired extends boolean,
363
- Args extends Record<string, InputFieldRef<unknown, 'Arg'>> = {},
372
+ Args extends Record<string, ArgumentRef<Types, unknown>> = {},
364
373
  Nullable extends FieldNullability<Type> = Types['DefaultFieldNullability'],
365
374
  InputName extends string = 'input',
366
375
  Model extends PrismaModelTypes = PrismaModelTypes &
367
376
  (TypeParam extends [keyof Types['PrismaTypes']]
368
377
  ? Types['PrismaTypes'][TypeParam[0]]
369
- : TypeParam extends [PrismaRef<PrismaModelTypes>]
378
+ : TypeParam extends [PrismaRef<Types, PrismaModelTypes>]
370
379
  ? TypeParam[0][typeof prismaModelKey]
371
- : TypeParam extends PrismaRef<PrismaModelTypes>
380
+ : TypeParam extends PrismaRef<Types, PrismaModelTypes>
372
381
  ? TypeParam[typeof prismaModelKey]
373
382
  : TypeParam extends keyof Types['PrismaTypes']
374
383
  ? Types['PrismaTypes'][TypeParam]
@@ -391,7 +400,7 @@ declare global {
391
400
  ? (Types & { WithInputArgRequired: boolean })['WithInputArgRequired']
392
401
  : ArgRequired
393
402
  >,
394
- ) => FieldRef<ShapeFromTypeParam<Types, Type, Nullable>>
403
+ ) => FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>>
395
404
  : '@pothos/plugin-prisma is required to use this method';
396
405
  }
397
406
 
@@ -442,15 +451,14 @@ declare global {
442
451
  export interface PrismaObjectFieldBuilder<
443
452
  Types extends SchemaTypes,
444
453
  Model extends PrismaModelTypes,
445
- NeedsResolve extends boolean,
446
454
  Shape extends object = Model['Shape'],
447
- > extends InternalPrismaObjectFieldBuilder<Types, Model, NeedsResolve, Shape>,
455
+ > extends InternalPrismaObjectFieldBuilder<Types, Model, Shape>,
448
456
  RootFieldBuilder<Types, Shape, 'PrismaObject'> {}
449
457
 
450
458
  export interface FieldWithInputBaseOptions<
451
459
  Types extends SchemaTypes,
452
- Args extends Record<string, InputFieldRef<unknown, 'Arg'>>,
453
- Fields extends Record<string, InputFieldRef<unknown, 'InputObject'>>,
460
+ Args extends Record<string, ArgumentRef<Types, unknown>>,
461
+ Fields extends Record<string, InputFieldRef<Types, unknown>>,
454
462
  InputName extends string,
455
463
  ArgRequired extends boolean,
456
464
  > {}
package/src/index.ts CHANGED
@@ -38,14 +38,13 @@ export type PrismaObjectFieldBuilder<
38
38
  export const ObjectFieldBuilder = InternalPrismaObjectFieldBuilder as new <
39
39
  Types extends SchemaTypes,
40
40
  Model extends PrismaModelTypes,
41
- NeedsResolve extends boolean,
42
41
  Shape extends object = Model['Shape'],
43
42
  >(
44
- name: string,
43
+ typename: string,
45
44
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
46
- ) => PothosSchemaTypes.PrismaObjectFieldBuilder<Types, Model, NeedsResolve, Shape>;
45
+ ) => PothosSchemaTypes.PrismaObjectFieldBuilder<Types, Model, Shape>;
47
46
 
48
- export class PrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
47
+ export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
49
48
  constructor(cache: BuildCache<Types>) {
50
49
  super(cache, pluginName);
51
50
  }
@@ -171,4 +170,11 @@ export class PrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
171
170
  }
172
171
  }
173
172
 
174
- SchemaBuilder.registerPlugin(pluginName, PrismaPlugin);
173
+ SchemaBuilder.registerPlugin(pluginName, PothosPrismaPlugin, {
174
+ v3: (options) => ({
175
+ prisma: {
176
+ ...options.prisma,
177
+ filterConnectionTotalCount: options.prisma?.filterConnectionTotalCount ?? false,
178
+ },
179
+ }),
180
+ });
@@ -1,12 +1,16 @@
1
- import { InterfaceRef } from '@pothos/core';
1
+ import { InterfaceRef, SchemaTypes } from '@pothos/core';
2
2
  import { prismaModelKey, PrismaObjectRef } from './object-ref';
3
3
  import type { PrismaModelTypes } from './types';
4
4
 
5
- export type PrismaRef<Model extends PrismaModelTypes, T = {}> =
6
- | PrismaInterfaceRef<Model, T>
7
- | PrismaObjectRef<Model, T>;
5
+ export type PrismaRef<Types extends SchemaTypes, Model extends PrismaModelTypes, T = {}> =
6
+ | PrismaInterfaceRef<Types, Model, T>
7
+ | PrismaObjectRef<Types, Model, T>;
8
8
 
9
- export class PrismaInterfaceRef<Model extends PrismaModelTypes, T = {}> extends InterfaceRef<T> {
9
+ export class PrismaInterfaceRef<
10
+ Types extends SchemaTypes,
11
+ Model extends PrismaModelTypes,
12
+ T = {},
13
+ > extends InterfaceRef<Types, T> {
10
14
  [prismaModelKey]!: Model;
11
15
 
12
16
  modelName: string;
@@ -60,7 +60,7 @@ export class ModelLoader {
60
60
  }
61
61
 
62
62
  static forRef<Types extends SchemaTypes>(
63
- ref: InterfaceRef<unknown> | ObjectRef<unknown>,
63
+ ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
64
64
  modelName: string,
65
65
  findUnique: ((model: Record<string, unknown>, ctx: {}) => unknown) | undefined,
66
66
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
@@ -106,7 +106,7 @@ export class ModelLoader {
106
106
  }
107
107
 
108
108
  static getDefaultFindBy<Types extends SchemaTypes>(
109
- ref: InterfaceRef<unknown> | ObjectRef<unknown>,
109
+ ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
110
110
  modelName: string,
111
111
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
112
112
  ) {
@@ -143,7 +143,7 @@ export class ModelLoader {
143
143
  }
144
144
 
145
145
  static getDefaultFindUnique<Types extends SchemaTypes>(
146
- ref: InterfaceRef<unknown> | ObjectRef<unknown>,
146
+ ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
147
147
  modelName: string,
148
148
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
149
149
  ): (model: Record<string, unknown>) => {} {
@@ -153,7 +153,7 @@ export class ModelLoader {
153
153
  }
154
154
 
155
155
  static getDefaultIDSelection<Types extends SchemaTypes>(
156
- ref: InterfaceRef<unknown> | ObjectRef<unknown>,
156
+ ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
157
157
  modelName: string,
158
158
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
159
159
  ): Record<string, boolean> {
@@ -173,7 +173,7 @@ export class ModelLoader {
173
173
  }
174
174
 
175
175
  static getCursorSelection<Types extends SchemaTypes>(
176
- ref: InterfaceRef<unknown> | ObjectRef<unknown>,
176
+ ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
177
177
  modelName: string,
178
178
  cursor: string,
179
179
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
@@ -202,7 +202,7 @@ export class ModelLoader {
202
202
  }
203
203
 
204
204
  static getFindUniqueForField<Types extends SchemaTypes>(
205
- ref: InterfaceRef<unknown> | ObjectRef<unknown>,
205
+ ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
206
206
  modelName: string,
207
207
  fieldName: string,
208
208
  builder: PothosSchemaTypes.SchemaBuilder<Types>,
package/src/node-ref.ts CHANGED
@@ -1,4 +1,9 @@
1
+ import { SchemaTypes } from '@pothos/core';
1
2
  import { PrismaObjectRef } from './object-ref';
2
3
  import type { PrismaModelTypes } from './types';
3
4
 
4
- export class PrismaNodeRef<Model extends PrismaModelTypes, T> extends PrismaObjectRef<Model, T> {}
5
+ export class PrismaNodeRef<
6
+ Types extends SchemaTypes,
7
+ Model extends PrismaModelTypes,
8
+ T,
9
+ > extends PrismaObjectRef<Types, Model, T> {}
package/src/object-ref.ts CHANGED
@@ -1,9 +1,19 @@
1
- import { abstractReturnShapeKey, brandWithType, ObjectRef, typeBrandKey } from '@pothos/core';
1
+ import {
2
+ abstractReturnShapeKey,
3
+ brandWithType,
4
+ ObjectRef,
5
+ SchemaTypes,
6
+ typeBrandKey,
7
+ } from '@pothos/core';
2
8
  import type { PrismaModelTypes, WithBrand } from './types';
3
9
 
4
10
  export const prismaModelKey = Symbol.for('Pothos.prismaModelKey');
5
11
 
6
- export class PrismaObjectRef<Model extends PrismaModelTypes, T = {}> extends ObjectRef<T> {
12
+ export class PrismaObjectRef<
13
+ Types extends SchemaTypes,
14
+ Model extends PrismaModelTypes,
15
+ T = {},
16
+ > extends ObjectRef<Types, T> {
7
17
  [prismaModelKey]!: Model;
8
18
 
9
19
  [abstractReturnShapeKey]!: WithBrand<T>;