@pothos/plugin-prisma 0.17.1 → 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 +22 -0
- package/README.md +403 -308
- package/esm/field-builder.js +12 -14
- 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 +86 -117
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/schema-builder.js +15 -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} +10 -8
- package/esm/util/cursors.d.ts.map +1 -0
- package/esm/{cursors.js → util/cursors.js} +34 -13
- package/esm/util/cursors.js.map +1 -0
- package/{lib/refs.d.ts → esm/util/datamodel.d.ts} +9 -8
- package/esm/util/datamodel.d.ts.map +1 -0
- package/esm/{refs.js → util/datamodel.js} +27 -30
- 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 +16 -18
- 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 +90 -121
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +18 -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} +10 -8
- package/lib/util/cursors.d.ts.map +1 -0
- package/lib/{cursors.js → util/cursors.js} +39 -14
- package/lib/util/cursors.js.map +1 -0
- package/{esm/refs.d.ts → lib/util/datamodel.d.ts} +9 -8
- package/lib/util/datamodel.d.ts.map +1 -0
- package/lib/{refs.js → util/datamodel.js} +32 -35
- 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 +7 -7
- package/src/field-builder.ts +12 -12
- 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 +199 -147
- package/src/schema-builder.ts +29 -7
- package/src/types.ts +138 -102
- package/src/{cursors.ts → util/cursors.ts} +45 -20
- package/src/{refs.ts → util/datamodel.ts} +36 -40
- 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/.turbo/turbo-build.log +0 -17
- package/.turbo/turbo-test.log +0 -18
- package/.turbo/turbo-type.log +0 -5
- package/babel.config.js +0 -3
- 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/tsconfig.tsbuildinfo +0 -1
|
@@ -1,63 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { prismaCursorConnectionQuery, wrapConnectionResult } from './cursors.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { RootFieldBuilder, } from '@pothos/core';
|
|
2
|
+
import { prismaCursorConnectionQuery, wrapConnectionResult } from './util/cursors.js';
|
|
3
|
+
import { getCursorFormatter, getCursorParser, getRefFromModel, getRelation, } from './util/datamodel.js';
|
|
4
|
+
// Workaround for FieldKind not being extended on Builder classes
|
|
5
|
+
const RootBuilder = RootFieldBuilder;
|
|
6
|
+
export class PrismaObjectFieldBuilder extends RootBuilder {
|
|
7
|
+
constructor(name, builder, model, fieldMap) {
|
|
8
|
+
super(name, builder, "PrismaObject", "Object");
|
|
9
|
+
this.exposeBoolean = this.createExpose("Boolean");
|
|
10
|
+
this.exposeFloat = this.createExpose("Float");
|
|
11
|
+
this.exposeInt = this.createExpose("Int");
|
|
12
|
+
this.exposeID = this.createExpose("ID");
|
|
13
|
+
this.exposeString = this.createExpose("String");
|
|
14
|
+
this.exposeBooleanList = this.createExpose(["Boolean"]);
|
|
15
|
+
this.exposeFloatList = this.createExpose(["Float"]);
|
|
16
|
+
this.exposeIntList = this.createExpose(["Int"]);
|
|
17
|
+
this.exposeIDList = this.createExpose(["ID"]);
|
|
18
|
+
this.exposeStringList = this.createExpose(["String"]);
|
|
10
19
|
this.relatedConnection = function relatedConnection(name, { maxSize, defaultSize, cursor, query, resolve, extensions, totalCount, ...options }, connectionOptions = {}, edgeOptions = {}) {
|
|
11
20
|
var _a, _b;
|
|
12
21
|
const relationField = getRelation(this.model, this.builder, name);
|
|
13
|
-
const parentRef = getRefFromModel(this.model, this.builder);
|
|
14
22
|
const ref = (_a = options.type) !== null && _a !== void 0 ? _a : getRefFromModel(relationField.type, this.builder);
|
|
15
|
-
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
16
|
-
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
17
23
|
let typeName;
|
|
24
|
+
const formatCursor = getCursorFormatter(relationField.type, this.builder, cursor);
|
|
25
|
+
const parseCursor = getCursorParser(relationField.type, this.builder, cursor);
|
|
18
26
|
const getQuery = (args, ctx) => ({
|
|
19
27
|
...(typeof query === "function" ? query(args, ctx) : query),
|
|
20
28
|
...prismaCursorConnectionQuery({
|
|
21
|
-
|
|
29
|
+
parseCursor,
|
|
22
30
|
maxSize,
|
|
23
31
|
defaultSize,
|
|
24
32
|
args,
|
|
25
33
|
}),
|
|
26
34
|
});
|
|
35
|
+
const relationSelect = (args, context, nestedQuery) => ({
|
|
36
|
+
select: {
|
|
37
|
+
[name]: nestedQuery({
|
|
38
|
+
...(typeof query === "function" ? query(args, context) : query),
|
|
39
|
+
...prismaCursorConnectionQuery({
|
|
40
|
+
parseCursor,
|
|
41
|
+
maxSize,
|
|
42
|
+
defaultSize,
|
|
43
|
+
args,
|
|
44
|
+
}),
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
27
48
|
const fieldRef = this.connection({
|
|
28
49
|
...options,
|
|
29
50
|
extensions: {
|
|
30
51
|
...extensions,
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
pothosPrismaLoaded: (value) => value[name] !== undefined,
|
|
53
|
+
pothosPrismaFallback: resolve &&
|
|
54
|
+
((q, parent, args, context, info) => Promise.resolve(resolve({
|
|
55
|
+
...q,
|
|
56
|
+
...(typeof query === "function" ? query(args, context) : query),
|
|
57
|
+
}, parent, args, context, info)).then((result) => wrapConnectionResult(result, args, q.take, formatCursor))),
|
|
33
58
|
},
|
|
34
59
|
type: ref,
|
|
35
|
-
|
|
60
|
+
select: relationSelect,
|
|
61
|
+
resolve: (parent, args, context) => {
|
|
36
62
|
var _a;
|
|
37
63
|
const connectionQuery = getQuery(args, context);
|
|
38
|
-
|
|
39
|
-
const mapping = getLoaderMapping(context, info.path);
|
|
40
|
-
const loadedValue = parent[name];
|
|
41
|
-
if (
|
|
42
|
-
// if we attempted to load the relation, and its missing it will be null
|
|
43
|
-
// undefined means that the query was not constructed in a way that requested the relation
|
|
44
|
-
loadedValue !== undefined &&
|
|
45
|
-
mapping) {
|
|
46
|
-
if (loadedValue !== null && loadedValue !== undefined) {
|
|
47
|
-
setLoaderMappings(context, info.path, mapping);
|
|
48
|
-
}
|
|
49
|
-
return loadedValue;
|
|
50
|
-
}
|
|
51
|
-
if (!resolve && !findUnique) {
|
|
52
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
53
|
-
}
|
|
54
|
-
const mergedQuery = { ...queryFromInfo(context, info), ...connectionQuery };
|
|
55
|
-
if (resolve) {
|
|
56
|
-
return resolve(mergedQuery, parent, args, context, info);
|
|
57
|
-
}
|
|
58
|
-
return loaderCache(parent).loadRelation(name, mergedQuery, context);
|
|
59
|
-
};
|
|
60
|
-
return wrapConnectionResult(await getResult(), args, connectionQuery.take, cursor, (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name]);
|
|
64
|
+
return wrapConnectionResult(parent[name], args, connectionQuery.take, formatCursor, (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name]);
|
|
61
65
|
},
|
|
62
66
|
}, {
|
|
63
67
|
...connectionOptions,
|
|
@@ -67,15 +71,9 @@ export class PrismaObjectFieldBuilder extends ObjectFieldBuilder {
|
|
|
67
71
|
return ({
|
|
68
72
|
totalCount: t.int({
|
|
69
73
|
extensions: {
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
resolve: (parent, args, context) => {
|
|
73
|
-
const loadedValue = parent.totalCount;
|
|
74
|
-
if (loadedValue !== undefined) {
|
|
75
|
-
return loadedValue;
|
|
76
|
-
}
|
|
77
|
-
return loaderCache(parent).loadCount(name, context);
|
|
74
|
+
pothosPrismaParentSelect: { _count: { select: { [name]: true } } },
|
|
78
75
|
},
|
|
76
|
+
resolve: (parent, args, context) => parent.totalCount,
|
|
79
77
|
}),
|
|
80
78
|
...(_b = (_a = connectionOptions).fields) === null || _b === void 0 ? void 0 : _b.call(_a, t),
|
|
81
79
|
});
|
|
@@ -97,108 +95,79 @@ export class PrismaObjectFieldBuilder extends ObjectFieldBuilder {
|
|
|
97
95
|
return fieldRef;
|
|
98
96
|
};
|
|
99
97
|
this.model = model;
|
|
100
|
-
this.
|
|
98
|
+
this.prismaFieldMap = fieldMap;
|
|
101
99
|
}
|
|
102
100
|
relation(...allArgs) {
|
|
103
101
|
var _a;
|
|
104
102
|
const [name, options = {}] = allArgs;
|
|
105
103
|
const relationField = getRelation(this.model, this.builder, name);
|
|
106
|
-
const parentRef = getRefFromModel(this.model, this.builder);
|
|
107
104
|
const ref = (_a = options.type) !== null && _a !== void 0 ? _a : getRefFromModel(relationField.type, this.builder);
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const { query = {}, resolve, ...rest } = options;
|
|
105
|
+
const { query = {}, resolve, extensions, ...rest } = options;
|
|
106
|
+
const relationSelect = (args, context, nestedQuery) => ({ select: { [name]: nestedQuery(query) } });
|
|
111
107
|
return this.field({
|
|
112
108
|
...rest,
|
|
113
109
|
type: relationField.isList ? [ref] : ref,
|
|
114
110
|
extensions: {
|
|
115
|
-
...
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
resolve: (parent, args, context, info) => {
|
|
120
|
-
const mapping = getLoaderMapping(context, info.path);
|
|
121
|
-
const loadedValue = parent[name];
|
|
122
|
-
if (
|
|
123
|
-
// if we attempted to load the relation, and its missing it will be null
|
|
124
|
-
// undefined means that the query was not constructed in a way that requested the relation
|
|
125
|
-
loadedValue !== undefined &&
|
|
126
|
-
mapping) {
|
|
127
|
-
if (loadedValue !== null && loadedValue !== undefined) {
|
|
128
|
-
setLoaderMappings(context, info.path, mapping);
|
|
129
|
-
}
|
|
130
|
-
return loadedValue;
|
|
131
|
-
}
|
|
132
|
-
const queryOptions = {
|
|
133
|
-
...(typeof query === "function" ? query(args, context) : query),
|
|
134
|
-
...queryFromInfo(context, info),
|
|
135
|
-
};
|
|
136
|
-
if (resolve) {
|
|
137
|
-
return resolve(queryOptions, parent, args, context, info);
|
|
138
|
-
}
|
|
139
|
-
if (!findUnique) {
|
|
140
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
141
|
-
}
|
|
142
|
-
return loaderCache(parent).loadRelation(name, queryOptions, context);
|
|
111
|
+
...extensions,
|
|
112
|
+
pothosPrismaLoaded: (value) => value[name] !== undefined,
|
|
113
|
+
pothosPrismaFallback: resolve &&
|
|
114
|
+
((q, parent, args, context, info) => resolve({ ...q, ...(typeof query === "function" ? query(args, context) : query) }, parent, args, context, info)),
|
|
143
115
|
},
|
|
116
|
+
select: relationSelect,
|
|
117
|
+
resolve: (parent) => parent[name],
|
|
144
118
|
});
|
|
145
119
|
}
|
|
146
120
|
relationCount(...allArgs) {
|
|
147
121
|
const [name, options = {}] = allArgs;
|
|
148
|
-
const parentRef = getRefFromModel(this.model, this.builder);
|
|
149
|
-
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
150
|
-
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
151
122
|
const { resolve, ...rest } = options;
|
|
123
|
+
const countSelect = {
|
|
124
|
+
_count: {
|
|
125
|
+
select: { [name]: true },
|
|
126
|
+
},
|
|
127
|
+
};
|
|
152
128
|
return this.field({
|
|
153
129
|
...rest,
|
|
154
130
|
type: "Int",
|
|
155
131
|
nullable: false,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
pothosPrismaRelationCount: name,
|
|
159
|
-
},
|
|
160
|
-
resolve: (parent, args, context, info) => {
|
|
161
|
-
var _a;
|
|
162
|
-
const loadedValue = (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name];
|
|
163
|
-
if (loadedValue !== undefined) {
|
|
164
|
-
return loadedValue;
|
|
165
|
-
}
|
|
166
|
-
if (resolve) {
|
|
167
|
-
return resolve(parent, args, context, info);
|
|
168
|
-
}
|
|
169
|
-
if (!findUnique) {
|
|
170
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
171
|
-
}
|
|
172
|
-
return loaderCache(parent).loadCount(name, context);
|
|
173
|
-
},
|
|
132
|
+
select: countSelect,
|
|
133
|
+
resolve: (parent, args, context, info) => { var _a; return (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
174
134
|
});
|
|
175
135
|
}
|
|
176
136
|
variant(...allArgs) {
|
|
177
137
|
const [variant, options = {}] = allArgs;
|
|
178
138
|
const ref = typeof variant === "string" ? getRefFromModel(variant, this.builder) : variant;
|
|
179
|
-
const
|
|
180
|
-
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
181
|
-
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
139
|
+
const selfSelect = (args, context, nestedQuery) => nestedQuery({});
|
|
182
140
|
return this.field({
|
|
183
141
|
...options,
|
|
184
142
|
type: ref,
|
|
143
|
+
select: selfSelect,
|
|
144
|
+
resolve: (parent, args, context, info) => parent,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
expose(...args) {
|
|
148
|
+
var _a;
|
|
149
|
+
const [name, options = {}] = args;
|
|
150
|
+
const typeConfig = this.builder.configStore.getTypeConfig(this.typename, "Object");
|
|
151
|
+
const usingSelect = !!((_a = typeConfig.extensions) === null || _a === void 0 ? void 0 : _a.pothosPrismaSelect);
|
|
152
|
+
return this.exposeField(name, {
|
|
153
|
+
...options,
|
|
185
154
|
extensions: {
|
|
186
155
|
...options.extensions,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (mapping) {
|
|
192
|
-
setLoaderMappings(context, info.path, mapping);
|
|
193
|
-
return parent;
|
|
194
|
-
}
|
|
195
|
-
const queryOptions = queryFromInfo(context, info);
|
|
196
|
-
if (!findUnique) {
|
|
197
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
198
|
-
}
|
|
199
|
-
return loaderCache(parent).loadSelf(queryOptions, context);
|
|
156
|
+
pothosPrismaVariant: name,
|
|
157
|
+
pothosPrismaSelect: usingSelect && {
|
|
158
|
+
[name]: true,
|
|
159
|
+
},
|
|
200
160
|
},
|
|
201
161
|
});
|
|
202
162
|
}
|
|
163
|
+
createExpose(type) {
|
|
164
|
+
return (...args) => {
|
|
165
|
+
const [name, options = {}] = args;
|
|
166
|
+
return this.expose(name, {
|
|
167
|
+
...options,
|
|
168
|
+
type,
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
}
|
|
203
172
|
}
|
|
204
173
|
//# sourceMappingURL=prisma-field-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-field-builder.js","sourceRoot":"","sources":["../src/prisma-field-builder.ts"],"names":[],"mappings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M,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACnF,MAAM,WAAW,GAAG,CAAC,CAAC,CAAA,MAAA,UAAU,CAAC,UAAU,0CAAE,kBAAkB,CAAA,CAAC;QAEhE,OAAO,IAAI,CAAC,WAAW,CAAC,IAAa,EAAE;YACrC,GAAG,OAAO;YACV,UAAU,EAAE;gBACV,GAAG,OAAO,CAAC,UAAU;gBACrB,mBAAmB,EAAE,IAAI;gBACzB,kBAAkB,EAAE,WAAW,IAAI;oBACjC,CAAC,IAAI,CAAC,EAAE,IAAI;iBACb;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAgC,IAAU;QAC5D,OAAO,CAKL,GAAG,IAeF,EACD,EAAE;YACF,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,EAAW,CAAC,GAAG,IAAI,CAAC;YAE3C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAa,EAAE;gBAChC,GAAG,OAAO;gBACV,IAAI;aACL,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;CACF"}
|
package/esm/schema-builder.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import './global-types.js';
|
|
2
2
|
import SchemaBuilder, { brandWithType, } from '@pothos/core';
|
|
3
3
|
import { PrismaObjectFieldBuilder } from './field-builder.js';
|
|
4
|
+
import { ModelLoader } from './model-loader.js';
|
|
4
5
|
import PrismaNodeRef from './node-ref.js';
|
|
5
|
-
import { getDelegateFromModel, getRefFromModel
|
|
6
|
-
import { queryFromInfo } from './util/
|
|
6
|
+
import { getDelegateFromModel, getRefFromModel } from './util/datamodel.js';
|
|
7
|
+
import { queryFromInfo } from './util/map-query.js';
|
|
8
|
+
import { getRelationMap } from './util/relation-map.js';
|
|
7
9
|
const schemaBuilderProto = SchemaBuilder.prototype;
|
|
8
10
|
schemaBuilderProto.prismaObject = function prismaObject(type, { fields, findUnique, ...options }) {
|
|
9
11
|
var _a, _b;
|
|
10
12
|
const ref = options.variant ? this.objectRef(options.variant) : getRefFromModel(type, this);
|
|
11
13
|
const name = (_b = (_a = options.variant) !== null && _a !== void 0 ? _a : options.name) !== null && _b !== void 0 ? _b : type;
|
|
14
|
+
const fieldMap = getRelationMap(this.options.prisma.client).get(type);
|
|
12
15
|
ref.name = name;
|
|
13
|
-
setFindUniqueForRef(ref, this, findUnique);
|
|
14
16
|
this.objectType(ref, {
|
|
15
17
|
...options,
|
|
16
18
|
extensions: {
|
|
17
19
|
...options.extensions,
|
|
18
20
|
pothosPrismaInclude: options.include,
|
|
21
|
+
pothosPrismaModel: type,
|
|
22
|
+
pothosPrismaFieldMap: fieldMap,
|
|
23
|
+
pothosPrismaSelect: options.select,
|
|
24
|
+
pothosPrismaLoader: ModelLoader.forRef(type, findUnique ||
|
|
25
|
+
(() => {
|
|
26
|
+
throw new Error(`Missing findUnique for ${ref.name}`);
|
|
27
|
+
}), this),
|
|
19
28
|
},
|
|
20
29
|
name,
|
|
21
|
-
fields: fields
|
|
30
|
+
fields: fields
|
|
31
|
+
? () => fields(new PrismaObjectFieldBuilder(name, this, type, getRelationMap(this.options.prisma.client).get(type)))
|
|
32
|
+
: undefined,
|
|
22
33
|
});
|
|
23
34
|
return ref;
|
|
24
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-builder.js","sourceRoot":"","sources":["../src/schema-builder.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,aAAa,EAAE,EACpB,aAAa,GAOd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,aAAa,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"schema-builder.js","sourceRoot":"","sources":["../src/schema-builder.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,aAAa,E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zD,OAAO,OAAO,CAAC;AACjB,CAAU,CAAC"}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,103 +1,99 @@
|
|
|
1
1
|
import { GraphQLResolveInfo } from 'graphql';
|
|
2
|
-
import { FieldKind, FieldMap, FieldNullability, FieldOptionsFromKind, InputFieldMap, InputFieldsFromShape, InputShapeFromFields, InterfaceParam, ListResolveValue, MaybePromise, ObjectRef, OutputShape, OutputType, SchemaTypes, ShapeFromTypeParam, ShapeWithNullability, typeBrandKey, TypeParam } from '@pothos/core';
|
|
2
|
+
import { FieldKind, FieldMap, FieldNullability, FieldOptionsFromKind, InputFieldMap, InputFieldsFromShape, InputShapeFromFields, InterfaceParam, ListResolveValue, MaybePromise, Normalize, ObjectRef, OutputShape, OutputType, SchemaTypes, ShapeFromTypeParam, ShapeWithNullability, typeBrandKey, TypeParam } from '@pothos/core';
|
|
3
3
|
import { PrismaObjectFieldBuilder } from './field-builder';
|
|
4
4
|
import { PrismaObjectRef } from './object-ref';
|
|
5
5
|
export interface PrismaDelegate {
|
|
6
6
|
findUnique: (...args: any[]) => Promise<unknown>;
|
|
7
7
|
}
|
|
8
|
-
declare
|
|
9
|
-
[K in keyof T]: T[K] extends (args: {}) => {
|
|
10
|
-
then: (cb: (result: unknown) => unknown) => unknown;
|
|
11
|
-
} ? K : never;
|
|
12
|
-
}[keyof T];
|
|
13
|
-
export declare type ModelTypes<Model extends {}> = Model extends {
|
|
14
|
-
findUnique: (options: infer UniqueOptions & {
|
|
15
|
-
where?: infer Where | null | undefined;
|
|
16
|
-
select?: infer Select | null | undefined;
|
|
17
|
-
} & ({
|
|
18
|
-
include?: infer Include | null | undefined;
|
|
19
|
-
} | {})) => infer Chain & {
|
|
20
|
-
then: (cb: (result: infer Shape | null) => unknown) => unknown;
|
|
21
|
-
};
|
|
22
|
-
} ? PrismaModelTypes & {
|
|
23
|
-
Shape: Shape;
|
|
24
|
-
Include: unknown extends Include ? never : Include;
|
|
25
|
-
Where: Where;
|
|
26
|
-
Fields: keyof Select;
|
|
27
|
-
ListRelation: ListRelationFields<Include> & string;
|
|
28
|
-
Relations: {
|
|
29
|
-
[RelationName in RelationKeys<Chain>]: Chain[RelationName] extends (args: {}) => {
|
|
30
|
-
then: (cb: (result: infer Relation) => unknown) => unknown;
|
|
31
|
-
} ? {
|
|
32
|
-
Shape: Relation;
|
|
33
|
-
Types: PrismaModelTypes;
|
|
34
|
-
} : never;
|
|
35
|
-
};
|
|
36
|
-
} : never;
|
|
8
|
+
export declare const prismaModelName: unique symbol;
|
|
37
9
|
export interface PrismaModelTypes {
|
|
38
10
|
Name: string;
|
|
39
11
|
Shape: {};
|
|
40
12
|
Include: unknown;
|
|
13
|
+
Select: unknown;
|
|
41
14
|
Where: {};
|
|
42
15
|
Fields: string;
|
|
43
16
|
ListRelations: string;
|
|
17
|
+
RelationName: string;
|
|
44
18
|
Relations: Record<string, {
|
|
45
19
|
Shape: unknown;
|
|
46
20
|
Types: PrismaModelTypes;
|
|
47
21
|
}>;
|
|
48
22
|
}
|
|
49
|
-
|
|
50
|
-
[
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
[K in keyof Include & keyof Model['Relations']]: Model['Relations'][K]['Shape'] extends infer RelationShape ? RelationShape extends (infer ItemShape)[] ? (ItemShape & (Include[K] extends {
|
|
57
|
-
include?: infer NestedInclude & object;
|
|
58
|
-
} ? ShapeFromInclude<Model['Relations'][K]['Types'], NestedInclude> : {}))[] : RelationShape & ((Include[K] extends {
|
|
59
|
-
include?: infer NestedInclude & object;
|
|
60
|
-
} ? ShapeFromInclude<Model['Relations'][K]['Types'], NestedInclude> : {}) | null) : never;
|
|
23
|
+
declare type ExtractModel<Types extends SchemaTypes, ParentShape> = ParentShape extends {
|
|
24
|
+
[prismaModelName]?: infer Name;
|
|
25
|
+
} ? Types['PrismaTypes'][Name & keyof Types['PrismaTypes']] extends infer Model ? Model extends PrismaModelTypes ? Model : never : never : never;
|
|
26
|
+
export declare type PrismaObjectFieldOptions<Types extends SchemaTypes, ParentShape, Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, Args extends InputFieldMap, Select, ResolveReturnShape> = PothosSchemaTypes.ObjectFieldOptions<Types, unknown extends Select ? ParentShape : ParentShape & ShapeFromSelection<ExtractModel<Types, ParentShape>, {
|
|
27
|
+
select: Select;
|
|
28
|
+
}>, Type, Nullable, Args, ResolveReturnShape> & {
|
|
29
|
+
select?: ExtractModel<Types, ParentShape>['Select'] & Select;
|
|
61
30
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
31
|
+
declare type PrismaObjectFieldsShape<Types extends SchemaTypes, Model extends PrismaModelTypes, NeedsResolve extends boolean, Shape extends object, Select> = Model['Select'] extends Select ? (t: PrismaObjectFieldBuilder<Types, Model, NeedsResolve, Shape>) => FieldMap : (t: PrismaSelectionFieldBuilder<Types, Model, Shape>) => FieldMap;
|
|
32
|
+
declare type PrismaSelectionFieldBuilder<Types extends SchemaTypes, Model extends PrismaModelTypes, Shape extends object> = PrismaObjectFieldBuilder<Types, Model, false, Shape>;
|
|
33
|
+
interface BaseSelection {
|
|
34
|
+
include?: unknown;
|
|
35
|
+
select?: unknown;
|
|
36
|
+
}
|
|
37
|
+
export declare type SelectedKeys<T> = {
|
|
38
|
+
[K in keyof T]: T[K] extends false ? never : K;
|
|
39
|
+
}[keyof T];
|
|
40
|
+
export declare type ShapeFromSelection<Model extends PrismaModelTypes, Selection> = Normalize<Selection extends BaseSelection ? unknown extends Selection['select'] ? Model['Shape'] & RelationShapeFromInclude<Model, Selection['include']> : Pick<Model['Shape'], SelectedKeys<Selection['select']>> & RelationShapeFromInclude<Model, Selection['select']> : Model['Shape']>;
|
|
41
|
+
declare type RelationShapeFromInclude<Model extends PrismaModelTypes, Include> = Normalize<{
|
|
42
|
+
[K in SelectedKeys<Include> as K extends Model['RelationName'] ? K : never]: K extends keyof Model['Relations'] ? Model['Relations'][K]['Shape'] extends unknown[] ? ShapeFromSelection<Model['Relations'][K]['Types'], Include[K]>[] : ShapeFromSelection<Model['Relations'][K]['Types'], Include[K]> : unknown;
|
|
43
|
+
}>;
|
|
44
|
+
export declare type PrismaObjectTypeOptions<Types extends SchemaTypes, Model extends PrismaModelTypes, Interfaces extends InterfaceParam<Types>[], FindUnique, Include, Select, Shape extends object> = NameOrVariant & Omit<PothosSchemaTypes.ObjectTypeOptions<Types, Shape> | PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>, 'fields'> & {
|
|
45
|
+
fields?: PrismaObjectFieldsShape<Types, Model, FindUnique extends null ? true : false, Shape & (FindUnique extends null ? {} : {
|
|
46
|
+
[prismaModelName]?: Model['Name'];
|
|
47
|
+
}), Select>;
|
|
48
|
+
} & ({
|
|
49
|
+
include?: Include & Model['Include'];
|
|
50
|
+
select?: never;
|
|
66
51
|
findUnique: FindUnique & (((parent: Shape, context: Types['Context']) => Model['Where']) | null);
|
|
67
|
-
}
|
|
68
|
-
|
|
52
|
+
} | {
|
|
53
|
+
select: Model['Select'] & Select;
|
|
54
|
+
include?: never;
|
|
55
|
+
findUnique: (parent: Shape, context: Types['Context']) => Model['Where'];
|
|
56
|
+
});
|
|
57
|
+
declare type NameOrVariant = {
|
|
69
58
|
name?: never;
|
|
70
59
|
variant?: string;
|
|
71
60
|
} | {
|
|
72
61
|
name?: string;
|
|
73
62
|
variant?: never;
|
|
74
63
|
};
|
|
75
|
-
export declare type PrismaNodeOptions<Types extends SchemaTypes, Model extends PrismaModelTypes, Interfaces extends InterfaceParam<Types>[], Include
|
|
76
|
-
include?: Include;
|
|
64
|
+
export declare type PrismaNodeOptions<Types extends SchemaTypes, Model extends PrismaModelTypes, Interfaces extends InterfaceParam<Types>[], Include, Select, Shape extends object> = NameOrVariant & Omit<PothosSchemaTypes.ObjectTypeOptions<Types, Shape> | PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>, 'fields' | 'isTypeOf'> & {
|
|
77
65
|
id: Omit<FieldOptionsFromKind<Types, Shape, 'ID', false, {}, 'Object', OutputShape<Types, 'ID'>, MaybePromise<OutputShape<Types, 'ID'>>>, 'args' | 'nullable' | 'resolve' | 'type'> & {
|
|
78
66
|
resolve: (parent: Shape, context: Types['Context']) => MaybePromise<OutputShape<Types, 'ID'>>;
|
|
79
67
|
};
|
|
80
|
-
fields?: PrismaObjectFieldsShape<Types, Model, false, Shape
|
|
68
|
+
fields?: PrismaObjectFieldsShape<Types, Model, false, Shape & {
|
|
69
|
+
[prismaModelName]?: Model['Name'];
|
|
70
|
+
}, Select>;
|
|
81
71
|
findUnique: (id: string, context: Types['Context']) => Model['Where'];
|
|
82
|
-
}
|
|
83
|
-
|
|
72
|
+
} & ({
|
|
73
|
+
include?: Include & Model['Include'];
|
|
74
|
+
select?: never;
|
|
75
|
+
} | {
|
|
76
|
+
select: Model['Select'] & Select;
|
|
77
|
+
include?: never;
|
|
78
|
+
});
|
|
79
|
+
declare type QueryForField<Types extends SchemaTypes, Args extends InputFieldMap, Include> = Include extends {
|
|
84
80
|
where?: unknown;
|
|
85
81
|
} ? Omit<Include, 'include' | 'select'> | ((args: InputShapeFromFields<Args>, ctx: Types['Context']) => Omit<Include, 'include' | 'select'>) : never;
|
|
86
|
-
|
|
87
|
-
include?: infer
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
declare type QueryFromRelation<Model extends PrismaModelTypes, Field extends keyof Model['Include']> = Model['Include'][Field] extends infer Include ? Include extends {
|
|
83
|
+
include?: infer I;
|
|
84
|
+
select?: infer S;
|
|
85
|
+
} ? {
|
|
86
|
+
include?: NonNullable<I>;
|
|
87
|
+
select?: NonNullable<S>;
|
|
88
|
+
} : never : never;
|
|
89
|
+
declare type CursorFromRelation<Model extends PrismaModelTypes, Field extends Model['ListRelations']> = Field extends keyof Model['Include'] ? Model['Include'][Field] extends infer Include ? Include extends {
|
|
90
90
|
cursor?: infer T;
|
|
91
91
|
} ? keyof T : never : never : never;
|
|
92
|
-
|
|
92
|
+
declare type RefForRelation<Model extends PrismaModelTypes, Field extends keyof Model['Relations']> = Model['Relations'][Field] extends unknown[] ? [ObjectRef<Model['Relations'][Field]>] : ObjectRef<Model['Relations'][Field]>;
|
|
93
93
|
export declare type RelatedFieldOptions<Types extends SchemaTypes, Model extends PrismaModelTypes, Field extends keyof Model['Relations'], Nullable extends boolean, Args extends InputFieldMap, ResolveReturnShape, NeedsResolve extends boolean, Shape> = Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, RefForRelation<Model, Field>, Nullable, Args, ResolveReturnShape>, 'resolve' | 'type'> & (NeedsResolve extends false ? {
|
|
94
|
-
resolve?: (query:
|
|
95
|
-
include?: IncludeFromRelation<Model, Field & keyof Model['Include']>;
|
|
96
|
-
}, parent: Shape, args: InputShapeFromFields<Args>, context: Types['Context'], info: GraphQLResolveInfo) => MaybePromise<ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>>;
|
|
94
|
+
resolve?: (query: QueryFromRelation<Model, Field & keyof Model['Include']>, parent: Shape, args: InputShapeFromFields<Args>, context: Types['Context'], info: GraphQLResolveInfo) => MaybePromise<ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>>;
|
|
97
95
|
} : {
|
|
98
|
-
resolve: (query:
|
|
99
|
-
include?: IncludeFromRelation<Model, Field & keyof Model['Include']>;
|
|
100
|
-
}, parent: Shape, args: InputShapeFromFields<Args>, context: Types['Context'], info: GraphQLResolveInfo) => MaybePromise<ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>>;
|
|
96
|
+
resolve: (query: QueryFromRelation<Model, Field & keyof Model['Include']>, parent: Shape, args: InputShapeFromFields<Args>, context: Types['Context'], info: GraphQLResolveInfo) => MaybePromise<ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>>;
|
|
101
97
|
}) & {
|
|
102
98
|
type?: PrismaObjectRef<Model['Relations'][Field]['Types']>;
|
|
103
99
|
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
@@ -151,24 +147,24 @@ export declare type RelatedConnectionOptions<Types extends SchemaTypes, Model ex
|
|
|
151
147
|
export declare type WithBrand<T> = T & {
|
|
152
148
|
[typeBrandKey]: string;
|
|
153
149
|
};
|
|
154
|
-
export declare type IncludeMap = Record<string,
|
|
155
|
-
export interface
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
export declare type IncludeMap = Record<string, SelectionMap | boolean>;
|
|
151
|
+
export interface SelectionMap {
|
|
152
|
+
select?: Record<string, SelectionMap | boolean>;
|
|
153
|
+
include?: Record<string, SelectionMap | boolean>;
|
|
154
|
+
where?: {};
|
|
158
155
|
}
|
|
156
|
+
export declare type FieldSelection = Record<string, SelectionMap | boolean> | ((args: object, context: object, query: (selection: SelectionMap | boolean | ((args: object, context: object) => SelectionMap)) => SelectionMap | boolean) => SelectionMap);
|
|
159
157
|
export declare type LoaderMappings = Record<string, {
|
|
160
158
|
field: string;
|
|
161
|
-
alias?: string;
|
|
162
159
|
mappings: LoaderMappings;
|
|
163
160
|
indirectPath: string[];
|
|
164
|
-
}
|
|
165
|
-
export interface
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
path: string[];
|
|
161
|
+
}>;
|
|
162
|
+
export interface IndirectInclude {
|
|
163
|
+
getType: () => string;
|
|
164
|
+
path: {
|
|
165
|
+
type?: string;
|
|
166
|
+
name: string;
|
|
167
|
+
}[];
|
|
172
168
|
}
|
|
173
169
|
export declare type ShapeFromConnection<T> = T extends {
|
|
174
170
|
shape: unknown;
|