@pothos/plugin-prisma 0.18.0 → 0.19.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.
- package/CHANGELOG.md +6 -0
- package/README.md +403 -308
- package/esm/field-builder.js +3 -3
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +4 -0
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts +23 -5
- package/esm/global-types.d.ts.map +1 -1
- package/esm/index.d.ts +4 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +46 -1
- package/esm/index.js.map +1 -1
- package/esm/model-loader.d.ts +5 -6
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +12 -69
- package/esm/model-loader.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +25 -6
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +83 -116
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/schema-builder.js +14 -4
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +73 -77
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +1 -0
- package/esm/types.js.map +1 -1
- package/esm/{cursors.d.ts → util/cursors.d.ts} +1 -1
- package/esm/util/cursors.d.ts.map +1 -0
- package/esm/{cursors.js → util/cursors.js} +0 -0
- package/esm/util/cursors.js.map +1 -0
- package/{lib/refs.d.ts → esm/util/datamodel.d.ts} +4 -8
- package/esm/util/datamodel.d.ts.map +1 -0
- package/esm/{refs.js → util/datamodel.js} +2 -25
- package/esm/util/datamodel.js.map +1 -0
- package/esm/util/deep-equal.d.ts +2 -0
- package/esm/util/deep-equal.d.ts.map +1 -0
- package/esm/util/deep-equal.js +39 -0
- package/esm/util/deep-equal.js.map +1 -0
- package/esm/util/loader-map.d.ts +6 -0
- package/esm/util/loader-map.d.ts.map +1 -0
- package/esm/{loader-map.js → util/loader-map.js} +10 -12
- package/esm/util/loader-map.js.map +1 -0
- package/esm/util/map-query.d.ts +6 -0
- package/esm/util/map-query.d.ts.map +1 -0
- package/esm/util/map-query.js +169 -0
- package/esm/util/map-query.js.map +1 -0
- package/esm/util/relation-map.d.ts +9 -0
- package/esm/util/relation-map.d.ts.map +1 -0
- package/esm/util/relation-map.js +20 -0
- package/esm/util/relation-map.js.map +1 -0
- package/esm/util/selections.d.ts +20 -0
- package/esm/util/selections.d.ts.map +1 -0
- package/esm/util/selections.js +139 -0
- package/esm/util/selections.js.map +1 -0
- package/lib/field-builder.js +9 -9
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +4 -0
- package/lib/generator.js.map +1 -1
- package/lib/global-types.d.ts +23 -5
- package/lib/global-types.d.ts.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +45 -0
- package/lib/index.js.map +1 -1
- package/lib/model-loader.d.ts +5 -6
- package/lib/model-loader.d.ts.map +1 -1
- package/lib/model-loader.js +13 -70
- package/lib/model-loader.js.map +1 -1
- package/lib/prisma-field-builder.d.ts +25 -6
- package/lib/prisma-field-builder.d.ts.map +1 -1
- package/lib/prisma-field-builder.js +89 -122
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +17 -7
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.d.ts +73 -77
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -1
- package/lib/{cursors.d.ts → util/cursors.d.ts} +1 -1
- package/lib/util/cursors.d.ts.map +1 -0
- package/lib/{cursors.js → util/cursors.js} +0 -0
- package/lib/util/cursors.js.map +1 -0
- package/{esm/refs.d.ts → lib/util/datamodel.d.ts} +4 -8
- package/lib/util/datamodel.d.ts.map +1 -0
- package/lib/{refs.js → util/datamodel.js} +3 -29
- package/lib/util/datamodel.js.map +1 -0
- package/lib/util/deep-equal.d.ts +2 -0
- package/lib/util/deep-equal.d.ts.map +1 -0
- package/lib/util/deep-equal.js +43 -0
- package/lib/util/deep-equal.js.map +1 -0
- package/lib/util/loader-map.d.ts +6 -0
- package/lib/util/loader-map.d.ts.map +1 -0
- package/lib/{loader-map.js → util/loader-map.js} +10 -12
- package/lib/util/loader-map.js.map +1 -0
- package/lib/util/map-query.d.ts +6 -0
- package/lib/util/map-query.d.ts.map +1 -0
- package/lib/util/map-query.js +175 -0
- package/lib/util/map-query.js.map +1 -0
- package/lib/util/relation-map.d.ts +9 -0
- package/lib/util/relation-map.d.ts.map +1 -0
- package/lib/util/relation-map.js +24 -0
- package/lib/util/relation-map.js.map +1 -0
- package/lib/util/selections.d.ts +20 -0
- package/lib/util/selections.d.ts.map +1 -0
- package/lib/util/selections.js +148 -0
- package/lib/util/selections.js.map +1 -0
- package/package.json +5 -5
- package/src/field-builder.ts +3 -3
- package/src/generator.ts +18 -0
- package/src/global-types.ts +59 -12
- package/src/index.ts +75 -1
- package/src/model-loader.ts +19 -92
- package/src/prisma-field-builder.ts +194 -152
- package/src/schema-builder.ts +28 -7
- package/src/types.ts +138 -102
- package/src/{cursors.ts → util/cursors.ts} +1 -1
- package/src/{refs.ts → util/datamodel.ts} +3 -44
- package/src/util/deep-equal.ts +51 -0
- package/src/{loader-map.ts → util/loader-map.ts} +13 -13
- package/src/util/map-query.ts +327 -0
- package/src/util/relation-map.ts +36 -0
- package/src/util/selections.ts +192 -0
- package/esm/cursors.d.ts.map +0 -1
- package/esm/cursors.js.map +0 -1
- package/esm/loader-map.d.ts +0 -6
- package/esm/loader-map.d.ts.map +0 -1
- package/esm/loader-map.js.map +0 -1
- package/esm/refs.d.ts.map +0 -1
- package/esm/refs.js.map +0 -1
- package/esm/util/index.d.ts +0 -5
- package/esm/util/index.d.ts.map +0 -1
- package/esm/util/index.js +0 -16
- package/esm/util/index.js.map +0 -1
- package/esm/util/map-includes.d.ts +0 -6
- package/esm/util/map-includes.d.ts.map +0 -1
- package/esm/util/map-includes.js +0 -184
- package/esm/util/map-includes.js.map +0 -1
- package/esm/util/merge-includes.d.ts +0 -3
- package/esm/util/merge-includes.d.ts.map +0 -1
- package/esm/util/merge-includes.js +0 -91
- package/esm/util/merge-includes.js.map +0 -1
- package/lib/cursors.d.ts.map +0 -1
- package/lib/cursors.js.map +0 -1
- package/lib/loader-map.d.ts +0 -6
- package/lib/loader-map.d.ts.map +0 -1
- package/lib/loader-map.js.map +0 -1
- package/lib/refs.d.ts.map +0 -1
- package/lib/refs.js.map +0 -1
- package/lib/util/index.d.ts +0 -5
- package/lib/util/index.d.ts.map +0 -1
- package/lib/util/index.js +0 -30
- package/lib/util/index.js.map +0 -1
- package/lib/util/map-includes.d.ts +0 -6
- package/lib/util/map-includes.d.ts.map +0 -1
- package/lib/util/map-includes.js +0 -189
- package/lib/util/map-includes.js.map +0 -1
- package/lib/util/merge-includes.d.ts +0 -3
- package/lib/util/merge-includes.d.ts.map +0 -1
- package/lib/util/merge-includes.js +0 -96
- package/lib/util/merge-includes.js.map +0 -1
- package/src/util/index.ts +0 -26
- package/src/util/map-includes.ts +0 -328
- package/src/util/merge-includes.ts +0 -121
package/src/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
InterfaceParam,
|
|
11
11
|
ListResolveValue,
|
|
12
12
|
MaybePromise,
|
|
13
|
+
Normalize,
|
|
13
14
|
ObjectRef,
|
|
14
15
|
OutputShape,
|
|
15
16
|
OutputType,
|
|
@@ -26,52 +27,17 @@ export interface PrismaDelegate {
|
|
|
26
27
|
findUnique: (...args: any[]) => Promise<unknown>;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
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;
|
|
30
|
+
export const prismaModelName = Symbol.for('Pothos.prismaModelName');
|
|
67
31
|
|
|
68
32
|
export interface PrismaModelTypes {
|
|
69
33
|
Name: string;
|
|
70
34
|
Shape: {};
|
|
71
35
|
Include: unknown;
|
|
36
|
+
Select: unknown;
|
|
72
37
|
Where: {};
|
|
73
38
|
Fields: string;
|
|
74
39
|
ListRelations: string;
|
|
40
|
+
RelationName: string;
|
|
75
41
|
Relations: Record<
|
|
76
42
|
string,
|
|
77
43
|
{
|
|
@@ -81,52 +47,86 @@ export interface PrismaModelTypes {
|
|
|
81
47
|
>;
|
|
82
48
|
}
|
|
83
49
|
|
|
84
|
-
|
|
85
|
-
[
|
|
86
|
-
|
|
87
|
-
|
|
50
|
+
type ExtractModel<Types extends SchemaTypes, ParentShape> = ParentShape extends {
|
|
51
|
+
[prismaModelName]?: infer Name;
|
|
52
|
+
}
|
|
53
|
+
? Types['PrismaTypes'][Name & keyof Types['PrismaTypes']] extends infer Model
|
|
54
|
+
? Model extends PrismaModelTypes
|
|
55
|
+
? Model
|
|
88
56
|
: never
|
|
89
|
-
: never
|
|
90
|
-
|
|
57
|
+
: never
|
|
58
|
+
: never;
|
|
91
59
|
|
|
92
|
-
export type
|
|
60
|
+
export type PrismaObjectFieldOptions<
|
|
61
|
+
Types extends SchemaTypes,
|
|
62
|
+
ParentShape,
|
|
63
|
+
Type extends TypeParam<Types>,
|
|
64
|
+
Nullable extends FieldNullability<Type>,
|
|
65
|
+
Args extends InputFieldMap,
|
|
66
|
+
Select,
|
|
67
|
+
ResolveReturnShape,
|
|
68
|
+
> = PothosSchemaTypes.ObjectFieldOptions<
|
|
69
|
+
Types,
|
|
70
|
+
unknown extends Select
|
|
71
|
+
? ParentShape
|
|
72
|
+
: ParentShape & ShapeFromSelection<ExtractModel<Types, ParentShape>, { select: Select }>,
|
|
73
|
+
Type,
|
|
74
|
+
Nullable,
|
|
75
|
+
Args,
|
|
76
|
+
ResolveReturnShape
|
|
77
|
+
> & {
|
|
78
|
+
select?: ExtractModel<Types, ParentShape>['Select'] & Select;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type PrismaObjectFieldsShape<
|
|
93
82
|
Types extends SchemaTypes,
|
|
94
83
|
Model extends PrismaModelTypes,
|
|
95
84
|
NeedsResolve extends boolean,
|
|
96
85
|
Shape extends object,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
};
|
|
86
|
+
Select,
|
|
87
|
+
> = Model['Select'] extends Select
|
|
88
|
+
? (t: PrismaObjectFieldBuilder<Types, Model, NeedsResolve, Shape>) => FieldMap
|
|
89
|
+
: (t: PrismaSelectionFieldBuilder<Types, Model, Shape>) => FieldMap;
|
|
118
90
|
|
|
119
|
-
|
|
91
|
+
type PrismaSelectionFieldBuilder<
|
|
92
|
+
Types extends SchemaTypes,
|
|
120
93
|
Model extends PrismaModelTypes,
|
|
121
|
-
|
|
122
|
-
> =
|
|
94
|
+
Shape extends object,
|
|
95
|
+
> = PrismaObjectFieldBuilder<Types, Model, false, Shape>;
|
|
96
|
+
|
|
97
|
+
interface BaseSelection {
|
|
98
|
+
include?: unknown;
|
|
99
|
+
select?: unknown;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type SelectedKeys<T> = { [K in keyof T]: T[K] extends false ? never : K }[keyof T];
|
|
103
|
+
|
|
104
|
+
export type ShapeFromSelection<Model extends PrismaModelTypes, Selection> = Normalize<
|
|
105
|
+
Selection extends BaseSelection
|
|
106
|
+
? unknown extends Selection['select']
|
|
107
|
+
? Model['Shape'] & RelationShapeFromInclude<Model, Selection['include']>
|
|
108
|
+
: Pick<Model['Shape'], SelectedKeys<Selection['select']>> &
|
|
109
|
+
RelationShapeFromInclude<Model, Selection['select']>
|
|
110
|
+
: Model['Shape']
|
|
111
|
+
>;
|
|
112
|
+
|
|
113
|
+
type RelationShapeFromInclude<Model extends PrismaModelTypes, Include> = Normalize<{
|
|
114
|
+
[K in SelectedKeys<Include> as K extends Model['RelationName']
|
|
115
|
+
? K
|
|
116
|
+
: never]: K extends keyof Model['Relations']
|
|
117
|
+
? Model['Relations'][K]['Shape'] extends unknown[]
|
|
118
|
+
? ShapeFromSelection<Model['Relations'][K]['Types'], Include[K]>[]
|
|
119
|
+
: ShapeFromSelection<Model['Relations'][K]['Types'], Include[K]>
|
|
120
|
+
: unknown;
|
|
121
|
+
}>;
|
|
123
122
|
|
|
124
123
|
export type PrismaObjectTypeOptions<
|
|
125
124
|
Types extends SchemaTypes,
|
|
126
125
|
Model extends PrismaModelTypes,
|
|
127
126
|
Interfaces extends InterfaceParam<Types>[],
|
|
128
127
|
FindUnique,
|
|
129
|
-
Include
|
|
128
|
+
Include,
|
|
129
|
+
Select,
|
|
130
130
|
Shape extends object,
|
|
131
131
|
> = NameOrVariant &
|
|
132
132
|
Omit<
|
|
@@ -134,13 +134,28 @@ export type PrismaObjectTypeOptions<
|
|
|
134
134
|
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
135
135
|
'fields'
|
|
136
136
|
> & {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
fields?: PrismaObjectFieldsShape<
|
|
138
|
+
Types,
|
|
139
|
+
Model,
|
|
140
|
+
FindUnique extends null ? true : false,
|
|
141
|
+
Shape & (FindUnique extends null ? {} : { [prismaModelName]?: Model['Name'] }),
|
|
142
|
+
Select
|
|
143
|
+
>;
|
|
144
|
+
} & (
|
|
145
|
+
| {
|
|
146
|
+
include?: Include & Model['Include'];
|
|
147
|
+
select?: never;
|
|
148
|
+
findUnique: FindUnique &
|
|
149
|
+
(((parent: Shape, context: Types['Context']) => Model['Where']) | null);
|
|
150
|
+
}
|
|
151
|
+
| {
|
|
152
|
+
select: Model['Select'] & Select;
|
|
153
|
+
include?: never;
|
|
154
|
+
findUnique: (parent: Shape, context: Types['Context']) => Model['Where'];
|
|
155
|
+
}
|
|
156
|
+
);
|
|
142
157
|
|
|
143
|
-
|
|
158
|
+
type NameOrVariant =
|
|
144
159
|
| {
|
|
145
160
|
name?: never;
|
|
146
161
|
variant?: string;
|
|
@@ -154,7 +169,8 @@ export type PrismaNodeOptions<
|
|
|
154
169
|
Types extends SchemaTypes,
|
|
155
170
|
Model extends PrismaModelTypes,
|
|
156
171
|
Interfaces extends InterfaceParam<Types>[],
|
|
157
|
-
Include
|
|
172
|
+
Include,
|
|
173
|
+
Select,
|
|
158
174
|
Shape extends object,
|
|
159
175
|
> = NameOrVariant &
|
|
160
176
|
Omit<
|
|
@@ -162,7 +178,6 @@ export type PrismaNodeOptions<
|
|
|
162
178
|
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
163
179
|
'fields' | 'isTypeOf'
|
|
164
180
|
> & {
|
|
165
|
-
include?: Include;
|
|
166
181
|
id: Omit<
|
|
167
182
|
FieldOptionsFromKind<
|
|
168
183
|
Types,
|
|
@@ -178,11 +193,26 @@ export type PrismaNodeOptions<
|
|
|
178
193
|
> & {
|
|
179
194
|
resolve: (parent: Shape, context: Types['Context']) => MaybePromise<OutputShape<Types, 'ID'>>;
|
|
180
195
|
};
|
|
181
|
-
fields?: PrismaObjectFieldsShape<
|
|
196
|
+
fields?: PrismaObjectFieldsShape<
|
|
197
|
+
Types,
|
|
198
|
+
Model,
|
|
199
|
+
false,
|
|
200
|
+
Shape & { [prismaModelName]?: Model['Name'] },
|
|
201
|
+
Select
|
|
202
|
+
>;
|
|
182
203
|
findUnique: (id: string, context: Types['Context']) => Model['Where'];
|
|
183
|
-
}
|
|
204
|
+
} & (
|
|
205
|
+
| {
|
|
206
|
+
include?: Include & Model['Include'];
|
|
207
|
+
select?: never;
|
|
208
|
+
}
|
|
209
|
+
| {
|
|
210
|
+
select: Model['Select'] & Select;
|
|
211
|
+
include?: never;
|
|
212
|
+
}
|
|
213
|
+
);
|
|
184
214
|
|
|
185
|
-
|
|
215
|
+
type QueryForField<
|
|
186
216
|
Types extends SchemaTypes,
|
|
187
217
|
Args extends InputFieldMap,
|
|
188
218
|
Include,
|
|
@@ -195,18 +225,19 @@ export type QueryForField<
|
|
|
195
225
|
) => Omit<Include, 'include' | 'select'>)
|
|
196
226
|
: never;
|
|
197
227
|
|
|
198
|
-
|
|
228
|
+
type QueryFromRelation<
|
|
199
229
|
Model extends PrismaModelTypes,
|
|
200
230
|
Field extends keyof Model['Include'],
|
|
201
231
|
> = Model['Include'][Field] extends infer Include
|
|
202
232
|
? Include extends {
|
|
203
|
-
include?: infer
|
|
233
|
+
include?: infer I;
|
|
234
|
+
select?: infer S;
|
|
204
235
|
}
|
|
205
|
-
? NonNullable<
|
|
236
|
+
? { include?: NonNullable<I>; select?: NonNullable<S> }
|
|
206
237
|
: never
|
|
207
238
|
: never;
|
|
208
239
|
|
|
209
|
-
|
|
240
|
+
type CursorFromRelation<
|
|
210
241
|
Model extends PrismaModelTypes,
|
|
211
242
|
Field extends Model['ListRelations'],
|
|
212
243
|
> = Field extends keyof Model['Include']
|
|
@@ -217,7 +248,7 @@ export type CursorFromRelation<
|
|
|
217
248
|
: never
|
|
218
249
|
: never;
|
|
219
250
|
|
|
220
|
-
|
|
251
|
+
type RefForRelation<
|
|
221
252
|
Model extends PrismaModelTypes,
|
|
222
253
|
Field extends keyof Model['Relations'],
|
|
223
254
|
> = Model['Relations'][Field] extends unknown[]
|
|
@@ -247,7 +278,7 @@ export type RelatedFieldOptions<
|
|
|
247
278
|
(NeedsResolve extends false
|
|
248
279
|
? {
|
|
249
280
|
resolve?: (
|
|
250
|
-
query:
|
|
281
|
+
query: QueryFromRelation<Model, Field & keyof Model['Include']>,
|
|
251
282
|
parent: Shape,
|
|
252
283
|
args: InputShapeFromFields<Args>,
|
|
253
284
|
context: Types['Context'],
|
|
@@ -258,7 +289,7 @@ export type RelatedFieldOptions<
|
|
|
258
289
|
}
|
|
259
290
|
: {
|
|
260
291
|
resolve: (
|
|
261
|
-
query:
|
|
292
|
+
query: QueryFromRelation<Model, Field & keyof Model['Include']>,
|
|
262
293
|
parent: Shape,
|
|
263
294
|
args: InputShapeFromFields<Args>,
|
|
264
295
|
context: Types['Context'],
|
|
@@ -472,31 +503,36 @@ export type RelatedConnectionOptions<
|
|
|
472
503
|
|
|
473
504
|
export type WithBrand<T> = T & { [typeBrandKey]: string };
|
|
474
505
|
|
|
475
|
-
export type IncludeMap = Record<string,
|
|
506
|
+
export type IncludeMap = Record<string, SelectionMap | boolean>;
|
|
476
507
|
|
|
477
|
-
export interface
|
|
478
|
-
|
|
479
|
-
|
|
508
|
+
export interface SelectionMap {
|
|
509
|
+
select?: Record<string, SelectionMap | boolean>;
|
|
510
|
+
include?: Record<string, SelectionMap | boolean>;
|
|
511
|
+
where?: {};
|
|
480
512
|
}
|
|
481
513
|
|
|
514
|
+
export type FieldSelection =
|
|
515
|
+
| Record<string, SelectionMap | boolean>
|
|
516
|
+
| ((
|
|
517
|
+
args: object,
|
|
518
|
+
context: object,
|
|
519
|
+
query: (
|
|
520
|
+
selection: SelectionMap | boolean | ((args: object, context: object) => SelectionMap),
|
|
521
|
+
) => SelectionMap | boolean,
|
|
522
|
+
) => SelectionMap);
|
|
523
|
+
|
|
482
524
|
export type LoaderMappings = Record<
|
|
483
525
|
string,
|
|
484
526
|
{
|
|
485
527
|
field: string;
|
|
486
|
-
alias?: string;
|
|
487
528
|
mappings: LoaderMappings;
|
|
488
529
|
indirectPath: string[];
|
|
489
|
-
}
|
|
530
|
+
}
|
|
490
531
|
>;
|
|
491
532
|
|
|
492
|
-
export interface
|
|
493
|
-
|
|
494
|
-
name: string;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
export interface IndirectLoadMap {
|
|
498
|
-
subFields: SubFieldInclude[];
|
|
499
|
-
path: string[];
|
|
533
|
+
export interface IndirectInclude {
|
|
534
|
+
getType: () => string;
|
|
535
|
+
path: { type?: string; name: string }[];
|
|
500
536
|
}
|
|
501
537
|
|
|
502
538
|
export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
|
|
@@ -75,7 +75,7 @@ export function parseCompositeCursor(fields: string[]) {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
interface PrismaCursorConnectionQueryOptions {
|
|
78
|
+
export interface PrismaCursorConnectionQueryOptions {
|
|
79
79
|
args: PothosSchemaTypes.DefaultConnectionArguments;
|
|
80
80
|
defaultSize?: number;
|
|
81
81
|
maxSize?: number;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ObjectRef, SchemaTypes } from '@pothos/core';
|
|
2
|
-
import { Prisma } from '
|
|
2
|
+
import { Prisma } from '../../tests/client';
|
|
3
|
+
import { PrismaObjectRef } from '../object-ref';
|
|
4
|
+
import { PrismaDelegate, PrismaModelTypes } from '../types';
|
|
3
5
|
import { formatCursor, parseCompositeCursor, parseRawCursor } from './cursors';
|
|
4
|
-
import { PrismaObjectRef } from './object-ref';
|
|
5
|
-
import { PrismaDelegate } from './types';
|
|
6
|
-
import { PrismaModelTypes } from '.';
|
|
7
6
|
|
|
8
7
|
export const refMap = new WeakMap<object, Map<string, PrismaObjectRef<PrismaModelTypes>>>();
|
|
9
8
|
export const findUniqueMap = new WeakMap<
|
|
@@ -32,36 +31,6 @@ export function getRefFromModel<Types extends SchemaTypes>(
|
|
|
32
31
|
return cache.get(name)!;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
export function getFindUniqueForRef<Types extends SchemaTypes>(
|
|
36
|
-
ref: ObjectRef<unknown>,
|
|
37
|
-
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
38
|
-
) {
|
|
39
|
-
if (!findUniqueMap.has(builder)) {
|
|
40
|
-
findUniqueMap.set(builder, new Map());
|
|
41
|
-
}
|
|
42
|
-
const cache = findUniqueMap.get(builder)!;
|
|
43
|
-
|
|
44
|
-
if (!cache.has(ref)) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return cache.get(ref)! as (args: unknown, context: Types['Context']) => unknown;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function setFindUniqueForRef<Types extends SchemaTypes>(
|
|
52
|
-
ref: ObjectRef<unknown>,
|
|
53
|
-
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
findUnique: ((args: any, context: Types['Context']) => unknown) | null,
|
|
56
|
-
) {
|
|
57
|
-
if (!findUniqueMap.has(builder)) {
|
|
58
|
-
findUniqueMap.set(builder, new Map());
|
|
59
|
-
}
|
|
60
|
-
const cache = findUniqueMap.get(builder)!;
|
|
61
|
-
|
|
62
|
-
cache.set(ref, findUnique);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
34
|
export function getRelation<Types extends SchemaTypes>(
|
|
66
35
|
name: string,
|
|
67
36
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
@@ -126,16 +95,6 @@ export function getCursorParser<Types extends SchemaTypes>(
|
|
|
126
95
|
});
|
|
127
96
|
}
|
|
128
97
|
|
|
129
|
-
export function getRelatedDelegate<Types extends SchemaTypes>(
|
|
130
|
-
name: string,
|
|
131
|
-
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
132
|
-
relation: string,
|
|
133
|
-
) {
|
|
134
|
-
const fieldData = getRelation(name, builder, relation);
|
|
135
|
-
|
|
136
|
-
return fieldData.type;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
98
|
export function getDelegateFromModel(client: Record<string, unknown>, model: string) {
|
|
140
99
|
const lowerCase = `${model.slice(0, 1).toLowerCase()}${model.slice(1)}`;
|
|
141
100
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
export function deepEqual(left: unknown, right: unknown, ignore?: Set<string>) {
|
|
3
|
+
if (left === right) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
if (left && right && typeof left === 'object' && typeof right === 'object') {
|
|
8
|
+
if (Array.isArray(left)) {
|
|
9
|
+
if (!Array.isArray(right)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { length } = left;
|
|
14
|
+
|
|
15
|
+
if (right.length !== length) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < length; i += 1) {
|
|
20
|
+
if (!deepEqual(left[i], right[i])) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const keys = Object.keys(left);
|
|
29
|
+
const keyLength = keys.length;
|
|
30
|
+
|
|
31
|
+
if (keyLength !== Object.keys(right).length) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
if (ignore?.has(key)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
!deepEqual((left as Record<string, unknown>)[key], (right as Record<string, unknown>)[key])
|
|
42
|
+
) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { GraphQLResolveInfo } from 'graphql';
|
|
1
|
+
import { GraphQLNamedType, GraphQLResolveInfo } from 'graphql';
|
|
2
2
|
import { createContextCache } from '@pothos/core';
|
|
3
|
-
import { LoaderMappings } from '
|
|
3
|
+
import { LoaderMappings } from '../types';
|
|
4
|
+
import { getIndirectType } from './map-query';
|
|
4
5
|
|
|
5
6
|
const cache = createContextCache((ctx) => new Map<string, LoaderMappings>());
|
|
6
7
|
|
|
7
|
-
export function cacheKey(path: GraphQLResolveInfo['path'], subPath: string[]) {
|
|
8
|
+
export function cacheKey(type: string, path: GraphQLResolveInfo['path'], subPath: string[]) {
|
|
8
9
|
let key = '';
|
|
9
10
|
let current: GraphQLResolveInfo['path'] | undefined = path;
|
|
10
11
|
|
|
@@ -19,30 +20,29 @@ export function cacheKey(path: GraphQLResolveInfo['path'], subPath: string[]) {
|
|
|
19
20
|
key = `${key}.${entry}`;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
return key
|
|
23
|
+
return `${type}@${key}`;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function setLoaderMappings(
|
|
26
27
|
ctx: object,
|
|
27
|
-
|
|
28
|
+
info: GraphQLResolveInfo,
|
|
28
29
|
value: LoaderMappings,
|
|
30
|
+
type: GraphQLNamedType,
|
|
29
31
|
) {
|
|
30
32
|
Object.keys(value).forEach((field) => {
|
|
31
33
|
const map = cache(ctx);
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const key = cacheKey(path, subPath);
|
|
35
|
+
const mapping = value[field];
|
|
36
|
+
const subPath = [...mapping.indirectPath, field];
|
|
37
|
+
const key = cacheKey(getIndirectType(type, info).name, info.path, subPath);
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
}
|
|
39
|
+
map.set(key, mapping.mappings);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export function getLoaderMapping(ctx: object, path: GraphQLResolveInfo['path']) {
|
|
43
|
+
export function getLoaderMapping(ctx: object, path: GraphQLResolveInfo['path'], type: string) {
|
|
44
44
|
const map = cache(ctx);
|
|
45
|
-
const key = cacheKey(path, []);
|
|
45
|
+
const key = cacheKey(type, path, []);
|
|
46
46
|
|
|
47
47
|
return map.get(key) ?? null;
|
|
48
48
|
}
|