@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
package/lib/index.js
CHANGED
|
@@ -26,7 +26,10 @@ exports.PrismaPlugin = void 0;
|
|
|
26
26
|
require("./global-types");
|
|
27
27
|
require("./field-builder");
|
|
28
28
|
require("./schema-builder");
|
|
29
|
+
const graphql_1 = require("graphql");
|
|
29
30
|
const core_1 = __importStar(require("@pothos/core"));
|
|
31
|
+
const loader_map_1 = require("./util/loader-map");
|
|
32
|
+
const map_query_1 = require("./util/map-query");
|
|
30
33
|
__exportStar(require("./types"), exports);
|
|
31
34
|
const pluginName = 'prisma';
|
|
32
35
|
exports.default = pluginName;
|
|
@@ -34,6 +37,48 @@ class PrismaPlugin extends core_1.BasePlugin {
|
|
|
34
37
|
constructor(cache) {
|
|
35
38
|
super(cache, pluginName);
|
|
36
39
|
}
|
|
40
|
+
onOutputFieldConfig(fieldConfig) {
|
|
41
|
+
if (fieldConfig.kind === 'PrismaObject' && fieldConfig.pothosOptions.select) {
|
|
42
|
+
return {
|
|
43
|
+
...fieldConfig,
|
|
44
|
+
extensions: {
|
|
45
|
+
...fieldConfig.extensions,
|
|
46
|
+
pothosPrismaSelect: fieldConfig.pothosOptions.select,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return fieldConfig;
|
|
51
|
+
}
|
|
52
|
+
wrapResolve(resolver, fieldConfig) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
if (fieldConfig.kind !== 'PrismaObject' || !((_a = fieldConfig.extensions) === null || _a === void 0 ? void 0 : _a.pothosPrismaSelect)) {
|
|
55
|
+
return resolver;
|
|
56
|
+
}
|
|
57
|
+
const parentConfig = this.buildCache.getTypeConfig(fieldConfig.parentType, 'Object');
|
|
58
|
+
const loadedCheck = fieldConfig.extensions.pothosPrismaLoaded;
|
|
59
|
+
const loaderCache = (_b = parentConfig.extensions) === null || _b === void 0 ? void 0 : _b.pothosPrismaLoader;
|
|
60
|
+
const fallback = fieldConfig.extensions.pothosPrismaFallback;
|
|
61
|
+
return (parent, args, context, info) => {
|
|
62
|
+
const mapping = (0, loader_map_1.getLoaderMapping)(context, info.path, info.parentType.name);
|
|
63
|
+
if ((!loadedCheck || loadedCheck(parent)) && mapping) {
|
|
64
|
+
(0, loader_map_1.setLoaderMappings)(context, info, mapping, (0, graphql_1.getNamedType)(info.returnType));
|
|
65
|
+
return resolver(parent, args, context, info);
|
|
66
|
+
}
|
|
67
|
+
if (fallback) {
|
|
68
|
+
return fallback((0, map_query_1.queryFromInfo)(context, info), parent, args, context, info);
|
|
69
|
+
}
|
|
70
|
+
const selectionState = (0, map_query_1.selectionStateFromInfo)(context, info);
|
|
71
|
+
return loaderCache(parent)
|
|
72
|
+
.loadSelection(selectionState, context)
|
|
73
|
+
.then((result) => {
|
|
74
|
+
const mappings = selectionState.mappings[info.path.key];
|
|
75
|
+
if (mappings) {
|
|
76
|
+
(0, loader_map_1.setLoaderMappings)(context, info, mappings.mappings, (0, graphql_1.getNamedType)(info.returnType));
|
|
77
|
+
}
|
|
78
|
+
return resolver(result, args, context, info);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
37
82
|
}
|
|
38
83
|
exports.PrismaPlugin = PrismaPlugin;
|
|
39
84
|
core_1.default.registerPlugin(pluginName, PrismaPlugin);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0BAAwB;AACxB,2BAAyB;AACzB,4BAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0BAAwB;AACxB,2BAAyB;AACzB,4BAA0B;AAC1B,qCAA6D;AAC7D,qDAKsB;AAEtB,kDAAwE;AACxE,gDAAyE;AAEzE,0CAAwB;AAExB,MAAM,UAAU,GAAG,QAAiB,CAAC;AAErC,kBAAe,UAAU,CAAC;AAE1B,MAAa,YAAwC,SAAQ,iBAAiB;IAC5E,YAAY,KAAwB;QAClC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAC3B,CAAC;IAEQ,mBAAmB,CAC1B,WAA2C;QAE3C,IAAI,WAAW,CAAC,IAAI,KAAK,cAAc,IAAI,WAAW,CAAC,aAAa,CAAC,MAAM,EAAE;YAC3E,OAAO;gBACL,GAAG,WAAW;gBACd,UAAU,EAAE;oBACV,GAAG,WAAW,CAAC,UAAU;oBACzB,kBAAkB,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM;iBACrD;aACF,CAAC;SACH;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAEQ,WAAW,CAClB,QAA0E,EAC1E,WAA2C;;QAE3C,IAAI,WAA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iBACtC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBACf,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAExD,IAAI,QAAQ,EAAE;oBACZ,IAAA,8BAAiB,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAA,sBAAY,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;iBACpF;gBAED,OAAO,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;IACJ,CAAC;CACF;AArED,oCAqEC;AAED,cAAa,CAAC,cAAc,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC"}
|
package/lib/model-loader.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { SchemaTypes } from '@pothos/core';
|
|
2
2
|
import { PrismaDelegate } from './types';
|
|
3
|
+
import { SelectionState } from './util/selections';
|
|
3
4
|
export declare class ModelLoader {
|
|
4
5
|
model: object;
|
|
5
6
|
delegate: PrismaDelegate;
|
|
6
7
|
findUnique: (args: unknown, ctx: {}) => unknown;
|
|
7
8
|
staged: Set<{
|
|
8
9
|
promise: Promise<Record<string, unknown>>;
|
|
9
|
-
|
|
10
|
+
state: SelectionState;
|
|
10
11
|
}>;
|
|
11
12
|
constructor(model: object, delegate: PrismaDelegate, findUnique: (args: unknown, ctx: {}) => unknown);
|
|
12
|
-
static
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
loadRelation(relation: string, include: unknown, context: {}): Promise<unknown>;
|
|
16
|
-
initLoad(relation: string | null, includeArg: unknown, context: {}, count?: boolean): Promise<Record<string, unknown>>;
|
|
13
|
+
static forRef<Types extends SchemaTypes>(modelName: string, findUnique: (args: unknown, ctx: {}) => unknown, builder: PothosSchemaTypes.SchemaBuilder<Types>): import("@pothos/core").ContextCache<ModelLoader, object, []>;
|
|
14
|
+
loadSelection(selection: SelectionState, context: object): Promise<Record<string, unknown>>;
|
|
15
|
+
initLoad(state: SelectionState, context: {}): Promise<Record<string, unknown>>;
|
|
17
16
|
}
|
|
18
17
|
//# sourceMappingURL=model-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAGL,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,WAAW;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,OAAO,CAAC;IAEhD,MAAM;iBACK,QAAQ,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;eAClC,cAAc;OAClB;gBAGH,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,OAAO;IAOjD,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,WAAW,EACrC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,OAAO,EAC/C,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC;IAO3C,aAAa,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM;IAcxD,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE;CAwBlD"}
|
package/lib/model-loader.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModelLoader = void 0;
|
|
4
|
-
/* eslint-disable prefer-destructuring */
|
|
5
|
-
/* eslint-disable no-underscore-dangle */
|
|
6
4
|
const core_1 = require("@pothos/core");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const loaderCache = new WeakMap();
|
|
5
|
+
const datamodel_1 = require("./util/datamodel");
|
|
6
|
+
const selections_1 = require("./util/selections");
|
|
10
7
|
class ModelLoader {
|
|
11
8
|
constructor(model, delegate, findUnique) {
|
|
12
9
|
this.staged = new Set();
|
|
@@ -14,88 +11,34 @@ class ModelLoader {
|
|
|
14
11
|
this.delegate = delegate;
|
|
15
12
|
this.findUnique = findUnique;
|
|
16
13
|
}
|
|
17
|
-
static
|
|
18
|
-
const delegate = (0,
|
|
19
|
-
|
|
20
|
-
const ref = (0, refs_1.getRefFromModel)(modelName, builder);
|
|
21
|
-
const findUnique = (0, refs_1.getFindUniqueForRef)(ref, builder);
|
|
22
|
-
loaderCache.set(delegate, (0, core_1.createContextCache)((model) => new ModelLoader(model, delegate, findUnique)));
|
|
23
|
-
}
|
|
24
|
-
return loaderCache.get(delegate);
|
|
25
|
-
}
|
|
26
|
-
async loadCount(relation, context) {
|
|
27
|
-
let promise;
|
|
28
|
-
const entry = [...this.staged][0];
|
|
29
|
-
if (entry) {
|
|
30
|
-
if (!entry.include._count) {
|
|
31
|
-
entry.include._count = { select: {} };
|
|
32
|
-
}
|
|
33
|
-
entry.include._count.select[relation] = true;
|
|
34
|
-
promise = entry.promise;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
promise = this.initLoad(relation, null, context, true);
|
|
38
|
-
}
|
|
39
|
-
const result = await promise;
|
|
40
|
-
return result._count[relation];
|
|
14
|
+
static forRef(modelName, findUnique, builder) {
|
|
15
|
+
const delegate = (0, datamodel_1.getDelegateFromModel)(builder.options.prisma.client, modelName);
|
|
16
|
+
return (0, core_1.createContextCache)((model) => new ModelLoader(model, delegate, findUnique));
|
|
41
17
|
}
|
|
42
|
-
async
|
|
18
|
+
async loadSelection(selection, context) {
|
|
19
|
+
const query = (0, selections_1.selectionToQuery)(selection);
|
|
43
20
|
for (const entry of this.staged) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
entry.include = merged;
|
|
21
|
+
if ((0, selections_1.selectionCompatible)(entry.state, query)) {
|
|
22
|
+
(0, selections_1.mergeSelection)(entry.state, query);
|
|
47
23
|
return entry.promise;
|
|
48
24
|
}
|
|
49
25
|
}
|
|
50
|
-
return this.initLoad(
|
|
51
|
-
}
|
|
52
|
-
async loadRelation(relation, include, context) {
|
|
53
|
-
let promise;
|
|
54
|
-
for (const entry of this.staged) {
|
|
55
|
-
if (entry.include[relation] === undefined) {
|
|
56
|
-
promise = entry.promise;
|
|
57
|
-
entry.include[relation] = include;
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
const merged = (0, util_1.mergeIncludes)(entry.include[relation], include);
|
|
61
|
-
if (merged) {
|
|
62
|
-
entry.include[relation] = merged;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (!promise) {
|
|
67
|
-
promise = this.initLoad(relation, include, context);
|
|
68
|
-
}
|
|
69
|
-
const result = await promise;
|
|
70
|
-
return result[relation];
|
|
26
|
+
return this.initLoad(selection, context);
|
|
71
27
|
}
|
|
72
|
-
async initLoad(
|
|
73
|
-
const include = (relation &&
|
|
74
|
-
(count
|
|
75
|
-
? {
|
|
76
|
-
_count: {
|
|
77
|
-
select: {
|
|
78
|
-
[relation]: true,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
: {
|
|
83
|
-
[relation]: includeArg,
|
|
84
|
-
})) ||
|
|
85
|
-
{};
|
|
28
|
+
async initLoad(state, context) {
|
|
86
29
|
const promise = new Promise((resolve, reject) => {
|
|
87
30
|
setTimeout(() => {
|
|
88
31
|
this.staged.delete(entry);
|
|
89
32
|
resolve(this.delegate.findUnique({
|
|
90
33
|
rejectOnNotFound: true,
|
|
34
|
+
...(0, selections_1.selectionToQuery)(state),
|
|
91
35
|
where: { ...this.findUnique(this.model, context) },
|
|
92
|
-
include: Object.keys(include).length > 0 ? include : undefined,
|
|
93
36
|
}));
|
|
94
37
|
}, 0);
|
|
95
38
|
});
|
|
96
39
|
const entry = {
|
|
97
40
|
promise,
|
|
98
|
-
|
|
41
|
+
state,
|
|
99
42
|
};
|
|
100
43
|
this.staged.add(entry);
|
|
101
44
|
return promise;
|
package/lib/model-loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-loader.js","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"model-loader.js","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":";;;AAAA,uCAA+D;AAE/D,gDAAwD;AACxD,kDAK2B;AAE3B,MAAa,WAAW;IAUtB,YACE,KAAa,EACb,QAAwB,EACxB,UAA+C;QARjD,WAAM,GAAG,IAAI,GAAG,EAGZ,CAAC;QAOH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,MAAM,CACX,SAAiB,EACjB,UAA+C,EAC/C,OAA+C;QAE/C,MAAM,QAAQ,GAAG,IAAA,gCAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAEhF,OAAO,IAAA,yBAAkB,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,KA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atibleTypes, FieldKind, FieldRef, InputFieldMap, NormalizeArgs, ObjectRef, PluginName, SchemaTypes, TypeParam } from '@pothos/core';
|
|
2
2
|
import { PrismaObjectRef } from './object-ref';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { PrismaModelTypes, RelatedConnectionOptions, RelatedFieldOptions, RelationCountOptions, ShapeFromConnection, VariantFieldOptions } from './types';
|
|
4
|
+
import { FieldMap } from './util/relation-map';
|
|
5
|
+
declare const RootBuilder: {
|
|
6
|
+
new <Types extends SchemaTypes, Shape, Kind extends FieldKind>(name: string, builder: PothosSchemaTypes.SchemaBuilder<Types>, kind: FieldKind, graphqlKind: PothosSchemaTypes.PothosKindToGraphQLType[FieldKind]): PothosSchemaTypes.RootFieldBuilder<Types, Shape, Kind>;
|
|
7
|
+
};
|
|
8
|
+
export declare class PrismaObjectFieldBuilder<Types extends SchemaTypes, Model extends PrismaModelTypes, NeedsResolve extends boolean, Shape extends object = Model['Shape']> extends RootBuilder<Types, Shape, 'PrismaObject'> {
|
|
7
9
|
model: string;
|
|
10
|
+
prismaFieldMap: FieldMap;
|
|
11
|
+
exposeBoolean: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], "Boolean", Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, "Boolean", Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").FieldNullability<"Boolean"> extends Nullable ? Types["DefaultFieldNullability"] extends true ? ("Boolean" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Boolean"] : never) | null | undefined : "Boolean" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Boolean"] : never : Nullable extends true ? ("Boolean" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Boolean"] : never) | null | undefined : "Boolean" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Boolean"] : never, "PrismaObject">;
|
|
12
|
+
exposeFloat: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], "Float", Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, "Float", Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").FieldNullability<"Float"> extends Nullable ? Types["DefaultFieldNullability"] extends true ? ("Float" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Float"] : never) | null | undefined : "Float" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Float"] : never : Nullable extends true ? ("Float" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Float"] : never) | null | undefined : "Float" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Float"] : never, "PrismaObject">;
|
|
13
|
+
exposeInt: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], "Int", Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, "Int", Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").FieldNullability<"Int"> extends Nullable ? Types["DefaultFieldNullability"] extends true ? ("Int" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Int"] : never) | null | undefined : "Int" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Int"] : never : Nullable extends true ? ("Int" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Int"] : never) | null | undefined : "Int" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "Int"] : never, "PrismaObject">;
|
|
14
|
+
exposeID: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], "ID", Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, "ID", Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").FieldNullability<"ID"> extends Nullable ? Types["DefaultFieldNullability"] extends true ? ("ID" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "ID"] : never) | null | undefined : "ID" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "ID"] : never : Nullable extends true ? ("ID" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "ID"] : never) | null | undefined : "ID" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "ID"] : never, "PrismaObject">;
|
|
15
|
+
exposeString: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], "String", Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, "String", Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").FieldNullability<"String"> extends Nullable ? Types["DefaultFieldNullability"] extends true ? ("String" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "String"] : never) | null | undefined : "String" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "String"] : never : Nullable extends true ? ("String" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "String"] : never) | null | undefined : "String" extends keyof Types["outputShapes"] ? Types["outputShapes"][keyof Types["outputShapes"] & "String"] : never, "PrismaObject">;
|
|
16
|
+
exposeBooleanList: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], ["Boolean"], Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, ["Boolean"], Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").ShapeFromTypeParam<Types, ["Boolean"], Nullable>, "PrismaObject">;
|
|
17
|
+
exposeFloatList: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], ["Float"], Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, ["Float"], Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").ShapeFromTypeParam<Types, ["Float"], Nullable>, "PrismaObject">;
|
|
18
|
+
exposeIntList: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], ["Int"], Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, ["Int"], Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").ShapeFromTypeParam<Types, ["Int"], Nullable>, "PrismaObject">;
|
|
19
|
+
exposeIDList: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], ["ID"], Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, ["ID"], Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").ShapeFromTypeParam<Types, ["ID"], Nullable>, "PrismaObject">;
|
|
20
|
+
exposeStringList: <Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model["Shape"], ["String"], Nullable>>(...args: NormalizeArgs<[name: Name, options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, ["String"], Nullable, {}, ResolveReturnShape>, "type" | "resolve" | "select"> | undefined]>) => FieldRef<import("@pothos/core").ShapeFromTypeParam<Types, ["String"], Nullable>, "PrismaObject">;
|
|
8
21
|
relatedConnection: 'relay' extends PluginName ? <Field extends Model['ListRelations'], Nullable extends boolean, Args extends InputFieldMap, ResolveReturnShape>(...args: NormalizeArgs<[
|
|
9
22
|
field: Field,
|
|
10
23
|
options: RelatedConnectionOptions<Types, Model, Field, Nullable, Args, NeedsResolve>,
|
|
11
24
|
connectionOptions?: PothosSchemaTypes.ConnectionObjectOptions<Types, ObjectRef<Shape>, false, false, ResolveReturnShape>,
|
|
12
25
|
edgeOptions?: PothosSchemaTypes.ConnectionEdgeObjectOptions<Types, ObjectRef<Shape>, false, ResolveReturnShape>
|
|
13
26
|
]>) => FieldRef<ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, Nullable>>> : '@pothos/plugin-relay is required to use this method';
|
|
14
|
-
constructor(name: string, builder: PothosSchemaTypes.SchemaBuilder<Types>, model: string);
|
|
27
|
+
constructor(name: string, builder: PothosSchemaTypes.SchemaBuilder<Types>, model: string, fieldMap: FieldMap);
|
|
15
28
|
relation<Field extends Model['Fields'], Nullable extends boolean, Args extends InputFieldMap, ResolveReturnShape>(...allArgs: NormalizeArgs<[
|
|
16
29
|
name: Field,
|
|
17
30
|
options?: RelatedFieldOptions<Types, Model, Field, Nullable, Args, ResolveReturnShape, NeedsResolve, Shape>
|
|
@@ -24,5 +37,11 @@ export declare class PrismaObjectFieldBuilder<Types extends SchemaTypes, Model e
|
|
|
24
37
|
variant: Variant,
|
|
25
38
|
options?: VariantFieldOptions<Types, Model, Variant extends PrismaObjectRef<Model> ? Variant : PrismaObjectRef<Model>>
|
|
26
39
|
]>): FieldRef<Model['Shape'], 'Object'>;
|
|
40
|
+
expose<Type extends TypeParam<Types>, Nullable extends boolean, ResolveReturnShape, Name extends CompatibleTypes<Types, Model['Shape'], Type, Nullable>>(...args: NormalizeArgs<[
|
|
41
|
+
name: Name,
|
|
42
|
+
options?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, Shape, Type, Nullable, {}, ResolveReturnShape>, 'resolve' | 'select'>
|
|
43
|
+
]>): FieldRef<import("@pothos/core").ShapeFromTypeParam<Types, Type, Nullable>, "PrismaObject">;
|
|
44
|
+
private createExpose;
|
|
27
45
|
}
|
|
46
|
+
export {};
|
|
28
47
|
//# sourceMappingURL=prisma-field-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-field-builder.d.ts","sourceRoot":"","sources":["../src/prisma-field-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,aAAa,EAEb,aAAa,EACb,
|
|
1
|
+
{"version":3,"file":"prisma-field-builder.d.ts","sourceRoot":"","sources":["../src/prisma-field-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,SAAS,EACT,QAAQ,EACR,aAAa,EAEb,aAAa,EACb,SAAS,EACT,UAAU,EAEV,WAAW,EACX,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAQjB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C,QAAA,MAAM,WAAW,EAAE;IAEjB,KAAK,KAAK,SAAS,WAAW,EAAE,KAAK,EAAE,IAAI,SAAS,SAAS,EAC3D,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC,EAC/C,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,iBAAiB,CAAC,uBAAuB,CAAC,SAAS,CAAC,GAChE,iBAAiB,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;CAC/B,CAAC;AAE9B,qBAAa,wBAAwB,CACnC,KAAK,SAAS,WAAW,EACzB,KAAK,SAAS,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AAC,EAAE,IAAI,EAAE,QAAQ,CAAC,EAEnE,GAAG,IAAI,EAAE,aAAa,CACpB;QACE,IAAI,EAAE,IAAI;QACV,OAAO,CAAC,EAAE,IAAI,CACZ,iBAAiB,CAAC,kBAAkB,CAClC,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,EAAE,EACF,kBAAkB,CACnB,EACD,SAAS,GAAG,QAAQ,CACrB;KACF,CACF;IAmBH,OAAO,CAAC,YAAY;CA+BrB"}
|
|
@@ -2,65 +2,69 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PrismaObjectFieldBuilder = void 0;
|
|
4
4
|
const core_1 = require("@pothos/core");
|
|
5
|
-
const cursors_1 = require("./cursors");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const cursors_1 = require("./util/cursors");
|
|
6
|
+
const datamodel_1 = require("./util/datamodel");
|
|
7
|
+
// Workaround for FieldKind not being extended on Builder classes
|
|
8
|
+
const RootBuilder = core_1.RootFieldBuilder;
|
|
9
|
+
class PrismaObjectFieldBuilder extends RootBuilder {
|
|
10
|
+
constructor(name, builder, model, fieldMap) {
|
|
11
|
+
super(name, builder, 'PrismaObject', 'Object');
|
|
12
|
+
this.exposeBoolean = this.createExpose('Boolean');
|
|
13
|
+
this.exposeFloat = this.createExpose('Float');
|
|
14
|
+
this.exposeInt = this.createExpose('Int');
|
|
15
|
+
this.exposeID = this.createExpose('ID');
|
|
16
|
+
this.exposeString = this.createExpose('String');
|
|
17
|
+
this.exposeBooleanList = this.createExpose(['Boolean']);
|
|
18
|
+
this.exposeFloatList = this.createExpose(['Float']);
|
|
19
|
+
this.exposeIntList = this.createExpose(['Int']);
|
|
20
|
+
this.exposeIDList = this.createExpose(['ID']);
|
|
21
|
+
this.exposeStringList = this.createExpose(['String']);
|
|
13
22
|
this.relatedConnection = function relatedConnection(name, { maxSize, defaultSize, cursor, query, resolve, extensions, totalCount, ...options }, connectionOptions = {}, edgeOptions = {}) {
|
|
14
23
|
var _a, _b;
|
|
15
|
-
const relationField = (0,
|
|
16
|
-
const
|
|
17
|
-
const ref = (_a = options.type) !== null && _a !== void 0 ? _a : (0, refs_1.getRefFromModel)(relationField.type, this.builder);
|
|
18
|
-
const findUnique = (0, refs_1.getFindUniqueForRef)(parentRef, this.builder);
|
|
19
|
-
const loaderCache = model_loader_1.ModelLoader.forModel(this.model, this.builder);
|
|
24
|
+
const relationField = (0, datamodel_1.getRelation)(this.model, this.builder, name);
|
|
25
|
+
const ref = (_a = options.type) !== null && _a !== void 0 ? _a : (0, datamodel_1.getRefFromModel)(relationField.type, this.builder);
|
|
20
26
|
let typeName;
|
|
27
|
+
const formatCursor = (0, datamodel_1.getCursorFormatter)(relationField.type, this.builder, cursor);
|
|
28
|
+
const parseCursor = (0, datamodel_1.getCursorParser)(relationField.type, this.builder, cursor);
|
|
21
29
|
const getQuery = (args, ctx) => ({
|
|
22
30
|
...(typeof query === 'function' ? query(args, ctx) : query),
|
|
23
31
|
...(0, cursors_1.prismaCursorConnectionQuery)({
|
|
24
|
-
|
|
32
|
+
parseCursor,
|
|
25
33
|
maxSize,
|
|
26
34
|
defaultSize,
|
|
27
35
|
args,
|
|
28
36
|
}),
|
|
29
37
|
});
|
|
38
|
+
const relationSelect = (args, context, nestedQuery) => ({
|
|
39
|
+
select: {
|
|
40
|
+
[name]: nestedQuery({
|
|
41
|
+
...(typeof query === 'function' ? query(args, context) : query),
|
|
42
|
+
...(0, cursors_1.prismaCursorConnectionQuery)({
|
|
43
|
+
parseCursor,
|
|
44
|
+
maxSize,
|
|
45
|
+
defaultSize,
|
|
46
|
+
args,
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
});
|
|
30
51
|
const fieldRef = this.connection({
|
|
31
52
|
...options,
|
|
32
53
|
extensions: {
|
|
33
54
|
...extensions,
|
|
34
|
-
|
|
35
|
-
|
|
55
|
+
pothosPrismaLoaded: (value) => value[name] !== undefined,
|
|
56
|
+
pothosPrismaFallback: resolve &&
|
|
57
|
+
((q, parent, args, context, info) => Promise.resolve(resolve({
|
|
58
|
+
...q,
|
|
59
|
+
...(typeof query === 'function' ? query(args, context) : query),
|
|
60
|
+
}, parent, args, context, info)).then((result) => (0, cursors_1.wrapConnectionResult)(result, args, q.take, formatCursor))),
|
|
36
61
|
},
|
|
37
62
|
type: ref,
|
|
38
|
-
|
|
63
|
+
select: relationSelect,
|
|
64
|
+
resolve: (parent, args, context) => {
|
|
39
65
|
var _a;
|
|
40
66
|
const connectionQuery = getQuery(args, context);
|
|
41
|
-
|
|
42
|
-
const mapping = (0, loader_map_1.getLoaderMapping)(context, info.path);
|
|
43
|
-
const loadedValue = parent[name];
|
|
44
|
-
if (
|
|
45
|
-
// if we attempted to load the relation, and its missing it will be null
|
|
46
|
-
// undefined means that the query was not constructed in a way that requested the relation
|
|
47
|
-
loadedValue !== undefined &&
|
|
48
|
-
mapping) {
|
|
49
|
-
if (loadedValue !== null && loadedValue !== undefined) {
|
|
50
|
-
(0, loader_map_1.setLoaderMappings)(context, info.path, mapping);
|
|
51
|
-
}
|
|
52
|
-
return loadedValue;
|
|
53
|
-
}
|
|
54
|
-
if (!resolve && !findUnique) {
|
|
55
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
56
|
-
}
|
|
57
|
-
const mergedQuery = { ...(0, util_1.queryFromInfo)(context, info), ...connectionQuery };
|
|
58
|
-
if (resolve) {
|
|
59
|
-
return resolve(mergedQuery, parent, args, context, info);
|
|
60
|
-
}
|
|
61
|
-
return loaderCache(parent).loadRelation(name, mergedQuery, context);
|
|
62
|
-
};
|
|
63
|
-
return (0, cursors_1.wrapConnectionResult)(await getResult(), args, connectionQuery.take, cursor, (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name]);
|
|
67
|
+
return (0, cursors_1.wrapConnectionResult)(parent[name], args, connectionQuery.take, formatCursor, (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name]);
|
|
64
68
|
},
|
|
65
69
|
}, {
|
|
66
70
|
...connectionOptions,
|
|
@@ -70,15 +74,9 @@ class PrismaObjectFieldBuilder extends core_1.ObjectFieldBuilder {
|
|
|
70
74
|
return ({
|
|
71
75
|
totalCount: t.int({
|
|
72
76
|
extensions: {
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
resolve: (parent, args, context) => {
|
|
76
|
-
const loadedValue = parent.totalCount;
|
|
77
|
-
if (loadedValue !== undefined) {
|
|
78
|
-
return loadedValue;
|
|
79
|
-
}
|
|
80
|
-
return loaderCache(parent).loadCount(name, context);
|
|
77
|
+
pothosPrismaParentSelect: { _count: { select: { [name]: true } } },
|
|
81
78
|
},
|
|
79
|
+
resolve: (parent, args, context) => parent.totalCount,
|
|
82
80
|
}),
|
|
83
81
|
...(_b = (_a = connectionOptions).fields) === null || _b === void 0 ? void 0 : _b.call(_a, t),
|
|
84
82
|
});
|
|
@@ -100,109 +98,80 @@ class PrismaObjectFieldBuilder extends core_1.ObjectFieldBuilder {
|
|
|
100
98
|
return fieldRef;
|
|
101
99
|
};
|
|
102
100
|
this.model = model;
|
|
103
|
-
this.
|
|
101
|
+
this.prismaFieldMap = fieldMap;
|
|
104
102
|
}
|
|
105
103
|
relation(...allArgs) {
|
|
106
104
|
var _a;
|
|
107
105
|
const [name, options = {}] = allArgs;
|
|
108
|
-
const relationField = (0,
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const loaderCache = model_loader_1.ModelLoader.forModel(this.model, this.builder);
|
|
113
|
-
const { query = {}, resolve, ...rest } = options;
|
|
106
|
+
const relationField = (0, datamodel_1.getRelation)(this.model, this.builder, name);
|
|
107
|
+
const ref = (_a = options.type) !== null && _a !== void 0 ? _a : (0, datamodel_1.getRefFromModel)(relationField.type, this.builder);
|
|
108
|
+
const { query = {}, resolve, extensions, ...rest } = options;
|
|
109
|
+
const relationSelect = (args, context, nestedQuery) => ({ select: { [name]: nestedQuery(query) } });
|
|
114
110
|
return this.field({
|
|
115
111
|
...rest,
|
|
116
112
|
type: relationField.isList ? [ref] : ref,
|
|
117
113
|
extensions: {
|
|
118
|
-
...
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
resolve: (parent, args, context, info) => {
|
|
123
|
-
const mapping = (0, loader_map_1.getLoaderMapping)(context, info.path);
|
|
124
|
-
const loadedValue = parent[name];
|
|
125
|
-
if (
|
|
126
|
-
// if we attempted to load the relation, and its missing it will be null
|
|
127
|
-
// undefined means that the query was not constructed in a way that requested the relation
|
|
128
|
-
loadedValue !== undefined &&
|
|
129
|
-
mapping) {
|
|
130
|
-
if (loadedValue !== null && loadedValue !== undefined) {
|
|
131
|
-
(0, loader_map_1.setLoaderMappings)(context, info.path, mapping);
|
|
132
|
-
}
|
|
133
|
-
return loadedValue;
|
|
134
|
-
}
|
|
135
|
-
const queryOptions = {
|
|
136
|
-
...(typeof query === 'function' ? query(args, context) : query),
|
|
137
|
-
...(0, util_1.queryFromInfo)(context, info),
|
|
138
|
-
};
|
|
139
|
-
if (resolve) {
|
|
140
|
-
return resolve(queryOptions, parent, args, context, info);
|
|
141
|
-
}
|
|
142
|
-
if (!findUnique) {
|
|
143
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
144
|
-
}
|
|
145
|
-
return loaderCache(parent).loadRelation(name, queryOptions, context);
|
|
114
|
+
...extensions,
|
|
115
|
+
pothosPrismaLoaded: (value) => value[name] !== undefined,
|
|
116
|
+
pothosPrismaFallback: resolve &&
|
|
117
|
+
((q, parent, args, context, info) => resolve({ ...q, ...(typeof query === 'function' ? query(args, context) : query) }, parent, args, context, info)),
|
|
146
118
|
},
|
|
119
|
+
select: relationSelect,
|
|
120
|
+
resolve: (parent) => parent[name],
|
|
147
121
|
});
|
|
148
122
|
}
|
|
149
123
|
relationCount(...allArgs) {
|
|
150
124
|
const [name, options = {}] = allArgs;
|
|
151
|
-
const parentRef = (0, refs_1.getRefFromModel)(this.model, this.builder);
|
|
152
|
-
const findUnique = (0, refs_1.getFindUniqueForRef)(parentRef, this.builder);
|
|
153
|
-
const loaderCache = model_loader_1.ModelLoader.forModel(this.model, this.builder);
|
|
154
125
|
const { resolve, ...rest } = options;
|
|
126
|
+
const countSelect = {
|
|
127
|
+
_count: {
|
|
128
|
+
select: { [name]: true },
|
|
129
|
+
},
|
|
130
|
+
};
|
|
155
131
|
return this.field({
|
|
156
132
|
...rest,
|
|
157
133
|
type: 'Int',
|
|
158
134
|
nullable: false,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
pothosPrismaRelationCount: name,
|
|
162
|
-
},
|
|
163
|
-
resolve: (parent, args, context, info) => {
|
|
164
|
-
var _a;
|
|
165
|
-
const loadedValue = (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name];
|
|
166
|
-
if (loadedValue !== undefined) {
|
|
167
|
-
return loadedValue;
|
|
168
|
-
}
|
|
169
|
-
if (resolve) {
|
|
170
|
-
return resolve(parent, args, context, info);
|
|
171
|
-
}
|
|
172
|
-
if (!findUnique) {
|
|
173
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
174
|
-
}
|
|
175
|
-
return loaderCache(parent).loadCount(name, context);
|
|
176
|
-
},
|
|
135
|
+
select: countSelect,
|
|
136
|
+
resolve: (parent, args, context, info) => { var _a; return (_a = parent._count) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
177
137
|
});
|
|
178
138
|
}
|
|
179
139
|
variant(...allArgs) {
|
|
180
140
|
const [variant, options = {}] = allArgs;
|
|
181
|
-
const ref = typeof variant === 'string' ? (0,
|
|
182
|
-
const
|
|
183
|
-
const findUnique = (0, refs_1.getFindUniqueForRef)(parentRef, this.builder);
|
|
184
|
-
const loaderCache = model_loader_1.ModelLoader.forModel(this.model, this.builder);
|
|
141
|
+
const ref = typeof variant === 'string' ? (0, datamodel_1.getRefFromModel)(variant, this.builder) : variant;
|
|
142
|
+
const selfSelect = (args, context, nestedQuery) => nestedQuery({});
|
|
185
143
|
return this.field({
|
|
186
144
|
...options,
|
|
187
145
|
type: ref,
|
|
146
|
+
select: selfSelect,
|
|
147
|
+
resolve: (parent, args, context, info) => parent,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
expose(...args) {
|
|
151
|
+
var _a;
|
|
152
|
+
const [name, options = {}] = args;
|
|
153
|
+
const typeConfig = this.builder.configStore.getTypeConfig(this.typename, 'Object');
|
|
154
|
+
const usingSelect = !!((_a = typeConfig.extensions) === null || _a === void 0 ? void 0 : _a.pothosPrismaSelect);
|
|
155
|
+
return this.exposeField(name, {
|
|
156
|
+
...options,
|
|
188
157
|
extensions: {
|
|
189
158
|
...options.extensions,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (mapping) {
|
|
195
|
-
(0, loader_map_1.setLoaderMappings)(context, info.path, mapping);
|
|
196
|
-
return parent;
|
|
197
|
-
}
|
|
198
|
-
const queryOptions = (0, util_1.queryFromInfo)(context, info);
|
|
199
|
-
if (!findUnique) {
|
|
200
|
-
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
201
|
-
}
|
|
202
|
-
return loaderCache(parent).loadSelf(queryOptions, context);
|
|
159
|
+
pothosPrismaVariant: name,
|
|
160
|
+
pothosPrismaSelect: usingSelect && {
|
|
161
|
+
[name]: true,
|
|
162
|
+
},
|
|
203
163
|
},
|
|
204
164
|
});
|
|
205
165
|
}
|
|
166
|
+
createExpose(type) {
|
|
167
|
+
return (...args) => {
|
|
168
|
+
const [name, options = {}] = args;
|
|
169
|
+
return this.expose(name, {
|
|
170
|
+
...options,
|
|
171
|
+
type,
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
}
|
|
206
175
|
}
|
|
207
176
|
exports.PrismaObjectFieldBuilder = PrismaObjectFieldBuilder;
|
|
208
177
|
//# sourceMappingURL=prisma-field-builder.js.map
|