@pothos/plugin-prisma 0.0.0-preview-20220211212258
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.
- package/.turbo/turbo-build.log +17 -0
- package/.turbo/turbo-test.log +18 -0
- package/.turbo/turbo-type.log +5 -0
- package/CHANGELOG.md +355 -0
- package/LICENSE +6 -0
- package/README.md +808 -0
- package/babel.config.js +3 -0
- package/bin/generator.js +2 -0
- package/esm/cursors.d.ts +55 -0
- package/esm/cursors.d.ts.map +1 -0
- package/esm/cursors.js +106 -0
- package/esm/cursors.js.map +1 -0
- package/esm/field-builder.d.ts +2 -0
- package/esm/field-builder.d.ts.map +1 -0
- package/esm/field-builder.js +53 -0
- package/esm/field-builder.js.map +1 -0
- package/esm/generator.d.ts +2 -0
- package/esm/generator.d.ts.map +1 -0
- package/esm/generator.js +83 -0
- package/esm/generator.js.map +1 -0
- package/esm/global-types.d.ts +52 -0
- package/esm/global-types.d.ts.map +1 -0
- package/esm/global-types.js +2 -0
- package/esm/global-types.js.map +1 -0
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +14 -0
- package/esm/index.js.map +1 -0
- package/esm/loader-map.d.ts +6 -0
- package/esm/loader-map.d.ts.map +1 -0
- package/esm/loader-map.js +35 -0
- package/esm/loader-map.js.map +1 -0
- package/esm/model-loader.d.ts +18 -0
- package/esm/model-loader.d.ts.map +1 -0
- package/esm/model-loader.js +101 -0
- package/esm/model-loader.js.map +1 -0
- package/esm/node-ref.d.ts +12 -0
- package/esm/node-ref.d.ts.map +1 -0
- package/esm/node-ref.js +19 -0
- package/esm/node-ref.js.map +1 -0
- package/esm/object-ref.d.ts +7 -0
- package/esm/object-ref.d.ts.map +1 -0
- package/esm/object-ref.js +5 -0
- package/esm/object-ref.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/prisma-field-builder.d.ts +28 -0
- package/esm/prisma-field-builder.d.ts.map +1 -0
- package/esm/prisma-field-builder.js +204 -0
- package/esm/prisma-field-builder.js.map +1 -0
- package/esm/refs.d.ts +15 -0
- package/esm/refs.d.ts.map +1 -0
- package/esm/refs.js +64 -0
- package/esm/refs.js.map +1 -0
- package/esm/schema-builder.d.ts +2 -0
- package/esm/schema-builder.d.ts.map +1 -0
- package/esm/schema-builder.js +65 -0
- package/esm/schema-builder.js.map +1 -0
- package/esm/types.d.ts +177 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/esm/util/index.d.ts +5 -0
- package/esm/util/index.d.ts.map +1 -0
- package/esm/util/index.js +16 -0
- package/esm/util/index.js.map +1 -0
- package/esm/util/map-includes.d.ts +6 -0
- package/esm/util/map-includes.d.ts.map +1 -0
- package/esm/util/map-includes.js +184 -0
- package/esm/util/map-includes.js.map +1 -0
- package/esm/util/merge-includes.d.ts +3 -0
- package/esm/util/merge-includes.d.ts.map +1 -0
- package/esm/util/merge-includes.js +91 -0
- package/esm/util/merge-includes.js.map +1 -0
- package/lib/cursors.d.ts +55 -0
- package/lib/cursors.d.ts.map +1 -0
- package/lib/cursors.js +112 -0
- package/lib/cursors.js.map +1 -0
- package/lib/field-builder.d.ts +2 -0
- package/lib/field-builder.d.ts.map +1 -0
- package/lib/field-builder.js +65 -0
- package/lib/field-builder.js.map +1 -0
- package/lib/generator.d.ts +2 -0
- package/lib/generator.d.ts.map +1 -0
- package/lib/generator.js +104 -0
- package/lib/generator.js.map +1 -0
- package/lib/global-types.d.ts +52 -0
- package/lib/global-types.d.ts.map +1 -0
- package/lib/global-types.js +3 -0
- package/lib/global-types.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +40 -0
- package/lib/index.js.map +1 -0
- package/lib/loader-map.d.ts +6 -0
- package/lib/loader-map.d.ts.map +1 -0
- package/lib/loader-map.js +41 -0
- package/lib/loader-map.js.map +1 -0
- package/lib/model-loader.d.ts +18 -0
- package/lib/model-loader.d.ts.map +1 -0
- package/lib/model-loader.js +105 -0
- package/lib/model-loader.js.map +1 -0
- package/lib/node-ref.d.ts +12 -0
- package/lib/node-ref.d.ts.map +1 -0
- package/lib/node-ref.js +22 -0
- package/lib/node-ref.js.map +1 -0
- package/lib/object-ref.d.ts +7 -0
- package/lib/object-ref.d.ts.map +1 -0
- package/lib/object-ref.js +9 -0
- package/lib/object-ref.js.map +1 -0
- package/lib/prisma-field-builder.d.ts +28 -0
- package/lib/prisma-field-builder.d.ts.map +1 -0
- package/lib/prisma-field-builder.js +208 -0
- package/lib/prisma-field-builder.js.map +1 -0
- package/lib/refs.d.ts +15 -0
- package/lib/refs.d.ts.map +1 -0
- package/lib/refs.js +73 -0
- package/lib/refs.js.map +1 -0
- package/lib/schema-builder.d.ts +2 -0
- package/lib/schema-builder.d.ts.map +1 -0
- package/lib/schema-builder.js +89 -0
- package/lib/schema-builder.js.map +1 -0
- package/lib/types.d.ts +177 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +4 -0
- package/lib/types.js.map +1 -0
- package/lib/util/index.d.ts +5 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/index.js +30 -0
- package/lib/util/index.js.map +1 -0
- package/lib/util/map-includes.d.ts +6 -0
- package/lib/util/map-includes.d.ts.map +1 -0
- package/lib/util/map-includes.js +189 -0
- package/lib/util/map-includes.js.map +1 -0
- package/lib/util/merge-includes.d.ts +3 -0
- package/lib/util/merge-includes.d.ts.map +1 -0
- package/lib/util/merge-includes.js +96 -0
- package/lib/util/merge-includes.js.map +1 -0
- package/package.json +71 -0
- package/src/cursors.ts +159 -0
- package/src/field-builder.ts +117 -0
- package/src/generator.ts +191 -0
- package/src/global-types.ts +196 -0
- package/src/index.ts +18 -0
- package/src/loader-map.ts +48 -0
- package/src/model-loader.ts +152 -0
- package/src/node-ref.ts +34 -0
- package/src/object-ref.ts +8 -0
- package/src/prisma-field-builder.ts +375 -0
- package/src/refs.ts +112 -0
- package/src/schema-builder.ts +121 -0
- package/src/types.ts +502 -0
- package/src/util/index.ts +26 -0
- package/src/util/map-includes.ts +329 -0
- package/src/util/merge-includes.ts +121 -0
- package/tsconfig.json +21 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { GraphQLResolveInfo } from 'graphql';
|
|
2
|
+
import {
|
|
3
|
+
FieldKind,
|
|
4
|
+
FieldMap,
|
|
5
|
+
FieldNullability,
|
|
6
|
+
FieldOptionsFromKind,
|
|
7
|
+
InputFieldMap,
|
|
8
|
+
InputFieldsFromShape,
|
|
9
|
+
InputShapeFromFields,
|
|
10
|
+
InterfaceParam,
|
|
11
|
+
ListResolveValue,
|
|
12
|
+
MaybePromise,
|
|
13
|
+
ObjectRef,
|
|
14
|
+
OutputShape,
|
|
15
|
+
OutputType,
|
|
16
|
+
SchemaTypes,
|
|
17
|
+
ShapeFromTypeParam,
|
|
18
|
+
ShapeWithNullability,
|
|
19
|
+
typeBrandKey,
|
|
20
|
+
TypeParam,
|
|
21
|
+
} from '@pothos/core';
|
|
22
|
+
import { PrismaObjectFieldBuilder } from './field-builder';
|
|
23
|
+
import { PrismaObjectRef } from './object-ref';
|
|
24
|
+
|
|
25
|
+
export interface PrismaDelegate {
|
|
26
|
+
findUnique: (...args: any[]) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type RelationKeys<T> = {
|
|
30
|
+
[K in keyof T]: T[K] extends (args: {}) => {
|
|
31
|
+
then: (cb: (result: unknown) => unknown) => unknown;
|
|
32
|
+
}
|
|
33
|
+
? K
|
|
34
|
+
: never;
|
|
35
|
+
}[keyof T];
|
|
36
|
+
|
|
37
|
+
export type ModelTypes<Model extends {}> = Model extends {
|
|
38
|
+
findUnique: (
|
|
39
|
+
options: infer UniqueOptions & {
|
|
40
|
+
where?: infer Where | null | undefined;
|
|
41
|
+
select?: infer Select | null | undefined;
|
|
42
|
+
} & (
|
|
43
|
+
| {
|
|
44
|
+
include?: infer Include | null | undefined;
|
|
45
|
+
}
|
|
46
|
+
| {}
|
|
47
|
+
),
|
|
48
|
+
) => infer Chain & {
|
|
49
|
+
then: (cb: (result: infer Shape | null) => unknown) => unknown;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
? PrismaModelTypes & {
|
|
53
|
+
Shape: Shape;
|
|
54
|
+
Include: unknown extends Include ? never : Include;
|
|
55
|
+
Where: Where;
|
|
56
|
+
Fields: keyof Select;
|
|
57
|
+
ListRelation: ListRelationFields<Include> & string;
|
|
58
|
+
Relations: {
|
|
59
|
+
[RelationName in RelationKeys<Chain>]: Chain[RelationName] extends (args: {}) => {
|
|
60
|
+
then: (cb: (result: infer Relation) => unknown) => unknown;
|
|
61
|
+
}
|
|
62
|
+
? { Shape: Relation; Types: PrismaModelTypes }
|
|
63
|
+
: never;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
: never;
|
|
67
|
+
|
|
68
|
+
export interface PrismaModelTypes {
|
|
69
|
+
Name: string;
|
|
70
|
+
Shape: {};
|
|
71
|
+
Include: unknown;
|
|
72
|
+
Where: {};
|
|
73
|
+
Fields: string;
|
|
74
|
+
ListRelations: string;
|
|
75
|
+
Relations: Record<
|
|
76
|
+
string,
|
|
77
|
+
{
|
|
78
|
+
Shape: unknown;
|
|
79
|
+
Types: PrismaModelTypes;
|
|
80
|
+
}
|
|
81
|
+
>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type ListRelationFields<T> = {
|
|
85
|
+
[K in keyof T]: T[K] extends infer Option
|
|
86
|
+
? Option extends { orderBy?: unknown }
|
|
87
|
+
? K
|
|
88
|
+
: never
|
|
89
|
+
: never;
|
|
90
|
+
}[keyof T];
|
|
91
|
+
|
|
92
|
+
export type PrismaObjectFieldsShape<
|
|
93
|
+
Types extends SchemaTypes,
|
|
94
|
+
Model extends PrismaModelTypes,
|
|
95
|
+
NeedsResolve extends boolean,
|
|
96
|
+
Shape extends object,
|
|
97
|
+
> = (t: PrismaObjectFieldBuilder<Types, Model, NeedsResolve, Shape>) => FieldMap;
|
|
98
|
+
|
|
99
|
+
export type ShapeFromInclude<Model extends PrismaModelTypes, Include> = {} extends Include
|
|
100
|
+
? Model['Shape']
|
|
101
|
+
: {
|
|
102
|
+
[K in keyof Include &
|
|
103
|
+
keyof Model['Relations']]: Model['Relations'][K]['Shape'] extends infer RelationShape
|
|
104
|
+
? RelationShape extends (infer ItemShape)[]
|
|
105
|
+
? (ItemShape &
|
|
106
|
+
(Include[K] extends { include?: infer NestedInclude & object }
|
|
107
|
+
? ShapeFromInclude<Model['Relations'][K]['Types'], NestedInclude>
|
|
108
|
+
: {}))[]
|
|
109
|
+
: RelationShape &
|
|
110
|
+
(
|
|
111
|
+
| (Include[K] extends { include?: infer NestedInclude & object }
|
|
112
|
+
? ShapeFromInclude<Model['Relations'][K]['Types'], NestedInclude>
|
|
113
|
+
: {})
|
|
114
|
+
| null
|
|
115
|
+
)
|
|
116
|
+
: never;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type ShapeWithInclude<
|
|
120
|
+
Model extends PrismaModelTypes,
|
|
121
|
+
Include extends Model['Include'],
|
|
122
|
+
> = Model['Shape'] & ([Include] extends [never] ? {} : ShapeFromInclude<Model, Include>);
|
|
123
|
+
|
|
124
|
+
export type PrismaObjectTypeOptions<
|
|
125
|
+
Types extends SchemaTypes,
|
|
126
|
+
Model extends PrismaModelTypes,
|
|
127
|
+
Interfaces extends InterfaceParam<Types>[],
|
|
128
|
+
FindUnique,
|
|
129
|
+
Include extends Model['Include'],
|
|
130
|
+
Shape extends object,
|
|
131
|
+
> = NameOrVariant &
|
|
132
|
+
Omit<
|
|
133
|
+
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
134
|
+
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
135
|
+
'fields'
|
|
136
|
+
> & {
|
|
137
|
+
include?: Include;
|
|
138
|
+
fields?: PrismaObjectFieldsShape<Types, Model, FindUnique extends null ? true : false, Shape>;
|
|
139
|
+
findUnique: FindUnique &
|
|
140
|
+
(((parent: Shape, context: Types['Context']) => Model['Where']) | null);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type NameOrVariant =
|
|
144
|
+
| {
|
|
145
|
+
name?: never;
|
|
146
|
+
variant?: string;
|
|
147
|
+
}
|
|
148
|
+
| {
|
|
149
|
+
name?: string;
|
|
150
|
+
variant?: never;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export type PrismaNodeOptions<
|
|
154
|
+
Types extends SchemaTypes,
|
|
155
|
+
Model extends PrismaModelTypes,
|
|
156
|
+
Interfaces extends InterfaceParam<Types>[],
|
|
157
|
+
Include extends Model['Include'],
|
|
158
|
+
Shape extends object,
|
|
159
|
+
> = NameOrVariant &
|
|
160
|
+
Omit<
|
|
161
|
+
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
162
|
+
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
163
|
+
'fields' | 'isTypeOf'
|
|
164
|
+
> & {
|
|
165
|
+
include?: Include;
|
|
166
|
+
id: Omit<
|
|
167
|
+
FieldOptionsFromKind<
|
|
168
|
+
Types,
|
|
169
|
+
Shape,
|
|
170
|
+
'ID',
|
|
171
|
+
false,
|
|
172
|
+
{},
|
|
173
|
+
'Object',
|
|
174
|
+
OutputShape<Types, 'ID'>,
|
|
175
|
+
MaybePromise<OutputShape<Types, 'ID'>>
|
|
176
|
+
>,
|
|
177
|
+
'args' | 'nullable' | 'resolve' | 'type'
|
|
178
|
+
> & {
|
|
179
|
+
resolve: (parent: Shape, context: Types['Context']) => MaybePromise<OutputShape<Types, 'ID'>>;
|
|
180
|
+
};
|
|
181
|
+
fields?: PrismaObjectFieldsShape<Types, Model, false, Shape>;
|
|
182
|
+
findUnique: (id: string, context: Types['Context']) => Model['Where'];
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export type QueryForField<
|
|
186
|
+
Types extends SchemaTypes,
|
|
187
|
+
Args extends InputFieldMap,
|
|
188
|
+
Include,
|
|
189
|
+
> = Include extends { where?: unknown }
|
|
190
|
+
?
|
|
191
|
+
| Omit<Include, 'include' | 'select'>
|
|
192
|
+
| ((
|
|
193
|
+
args: InputShapeFromFields<Args>,
|
|
194
|
+
ctx: Types['Context'],
|
|
195
|
+
) => Omit<Include, 'include' | 'select'>)
|
|
196
|
+
: never;
|
|
197
|
+
|
|
198
|
+
export type IncludeFromRelation<
|
|
199
|
+
Model extends PrismaModelTypes,
|
|
200
|
+
Field extends keyof Model['Include'],
|
|
201
|
+
> = Model['Include'][Field] extends infer Include
|
|
202
|
+
? Include extends {
|
|
203
|
+
include?: infer T;
|
|
204
|
+
}
|
|
205
|
+
? NonNullable<T>
|
|
206
|
+
: never
|
|
207
|
+
: never;
|
|
208
|
+
|
|
209
|
+
export type CursorFromRelation<
|
|
210
|
+
Model extends PrismaModelTypes,
|
|
211
|
+
Field extends Model['ListRelations'],
|
|
212
|
+
> = Field extends keyof Model['Include']
|
|
213
|
+
? Model['Include'][Field] extends infer Include
|
|
214
|
+
? Include extends { cursor?: infer T }
|
|
215
|
+
? keyof T
|
|
216
|
+
: never
|
|
217
|
+
: never
|
|
218
|
+
: never;
|
|
219
|
+
|
|
220
|
+
export type RefForRelation<
|
|
221
|
+
Model extends PrismaModelTypes,
|
|
222
|
+
Field extends keyof Model['Relations'],
|
|
223
|
+
> = Model['Relations'][Field] extends unknown[]
|
|
224
|
+
? [ObjectRef<Model['Relations'][Field]>]
|
|
225
|
+
: ObjectRef<Model['Relations'][Field]>;
|
|
226
|
+
|
|
227
|
+
export type RelatedFieldOptions<
|
|
228
|
+
Types extends SchemaTypes,
|
|
229
|
+
Model extends PrismaModelTypes,
|
|
230
|
+
Field extends keyof Model['Relations'],
|
|
231
|
+
Nullable extends boolean,
|
|
232
|
+
Args extends InputFieldMap,
|
|
233
|
+
ResolveReturnShape,
|
|
234
|
+
NeedsResolve extends boolean,
|
|
235
|
+
Shape,
|
|
236
|
+
> = Omit<
|
|
237
|
+
PothosSchemaTypes.ObjectFieldOptions<
|
|
238
|
+
Types,
|
|
239
|
+
Shape,
|
|
240
|
+
RefForRelation<Model, Field>,
|
|
241
|
+
Nullable,
|
|
242
|
+
Args,
|
|
243
|
+
ResolveReturnShape
|
|
244
|
+
>,
|
|
245
|
+
'resolve' | 'type'
|
|
246
|
+
> &
|
|
247
|
+
(NeedsResolve extends false
|
|
248
|
+
? {
|
|
249
|
+
resolve?: (
|
|
250
|
+
query: { include?: IncludeFromRelation<Model, Field & keyof Model['Include']> },
|
|
251
|
+
parent: Shape,
|
|
252
|
+
args: InputShapeFromFields<Args>,
|
|
253
|
+
context: Types['Context'],
|
|
254
|
+
info: GraphQLResolveInfo,
|
|
255
|
+
) => MaybePromise<
|
|
256
|
+
ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>
|
|
257
|
+
>;
|
|
258
|
+
}
|
|
259
|
+
: {
|
|
260
|
+
resolve: (
|
|
261
|
+
query: { include?: IncludeFromRelation<Model, Field & keyof Model['Include']> },
|
|
262
|
+
parent: Shape,
|
|
263
|
+
args: InputShapeFromFields<Args>,
|
|
264
|
+
context: Types['Context'],
|
|
265
|
+
info: GraphQLResolveInfo,
|
|
266
|
+
) => MaybePromise<
|
|
267
|
+
ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>
|
|
268
|
+
>;
|
|
269
|
+
}) & {
|
|
270
|
+
type?: PrismaObjectRef<Model['Relations'][Field]['Types']>;
|
|
271
|
+
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export type VariantFieldOptions<
|
|
275
|
+
Types extends SchemaTypes,
|
|
276
|
+
Model extends PrismaModelTypes,
|
|
277
|
+
Variant extends PrismaObjectRef<Model>,
|
|
278
|
+
> = Omit<
|
|
279
|
+
PothosSchemaTypes.ObjectFieldOptions<Types, Model['Shape'], Variant, false, {}, Model['Shape']>,
|
|
280
|
+
'resolve' | 'type'
|
|
281
|
+
>;
|
|
282
|
+
|
|
283
|
+
export type RelationCountOptions<
|
|
284
|
+
Types extends SchemaTypes,
|
|
285
|
+
Shape,
|
|
286
|
+
NeedsResolve extends boolean,
|
|
287
|
+
> = Omit<
|
|
288
|
+
PothosSchemaTypes.ObjectFieldOptions<Types, Shape, 'Int', false, {}, number>,
|
|
289
|
+
'resolve' | 'type'
|
|
290
|
+
> &
|
|
291
|
+
(NeedsResolve extends false
|
|
292
|
+
? {
|
|
293
|
+
resolve?: (
|
|
294
|
+
parent: Shape,
|
|
295
|
+
args: {},
|
|
296
|
+
context: Types['Context'],
|
|
297
|
+
info: GraphQLResolveInfo,
|
|
298
|
+
) => MaybePromise<number>;
|
|
299
|
+
}
|
|
300
|
+
: {
|
|
301
|
+
resolve: (
|
|
302
|
+
parent: Shape,
|
|
303
|
+
args: {},
|
|
304
|
+
context: Types['Context'],
|
|
305
|
+
info: GraphQLResolveInfo,
|
|
306
|
+
) => MaybePromise<number>;
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
export type PrismaFieldOptions<
|
|
310
|
+
Types extends SchemaTypes,
|
|
311
|
+
ParentShape,
|
|
312
|
+
Type extends
|
|
313
|
+
| PrismaObjectRef<PrismaModelTypes>
|
|
314
|
+
| keyof Types['PrismaTypes']
|
|
315
|
+
| [keyof Types['PrismaTypes']]
|
|
316
|
+
| [PrismaObjectRef<PrismaModelTypes>],
|
|
317
|
+
Model extends PrismaModelTypes,
|
|
318
|
+
Param extends TypeParam<Types>,
|
|
319
|
+
Args extends InputFieldMap,
|
|
320
|
+
Nullable extends FieldNullability<Param>,
|
|
321
|
+
ResolveReturnShape,
|
|
322
|
+
Kind extends FieldKind = FieldKind,
|
|
323
|
+
> = Omit<
|
|
324
|
+
FieldOptionsFromKind<
|
|
325
|
+
Types,
|
|
326
|
+
ParentShape,
|
|
327
|
+
Param,
|
|
328
|
+
Nullable,
|
|
329
|
+
Args,
|
|
330
|
+
Kind,
|
|
331
|
+
ParentShape,
|
|
332
|
+
ResolveReturnShape
|
|
333
|
+
>,
|
|
334
|
+
'resolve' | 'type'
|
|
335
|
+
> & {
|
|
336
|
+
type: Type;
|
|
337
|
+
resolve: (
|
|
338
|
+
query: {
|
|
339
|
+
include?: Model['Include'];
|
|
340
|
+
},
|
|
341
|
+
parent: ParentShape,
|
|
342
|
+
args: InputShapeFromFields<Args>,
|
|
343
|
+
context: Types['Context'],
|
|
344
|
+
info: GraphQLResolveInfo,
|
|
345
|
+
) => ShapeFromTypeParam<Types, Param, Nullable> extends infer Shape
|
|
346
|
+
? [Shape] extends [[readonly (infer Item)[] | null | undefined]]
|
|
347
|
+
? ListResolveValue<Shape, Item, ResolveReturnShape>
|
|
348
|
+
: MaybePromise<Shape>
|
|
349
|
+
: never;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
export type PrismaConnectionFieldOptions<
|
|
353
|
+
Types extends SchemaTypes,
|
|
354
|
+
ParentShape,
|
|
355
|
+
Type extends PrismaObjectRef<PrismaModelTypes> | keyof Types['PrismaTypes'],
|
|
356
|
+
Model extends PrismaModelTypes,
|
|
357
|
+
Param extends OutputType<Types>,
|
|
358
|
+
Nullable extends boolean,
|
|
359
|
+
Args extends InputFieldMap,
|
|
360
|
+
ResolveReturnShape,
|
|
361
|
+
Kind extends FieldKind,
|
|
362
|
+
> = Omit<
|
|
363
|
+
PothosSchemaTypes.ConnectionFieldOptions<
|
|
364
|
+
Types,
|
|
365
|
+
ParentShape,
|
|
366
|
+
Param,
|
|
367
|
+
Nullable,
|
|
368
|
+
false,
|
|
369
|
+
false,
|
|
370
|
+
Args,
|
|
371
|
+
ResolveReturnShape
|
|
372
|
+
>,
|
|
373
|
+
'resolve' | 'type'
|
|
374
|
+
> &
|
|
375
|
+
Omit<
|
|
376
|
+
FieldOptionsFromKind<
|
|
377
|
+
Types,
|
|
378
|
+
ParentShape,
|
|
379
|
+
Param,
|
|
380
|
+
Nullable,
|
|
381
|
+
Args & InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments>,
|
|
382
|
+
Kind,
|
|
383
|
+
ParentShape,
|
|
384
|
+
ResolveReturnShape
|
|
385
|
+
>,
|
|
386
|
+
'args' | 'resolve' | 'type'
|
|
387
|
+
> & {
|
|
388
|
+
type: Type;
|
|
389
|
+
cursor: string & keyof Model['Where'];
|
|
390
|
+
defaultSize?: number;
|
|
391
|
+
maxSize?: number;
|
|
392
|
+
resolve: (
|
|
393
|
+
query: {
|
|
394
|
+
include?: Model['Include'];
|
|
395
|
+
cursor?: {};
|
|
396
|
+
take: number;
|
|
397
|
+
skip: number;
|
|
398
|
+
},
|
|
399
|
+
parent: ParentShape,
|
|
400
|
+
args: InputShapeFromFields<Args> & PothosSchemaTypes.DefaultConnectionArguments,
|
|
401
|
+
context: Types['Context'],
|
|
402
|
+
info: GraphQLResolveInfo,
|
|
403
|
+
) => MaybePromise<Model['Shape'][]>;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
export type RelatedConnectionOptions<
|
|
407
|
+
Types extends SchemaTypes,
|
|
408
|
+
Model extends PrismaModelTypes,
|
|
409
|
+
Field extends Model['ListRelations'],
|
|
410
|
+
Nullable extends boolean,
|
|
411
|
+
Args extends InputFieldMap,
|
|
412
|
+
NeedsResolve extends boolean,
|
|
413
|
+
> = Omit<
|
|
414
|
+
PothosSchemaTypes.ObjectFieldOptions<
|
|
415
|
+
Types,
|
|
416
|
+
Model['Shape'],
|
|
417
|
+
ObjectRef<unknown>,
|
|
418
|
+
Nullable,
|
|
419
|
+
Args,
|
|
420
|
+
unknown
|
|
421
|
+
>,
|
|
422
|
+
'resolve' | 'type'
|
|
423
|
+
> &
|
|
424
|
+
Omit<
|
|
425
|
+
PothosSchemaTypes.ConnectionFieldOptions<
|
|
426
|
+
Types,
|
|
427
|
+
Model['Shape'],
|
|
428
|
+
ObjectRef<unknown>,
|
|
429
|
+
false,
|
|
430
|
+
false,
|
|
431
|
+
Nullable,
|
|
432
|
+
Args,
|
|
433
|
+
unknown
|
|
434
|
+
>,
|
|
435
|
+
'resolve' | 'type'
|
|
436
|
+
> & {
|
|
437
|
+
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
438
|
+
type?: PrismaObjectRef<Model['Relations'][Field]['Types']>;
|
|
439
|
+
cursor: CursorFromRelation<Model, Field>;
|
|
440
|
+
defaultSize?: number;
|
|
441
|
+
maxSize?: number;
|
|
442
|
+
totalCount?: NeedsResolve extends false ? boolean : false;
|
|
443
|
+
} & (NeedsResolve extends false
|
|
444
|
+
? {
|
|
445
|
+
resolve?: (
|
|
446
|
+
query: {
|
|
447
|
+
include?: Model['Include'];
|
|
448
|
+
cursor?: {};
|
|
449
|
+
take: number;
|
|
450
|
+
skip: number;
|
|
451
|
+
},
|
|
452
|
+
parent: Model['Shape'],
|
|
453
|
+
args: InputShapeFromFields<Args>,
|
|
454
|
+
context: Types['Context'],
|
|
455
|
+
info: GraphQLResolveInfo,
|
|
456
|
+
) => MaybePromise<Model['Relations'][Field & keyof Model['Relations']]>;
|
|
457
|
+
}
|
|
458
|
+
: {
|
|
459
|
+
resolve: (
|
|
460
|
+
query: {
|
|
461
|
+
include?: Model['Include'];
|
|
462
|
+
cursor?: {};
|
|
463
|
+
take: number;
|
|
464
|
+
skip: number;
|
|
465
|
+
},
|
|
466
|
+
parent: Model['Shape'],
|
|
467
|
+
args: InputShapeFromFields<Args>,
|
|
468
|
+
context: Types['Context'],
|
|
469
|
+
info: GraphQLResolveInfo,
|
|
470
|
+
) => MaybePromise<Model['Relations'][Field & keyof Model['Relations']]>;
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
export type WithBrand<T> = T & { [typeBrandKey]: string };
|
|
474
|
+
|
|
475
|
+
export type IncludeMap = Record<string, Record<string, unknown> | boolean>;
|
|
476
|
+
|
|
477
|
+
export interface IncludeCounts {
|
|
478
|
+
current: Record<string, boolean>;
|
|
479
|
+
parent: Record<string, boolean>;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export type LoaderMappings = Record<
|
|
483
|
+
string,
|
|
484
|
+
{
|
|
485
|
+
field: string;
|
|
486
|
+
alias?: string;
|
|
487
|
+
mappings: LoaderMappings;
|
|
488
|
+
indirectPath: string[];
|
|
489
|
+
}[]
|
|
490
|
+
>;
|
|
491
|
+
|
|
492
|
+
export interface SubFieldInclude {
|
|
493
|
+
type?: string;
|
|
494
|
+
name: string;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export interface IndirectLoadMap {
|
|
498
|
+
subFields: SubFieldInclude[];
|
|
499
|
+
path: string[];
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GraphQLNamedType, GraphQLResolveInfo } from 'graphql';
|
|
2
|
+
|
|
3
|
+
export * from './map-includes';
|
|
4
|
+
export * from './merge-includes';
|
|
5
|
+
|
|
6
|
+
export function resolveIndirectType(
|
|
7
|
+
type: GraphQLNamedType,
|
|
8
|
+
info: GraphQLResolveInfo,
|
|
9
|
+
): GraphQLNamedType {
|
|
10
|
+
const indirectInclude = type.extensions?.pothosPrismaIndirectInclude as
|
|
11
|
+
| { getType: () => string }
|
|
12
|
+
| undefined;
|
|
13
|
+
|
|
14
|
+
if (indirectInclude) {
|
|
15
|
+
const includeTypeName = indirectInclude.getType();
|
|
16
|
+
const resolvedType = info.schema.getType(includeTypeName);
|
|
17
|
+
|
|
18
|
+
if (!resolvedType) {
|
|
19
|
+
throw new Error(`Could not find type ${includeTypeName}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return resolveIndirectType(resolvedType, info);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return type;
|
|
26
|
+
}
|