@pothos/plugin-prisma 0.18.0 → 3.1.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 +18 -0
- package/README.md +420 -315
- package/esm/field-builder.d.ts.map +1 -1
- package/esm/field-builder.js +19 -6
- 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 +18 -78
- 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 -118
- 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 +74 -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} +5 -5
- 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.d.ts.map +1 -1
- package/lib/field-builder.js +30 -13
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +9 -1
- 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 +50 -1
- 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 +19 -79
- 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 +92 -124
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +22 -8
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.d.ts +74 -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} +5 -5
- 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 +8 -8
- package/src/field-builder.ts +22 -5
- package/src/generator.ts +18 -0
- package/src/global-types.ts +59 -12
- package/src/index.ts +75 -1
- package/src/model-loader.ts +27 -106
- package/src/prisma-field-builder.ts +195 -152
- package/src/schema-builder.ts +28 -7
- package/src/types.ts +155 -102
- package/src/{cursors.ts → util/cursors.ts} +3 -3
- 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
|
@@ -1,19 +1,25 @@
|
|
|
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
|
-
var _a
|
|
20
|
+
var _a;
|
|
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;
|
|
18
24
|
const formatCursor = getCursorFormatter(relationField.type, this.builder, cursor);
|
|
19
25
|
const parseCursor = getCursorParser(relationField.type, this.builder, cursor);
|
|
@@ -26,40 +32,36 @@ export class PrismaObjectFieldBuilder extends ObjectFieldBuilder {
|
|
|
26
32
|
args,
|
|
27
33
|
}),
|
|
28
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
|
+
});
|
|
29
48
|
const fieldRef = this.connection({
|
|
30
49
|
...options,
|
|
31
50
|
extensions: {
|
|
32
51
|
...extensions,
|
|
33
|
-
|
|
34
|
-
|
|
52
|
+
pothosPrismaSelect: relationSelect,
|
|
53
|
+
pothosPrismaLoaded: (value) => value[name] !== undefined,
|
|
54
|
+
pothosPrismaFallback: resolve &&
|
|
55
|
+
((q, parent, args, context, info) => Promise.resolve(resolve({
|
|
56
|
+
...q,
|
|
57
|
+
...(typeof query === "function" ? query(args, context) : query),
|
|
58
|
+
}, parent, args, context, info)).then((result) => wrapConnectionResult(result, args, q.take, formatCursor))),
|
|
35
59
|
},
|
|
36
60
|
type: ref,
|
|
37
|
-
resolve:
|
|
61
|
+
resolve: (parent, args, context) => {
|
|
38
62
|
var _a;
|
|
39
63
|
const connectionQuery = getQuery(args, context);
|
|
40
|
-
|
|
41
|
-
const mapping = getLoaderMapping(context, info.path);
|
|
42
|
-
const loadedValue = parent[name];
|
|
43
|
-
if (
|
|
44
|
-
// if we attempted to load the relation, and its missing it will be null
|
|
45
|
-
// undefined means that the query was not constructed in a way that requested the relation
|
|
46
|
-
loadedValue !== undefined &&
|
|
47
|
-
mapping) {
|
|
48
|
-
if (loadedValue !== null && loadedValue !== undefined) {
|
|
49
|
-
setLoaderMappings(context, info.path, mapping);
|
|
50
|
-
}
|
|
51
|
-
return loadedValue;
|
|
52
|
-
}
|
|
53
|
-
if (!resolve && !findUnique) {
|
|
54
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
55
|
-
}
|
|
56
|
-
const mergedQuery = { ...queryFromInfo(context, info), ...connectionQuery };
|
|
57
|
-
if (resolve) {
|
|
58
|
-
return resolve(mergedQuery, parent, args, context, info);
|
|
59
|
-
}
|
|
60
|
-
return loaderCache(parent).loadRelation(name, mergedQuery, context);
|
|
61
|
-
};
|
|
62
|
-
return wrapConnectionResult(await getResult(), args, connectionQuery.take, formatCursor, (_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]);
|
|
63
65
|
},
|
|
64
66
|
}, {
|
|
65
67
|
...connectionOptions,
|
|
@@ -68,23 +70,18 @@ export class PrismaObjectFieldBuilder extends ObjectFieldBuilder {
|
|
|
68
70
|
var _a, _b;
|
|
69
71
|
return ({
|
|
70
72
|
totalCount: t.int({
|
|
73
|
+
nullable: false,
|
|
71
74
|
extensions: {
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
resolve: (parent, args, context) => {
|
|
75
|
-
const loadedValue = parent.totalCount;
|
|
76
|
-
if (loadedValue !== undefined) {
|
|
77
|
-
return loadedValue;
|
|
78
|
-
}
|
|
79
|
-
return loaderCache(parent).loadCount(name, context);
|
|
75
|
+
pothosPrismaParentSelect: { _count: { select: { [name]: true } } },
|
|
80
76
|
},
|
|
77
|
+
resolve: (parent, args, context) => parent.totalCount,
|
|
81
78
|
}),
|
|
82
79
|
...(_b = (_a = connectionOptions).fields) === null || _b === void 0 ? void 0 : _b.call(_a, t),
|
|
83
80
|
});
|
|
84
81
|
}
|
|
85
82
|
: connectionOptions.fields,
|
|
86
83
|
extensions: {
|
|
87
|
-
...
|
|
84
|
+
...connectionOptions === null || connectionOptions === void 0 ? void 0 : connectionOptions.extensions,
|
|
88
85
|
pothosPrismaIndirectInclude: {
|
|
89
86
|
getType: () => {
|
|
90
87
|
if (!typeName) {
|
|
@@ -99,108 +96,79 @@ export class PrismaObjectFieldBuilder extends ObjectFieldBuilder {
|
|
|
99
96
|
return fieldRef;
|
|
100
97
|
};
|
|
101
98
|
this.model = model;
|
|
102
|
-
this.
|
|
99
|
+
this.prismaFieldMap = fieldMap;
|
|
103
100
|
}
|
|
104
101
|
relation(...allArgs) {
|
|
105
102
|
var _a;
|
|
106
103
|
const [name, options = {}] = allArgs;
|
|
107
104
|
const relationField = getRelation(this.model, this.builder, name);
|
|
108
|
-
const parentRef = getRefFromModel(this.model, this.builder);
|
|
109
105
|
const ref = (_a = options.type) !== null && _a !== void 0 ? _a : getRefFromModel(relationField.type, this.builder);
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const { query = {}, resolve, ...rest } = options;
|
|
106
|
+
const { query = {}, resolve, extensions, ...rest } = options;
|
|
107
|
+
const relationSelect = (args, context, nestedQuery) => ({ select: { [name]: nestedQuery(query) } });
|
|
113
108
|
return this.field({
|
|
114
109
|
...rest,
|
|
115
110
|
type: relationField.isList ? [ref] : ref,
|
|
116
111
|
extensions: {
|
|
117
|
-
...
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const mapping = getLoaderMapping(context, info.path);
|
|
123
|
-
const loadedValue = parent[name];
|
|
124
|
-
if (
|
|
125
|
-
// if we attempted to load the relation, and its missing it will be null
|
|
126
|
-
// undefined means that the query was not constructed in a way that requested the relation
|
|
127
|
-
loadedValue !== undefined &&
|
|
128
|
-
mapping) {
|
|
129
|
-
if (loadedValue !== null && loadedValue !== undefined) {
|
|
130
|
-
setLoaderMappings(context, info.path, mapping);
|
|
131
|
-
}
|
|
132
|
-
return loadedValue;
|
|
133
|
-
}
|
|
134
|
-
const queryOptions = {
|
|
135
|
-
...(typeof query === "function" ? query(args, context) : query),
|
|
136
|
-
...queryFromInfo(context, info),
|
|
137
|
-
};
|
|
138
|
-
if (resolve) {
|
|
139
|
-
return resolve(queryOptions, parent, args, context, info);
|
|
140
|
-
}
|
|
141
|
-
if (!findUnique) {
|
|
142
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
143
|
-
}
|
|
144
|
-
return loaderCache(parent).loadRelation(name, queryOptions, context);
|
|
112
|
+
...extensions,
|
|
113
|
+
pothosPrismaSelect: relationSelect,
|
|
114
|
+
pothosPrismaLoaded: (value) => value[name] !== undefined,
|
|
115
|
+
pothosPrismaFallback: resolve &&
|
|
116
|
+
((q, parent, args, context, info) => resolve({ ...q, ...(typeof query === "function" ? query(args, context) : query) }, parent, args, context, info)),
|
|
145
117
|
},
|
|
118
|
+
resolve: (parent) => parent[name],
|
|
146
119
|
});
|
|
147
120
|
}
|
|
148
121
|
relationCount(...allArgs) {
|
|
149
122
|
const [name, options = {}] = allArgs;
|
|
150
|
-
const parentRef = getRefFromModel(this.model, this.builder);
|
|
151
|
-
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
152
|
-
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
153
123
|
const { resolve, ...rest } = options;
|
|
124
|
+
const countSelect = {
|
|
125
|
+
_count: {
|
|
126
|
+
select: { [name]: true },
|
|
127
|
+
},
|
|
128
|
+
};
|
|
154
129
|
return this.field({
|
|
155
130
|
...rest,
|
|
156
131
|
type: "Int",
|
|
157
132
|
nullable: false,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
pothosPrismaRelationCount: name,
|
|
161
|
-
},
|
|
162
|
-
resolve: (parent, args, context, info) => {
|
|
163
|
-
var _a;
|
|
164
|
-
const loadedValue = (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name];
|
|
165
|
-
if (loadedValue !== undefined) {
|
|
166
|
-
return loadedValue;
|
|
167
|
-
}
|
|
168
|
-
if (resolve) {
|
|
169
|
-
return resolve(parent, args, context, info);
|
|
170
|
-
}
|
|
171
|
-
if (!findUnique) {
|
|
172
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
173
|
-
}
|
|
174
|
-
return loaderCache(parent).loadCount(name, context);
|
|
175
|
-
},
|
|
133
|
+
select: countSelect,
|
|
134
|
+
resolve: (parent, args, context, info) => { var _a; return (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
176
135
|
});
|
|
177
136
|
}
|
|
178
137
|
variant(...allArgs) {
|
|
179
138
|
const [variant, options = {}] = allArgs;
|
|
180
139
|
const ref = typeof variant === "string" ? getRefFromModel(variant, this.builder) : variant;
|
|
181
|
-
const
|
|
182
|
-
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
183
|
-
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
140
|
+
const selfSelect = (args, context, nestedQuery) => nestedQuery({});
|
|
184
141
|
return this.field({
|
|
185
142
|
...options,
|
|
186
143
|
type: ref,
|
|
144
|
+
select: selfSelect,
|
|
145
|
+
resolve: (parent, args, context, info) => parent,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
expose(...args) {
|
|
149
|
+
var _a;
|
|
150
|
+
const [name, options = {}] = args;
|
|
151
|
+
const typeConfig = this.builder.configStore.getTypeConfig(this.typename, "Object");
|
|
152
|
+
const usingSelect = !!((_a = typeConfig.extensions) === null || _a === void 0 ? void 0 : _a.pothosPrismaSelect);
|
|
153
|
+
return this.exposeField(name, {
|
|
154
|
+
...options,
|
|
187
155
|
extensions: {
|
|
188
156
|
...options.extensions,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (mapping) {
|
|
194
|
-
setLoaderMappings(context, info.path, mapping);
|
|
195
|
-
return parent;
|
|
196
|
-
}
|
|
197
|
-
const queryOptions = queryFromInfo(context, info);
|
|
198
|
-
if (!findUnique) {
|
|
199
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
200
|
-
}
|
|
201
|
-
return loaderCache(parent).loadSelf(queryOptions, context);
|
|
157
|
+
pothosPrismaVariant: name,
|
|
158
|
+
pothosPrismaSelect: usingSelect && {
|
|
159
|
+
[name]: true,
|
|
160
|
+
},
|
|
202
161
|
},
|
|
203
162
|
});
|
|
204
163
|
}
|
|
164
|
+
createExpose(type) {
|
|
165
|
+
return (...args) => {
|
|
166
|
+
const [name, options = {}] = args;
|
|
167
|
+
return this.expose(name, {
|
|
168
|
+
...options,
|
|
169
|
+
type,
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
}
|
|
205
173
|
}
|
|
206
174
|
//# 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":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"prisma-field-builder.js","sourceRoot":"","sources":["../src/prisma-field-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EASL,gBAAgB,GAGjB,MAAM,cAAc,CAAC;AAUtB,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,iEAAiE;AACjE,MAAM,WAAW,GAQb,gBAAyB,CAAC;AAE9B,MAAM,OAAO,wBAKX,SAAQ,WAAyC;IA2LjD,YACE,IAAY,EACZ,OAA+C,EAC/C,KAAa,EACb,QAAkB;QAElB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;QA7LjD,kBAAa,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAC7C,gBAAW,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACzC,cAAS,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACrC,aAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACnC,iBAAY,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC3C,sBAAiB,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACnD,oBAAe,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAC/C,kBAAa,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3C,iBAAY,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,C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AAM;SACjD,CAAuC,CAAC;IAC3C,CAAC;IAED,MAAM,CAMJ,GAAG,IAeF;;QAED,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,EAAW,CAAC,GAAG,IAAI,CAAC;QAE3C,MAAM,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,25 +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,
|
|
19
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),
|
|
20
28
|
},
|
|
21
29
|
name,
|
|
22
|
-
fields: fields
|
|
30
|
+
fields: fields
|
|
31
|
+
? () => fields(new PrismaObjectFieldBuilder(name, this, type, getRelationMap(this.options.prisma.client).get(type)))
|
|
32
|
+
: undefined,
|
|
23
33
|
});
|
|
24
34
|
return ref;
|
|
25
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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AC9C,CAAC;SACH,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzD,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 extends (...args: any[]) => infer S ? S : Select;
|
|
28
|
+
}>, Type, Nullable, Args, ResolveReturnShape> & {
|
|
29
|
+
select?: Select & (ExtractModel<Types, ParentShape>['Select'] | ((args: InputShapeFromFields<Args>, ctx: Types['Context']) => ExtractModel<Types, ParentShape>['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']]>;
|
|
@@ -125,6 +121,7 @@ export declare type PrismaConnectionFieldOptions<Types extends SchemaTypes, Pare
|
|
|
125
121
|
take: number;
|
|
126
122
|
skip: number;
|
|
127
123
|
}, parent: ParentShape, args: InputShapeFromFields<Args> & PothosSchemaTypes.DefaultConnectionArguments, context: Types['Context'], info: GraphQLResolveInfo) => MaybePromise<Model['Shape'][]>;
|
|
124
|
+
totalCount?: (parent: ParentShape, args: InputShapeFromFields<Args> & PothosSchemaTypes.DefaultConnectionArguments, context: Types['Context'], info: GraphQLResolveInfo) => MaybePromise<number>;
|
|
128
125
|
};
|
|
129
126
|
export declare type RelatedConnectionOptions<Types extends SchemaTypes, Model extends PrismaModelTypes, Field extends Model['ListRelations'], Nullable extends boolean, Args extends InputFieldMap, NeedsResolve extends boolean> = Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Model['Shape'], ObjectRef<unknown>, Nullable, Args, unknown>, 'resolve' | 'type'> & Omit<PothosSchemaTypes.ConnectionFieldOptions<Types, Model['Shape'], ObjectRef<unknown>, false, false, Nullable, Args, unknown>, 'resolve' | 'type'> & {
|
|
130
127
|
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
@@ -151,24 +148,24 @@ export declare type RelatedConnectionOptions<Types extends SchemaTypes, Model ex
|
|
|
151
148
|
export declare type WithBrand<T> = T & {
|
|
152
149
|
[typeBrandKey]: string;
|
|
153
150
|
};
|
|
154
|
-
export declare type IncludeMap = Record<string,
|
|
155
|
-
export interface
|
|
156
|
-
|
|
157
|
-
|
|
151
|
+
export declare type IncludeMap = Record<string, SelectionMap | boolean>;
|
|
152
|
+
export interface SelectionMap {
|
|
153
|
+
select?: Record<string, SelectionMap | boolean>;
|
|
154
|
+
include?: Record<string, SelectionMap | boolean>;
|
|
155
|
+
where?: {};
|
|
158
156
|
}
|
|
157
|
+
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
158
|
export declare type LoaderMappings = Record<string, {
|
|
160
159
|
field: string;
|
|
161
|
-
alias?: string;
|
|
162
160
|
mappings: LoaderMappings;
|
|
163
161
|
indirectPath: string[];
|
|
164
|
-
}
|
|
165
|
-
export interface
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
path: string[];
|
|
162
|
+
}>;
|
|
163
|
+
export interface IndirectInclude {
|
|
164
|
+
getType: () => string;
|
|
165
|
+
path: {
|
|
166
|
+
type?: string;
|
|
167
|
+
name: string;
|
|
168
|
+
}[];
|
|
172
169
|
}
|
|
173
170
|
export declare type ShapeFromConnection<T> = T extends {
|
|
174
171
|
shape: unknown;
|