@pothos/plugin-prisma 0.15.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/.turbo/turbo-test.log +8 -7
- package/.turbo/turbo-type.log +2 -2
- package/CHANGELOG.md +24 -0
- package/esm/field-builder.d.ts.map +1 -1
- package/esm/field-builder.js +5 -3
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +2 -1
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts +12 -12
- package/esm/global-types.d.ts.map +1 -1
- package/esm/model-loader.d.ts +2 -1
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +23 -11
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +4 -2
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/node-ref.js +3 -2
- package/esm/node-ref.js.map +1 -1
- package/esm/object-ref.d.ts +7 -0
- package/esm/object-ref.d.ts.map +1 -0
- package/esm/object-ref.js +5 -0
- package/esm/object-ref.js.map +1 -0
- package/esm/prisma-field-builder.d.ts +10 -4
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +33 -7
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/refs.d.ts +5 -3
- package/esm/refs.d.ts.map +1 -1
- package/esm/refs.js +2 -1
- package/esm/refs.js.map +1 -1
- package/esm/schema-builder.js +8 -11
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +19 -6
- package/esm/types.d.ts.map +1 -1
- package/esm/util/map-includes.d.ts +1 -0
- package/esm/util/map-includes.d.ts.map +1 -1
- package/esm/util/map-includes.js +23 -7
- package/esm/util/map-includes.js.map +1 -1
- package/lib/field-builder.d.ts.map +1 -1
- package/lib/field-builder.js +5 -3
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +2 -1
- package/lib/generator.js.map +1 -1
- package/lib/global-types.d.ts +12 -12
- package/lib/global-types.d.ts.map +1 -1
- package/lib/model-loader.d.ts +2 -1
- package/lib/model-loader.d.ts.map +1 -1
- package/lib/model-loader.js +23 -11
- package/lib/model-loader.js.map +1 -1
- package/lib/node-ref.d.ts +4 -2
- package/lib/node-ref.d.ts.map +1 -1
- package/lib/node-ref.js +2 -1
- package/lib/node-ref.js.map +1 -1
- package/lib/object-ref.d.ts +7 -0
- package/lib/object-ref.d.ts.map +1 -0
- package/lib/object-ref.js +9 -0
- package/lib/object-ref.js.map +1 -0
- package/lib/prisma-field-builder.d.ts +10 -4
- package/lib/prisma-field-builder.d.ts.map +1 -1
- package/lib/prisma-field-builder.js +32 -6
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/refs.d.ts +5 -3
- package/lib/refs.d.ts.map +1 -1
- package/lib/refs.js +2 -1
- package/lib/refs.js.map +1 -1
- package/lib/schema-builder.js +8 -11
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.d.ts +19 -6
- package/lib/types.d.ts.map +1 -1
- package/lib/util/map-includes.d.ts +1 -0
- package/lib/util/map-includes.d.ts.map +1 -1
- package/lib/util/map-includes.js +24 -8
- package/lib/util/map-includes.js.map +1 -1
- package/package.json +10 -10
- package/src/field-builder.ts +7 -5
- package/src/generator.ts +8 -1
- package/src/global-types.ts +28 -11
- package/src/model-loader.ts +30 -13
- package/src/node-ref.ts +7 -2
- package/src/object-ref.ts +8 -0
- package/src/prisma-field-builder.ts +59 -8
- package/src/refs.ts +5 -3
- package/src/schema-builder.ts +5 -7
- package/src/types.ts +69 -35
- package/src/util/map-includes.ts +35 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/generated.ts +0 -54
package/lib/util/map-includes.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queryFromInfo = exports.includesFromSelectionSet = void 0;
|
|
3
|
+
exports.queryFromInfo = exports.includesFromSelectionSet = exports.SELF_RELATION = void 0;
|
|
4
4
|
/* eslint-disable no-underscore-dangle */
|
|
5
5
|
/* eslint-disable no-param-reassign */
|
|
6
6
|
/* eslint-disable no-continue */
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
8
7
|
const graphql_1 = require("graphql");
|
|
9
8
|
const values_1 = require("graphql/execution/values");
|
|
10
9
|
const loader_map_1 = require("../loader-map");
|
|
11
10
|
const _1 = require(".");
|
|
11
|
+
exports.SELF_RELATION = '@self';
|
|
12
12
|
function handleField(ctx, info, fields, selection, includes, counts, mappings, indirectMap) {
|
|
13
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
14
14
|
if (selection.name.value.startsWith('__')) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -56,7 +56,7 @@ function handleField(ctx, info, fields, selection, includes, counts, mappings, i
|
|
|
56
56
|
const args = (0, values_1.getArgumentValues)(field, selection, info.variableValues);
|
|
57
57
|
query = query(args, ctx);
|
|
58
58
|
}
|
|
59
|
-
const existingInclude = includes[relationName];
|
|
59
|
+
const existingInclude = relationName === exports.SELF_RELATION ? { include: includes } : includes[relationName];
|
|
60
60
|
query = { ...query, include: newIncludes };
|
|
61
61
|
if (typeof existingInclude === 'object') {
|
|
62
62
|
query = (0, _1.mergeIncludes)(existingInclude, query);
|
|
@@ -64,20 +64,36 @@ function handleField(ctx, info, fields, selection, includes, counts, mappings, i
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
if (!mappings[relationName]) {
|
|
68
|
+
mappings[relationName] = [];
|
|
69
|
+
}
|
|
67
70
|
const nestedIncludes = query.include;
|
|
68
71
|
const nestedMappings = {};
|
|
69
72
|
const nestedCounts = {
|
|
70
73
|
current: {},
|
|
71
74
|
parent: counts.current,
|
|
72
75
|
};
|
|
73
|
-
if (
|
|
74
|
-
mappings[relationName]
|
|
76
|
+
if (relationName === exports.SELF_RELATION) {
|
|
77
|
+
mappings[relationName].push({
|
|
78
|
+
field: selection.name.value,
|
|
79
|
+
alias: (_j = selection.alias) === null || _j === void 0 ? void 0 : _j.value,
|
|
80
|
+
mappings: nestedMappings,
|
|
81
|
+
indirectPath: (_k = indirectMap === null || indirectMap === void 0 ? void 0 : indirectMap.path) !== null && _k !== void 0 ? _k : [],
|
|
82
|
+
});
|
|
83
|
+
const { include } = query;
|
|
84
|
+
if (selection.selectionSet) {
|
|
85
|
+
includesFromSelectionSet(ctx, type, info, includes, counts, nestedMappings, selection.selectionSet);
|
|
86
|
+
}
|
|
87
|
+
Object.keys(include).forEach((key) => {
|
|
88
|
+
includes[key] = include[key];
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
75
91
|
}
|
|
76
92
|
mappings[relationName].push({
|
|
77
93
|
field: selection.name.value,
|
|
78
|
-
alias: (
|
|
94
|
+
alias: (_l = selection.alias) === null || _l === void 0 ? void 0 : _l.value,
|
|
79
95
|
mappings: nestedMappings,
|
|
80
|
-
indirectPath: (
|
|
96
|
+
indirectPath: (_m = indirectMap === null || indirectMap === void 0 ? void 0 : indirectMap.path) !== null && _m !== void 0 ? _m : [],
|
|
81
97
|
});
|
|
82
98
|
if (selection.selectionSet) {
|
|
83
99
|
includesFromSelectionSet(ctx, type, info, nestedIncludes, nestedCounts, nestedMappings, selection.selectionSet);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-includes.js","sourceRoot":"","sources":["../../src/util/map-includes.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,sCAAsC;AACtC,gCAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"map-includes.js","sourceRoot":"","sources":["../../src/util/map-includes.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,sCAAsC;AACtC,gCAAgC;AAChC,qCAQiB;AACjB,qDAA6D;AAC7D,8CAAkD;AAQlD,wBAAuD;AAE1C,QAAA,aAAa,GAAG,OAAO,C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AAC;IAEF,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE;QAC7B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,SAAS;SACV;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAA,sBAAY,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE3F,wBAAwB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;KAC1F;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1C,QAAQ,CAAC,MAAM,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;KAC9C;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QACpC,IAAI,QAAQ,EAAE;YACZ,IAAA,8BAAiB,EAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SAC7C;QAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;KAC9B;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AArCD,sCAqCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pothos/plugin-prisma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"description": "A Pothos plugin for more efficient integration with prisma",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@prisma/generator-helper": "^3.
|
|
39
|
+
"@prisma/generator-helper": "^3.9.1"
|
|
40
40
|
},
|
|
41
41
|
"prisma": {
|
|
42
42
|
"seed": "pnpm ts-node prisma/seed.ts"
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"typescript": ">4.5.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@pothos/core": "
|
|
51
|
-
"@pothos/plugin-errors": "
|
|
52
|
-
"@pothos/plugin-relay": "
|
|
53
|
-
"@pothos/plugin-scope-auth": "
|
|
54
|
-
"@pothos/test-utils": "
|
|
55
|
-
"@prisma/client": "^3.
|
|
56
|
-
"graphql": "16.
|
|
50
|
+
"@pothos/core": "3.1.2",
|
|
51
|
+
"@pothos/plugin-errors": "3.0.1",
|
|
52
|
+
"@pothos/plugin-relay": "3.3.1",
|
|
53
|
+
"@pothos/plugin-scope-auth": "3.0.2",
|
|
54
|
+
"@pothos/test-utils": "1.0.1",
|
|
55
|
+
"@prisma/client": "^3.9.1",
|
|
56
|
+
"graphql": "16.3.0",
|
|
57
57
|
"graphql-tag": "^2.12.6",
|
|
58
|
-
"prisma": "^3.
|
|
58
|
+
"prisma": "^3.9.1"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"generate": "prisma generate",
|
package/src/field-builder.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
ObjectRef,
|
|
7
7
|
RootFieldBuilder,
|
|
8
8
|
SchemaTypes,
|
|
9
|
-
TypeParam,
|
|
10
9
|
} from '@pothos/core';
|
|
11
10
|
import { resolvePrismaCursorConnection } from './cursors';
|
|
12
11
|
import { getRefFromModel } from './refs';
|
|
@@ -22,9 +21,12 @@ const fieldBuilderProto = RootFieldBuilder.prototype as PothosSchemaTypes.RootFi
|
|
|
22
21
|
>;
|
|
23
22
|
|
|
24
23
|
fieldBuilderProto.prismaField = function prismaField({ type, resolve, ...options }) {
|
|
25
|
-
const
|
|
26
|
-
const typeRef =
|
|
27
|
-
|
|
24
|
+
const modelOrRef = Array.isArray(type) ? type[0] : type;
|
|
25
|
+
const typeRef =
|
|
26
|
+
typeof modelOrRef === 'string'
|
|
27
|
+
? getRefFromModel(modelOrRef, this.builder)
|
|
28
|
+
: (modelOrRef as ObjectRef<unknown>);
|
|
29
|
+
const typeParam = Array.isArray(type) ? ([typeRef] as [ObjectRef<unknown>]) : typeRef;
|
|
28
30
|
|
|
29
31
|
return this.field({
|
|
30
32
|
...options,
|
|
@@ -66,7 +68,7 @@ fieldBuilderProto.prismaConnection = function prismaConnection<
|
|
|
66
68
|
connectionOptions: {},
|
|
67
69
|
edgeOptions: {},
|
|
68
70
|
) {
|
|
69
|
-
const ref = getRefFromModel(type, this.builder);
|
|
71
|
+
const ref = typeof type === 'string' ? getRefFromModel(type, this.builder) : type;
|
|
70
72
|
let typeName: string | undefined;
|
|
71
73
|
|
|
72
74
|
const fieldRef = (
|
package/src/generator.ts
CHANGED
|
@@ -45,7 +45,14 @@ generatorHandler({
|
|
|
45
45
|
[],
|
|
46
46
|
model.name,
|
|
47
47
|
undefined,
|
|
48
|
+
|
|
48
49
|
ts.factory.createTypeLiteralNode([
|
|
50
|
+
ts.factory.createPropertySignature(
|
|
51
|
+
[],
|
|
52
|
+
'Name',
|
|
53
|
+
undefined,
|
|
54
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(model.name)),
|
|
55
|
+
),
|
|
49
56
|
ts.factory.createPropertySignature(
|
|
50
57
|
[],
|
|
51
58
|
'Shape',
|
|
@@ -96,7 +103,7 @@ generatorHandler({
|
|
|
96
103
|
undefined,
|
|
97
104
|
ts.factory.createTypeLiteralNode(
|
|
98
105
|
relations.map((field) => {
|
|
99
|
-
const typeName =
|
|
106
|
+
const typeName = field.type;
|
|
100
107
|
|
|
101
108
|
return ts.factory.createPropertySignature(
|
|
102
109
|
[],
|
package/src/global-types.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
ShapeFromTypeParam,
|
|
14
14
|
} from '@pothos/core';
|
|
15
15
|
import PrismaNodeRef from './node-ref';
|
|
16
|
+
import { prismaModelKey, PrismaObjectRef } from './object-ref';
|
|
16
17
|
import {
|
|
17
18
|
PrismaConnectionFieldOptions,
|
|
18
19
|
PrismaFieldOptions,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
PrismaObjectTypeOptions,
|
|
22
23
|
ShapeWithInclude,
|
|
23
24
|
} from './types';
|
|
24
|
-
import { PrismaPlugin } from '.';
|
|
25
|
+
import { PrismaPlugin, ShapeFromConnection } from '.';
|
|
25
26
|
|
|
26
27
|
declare global {
|
|
27
28
|
export namespace PothosSchemaTypes {
|
|
@@ -58,7 +59,7 @@ declare global {
|
|
|
58
59
|
>(
|
|
59
60
|
name: Name,
|
|
60
61
|
options: PrismaObjectTypeOptions<Types, Model, Interfaces, FindUnique, Include, Shape>,
|
|
61
|
-
) =>
|
|
62
|
+
) => PrismaObjectRef<Model, Shape>;
|
|
62
63
|
|
|
63
64
|
prismaNode: 'relay' extends PluginName
|
|
64
65
|
? <
|
|
@@ -70,7 +71,7 @@ declare global {
|
|
|
70
71
|
>(
|
|
71
72
|
name: Name,
|
|
72
73
|
options: PrismaNodeOptions<Types, Model, Interfaces, Include, Shape>,
|
|
73
|
-
) => PrismaNodeRef<Shape>
|
|
74
|
+
) => PrismaNodeRef<Model, Shape>
|
|
74
75
|
: '@pothos/plugin-relay is required to use this method';
|
|
75
76
|
}
|
|
76
77
|
|
|
@@ -81,15 +82,23 @@ declare global {
|
|
|
81
82
|
> {
|
|
82
83
|
prismaField: <
|
|
83
84
|
Args extends InputFieldMap,
|
|
84
|
-
TypeParam extends
|
|
85
|
+
TypeParam extends
|
|
86
|
+
| PrismaObjectRef<PrismaModelTypes>
|
|
87
|
+
| keyof Types['PrismaTypes']
|
|
88
|
+
| [keyof Types['PrismaTypes']]
|
|
89
|
+
| [PrismaObjectRef<PrismaModelTypes>],
|
|
85
90
|
Nullable extends FieldNullability<Type>,
|
|
86
91
|
ResolveReturnShape,
|
|
87
|
-
Type extends TypeParam extends [
|
|
92
|
+
Type extends TypeParam extends [unknown]
|
|
88
93
|
? [ObjectRef<Model['Shape']>]
|
|
89
94
|
: ObjectRef<Model['Shape']>,
|
|
90
95
|
Model extends PrismaModelTypes = PrismaModelTypes &
|
|
91
96
|
(TypeParam extends [keyof Types['PrismaTypes']]
|
|
92
97
|
? Types['PrismaTypes'][TypeParam[0]]
|
|
98
|
+
: TypeParam extends [PrismaObjectRef<PrismaModelTypes>]
|
|
99
|
+
? TypeParam[0][typeof prismaModelKey]
|
|
100
|
+
: TypeParam extends PrismaObjectRef<PrismaModelTypes>
|
|
101
|
+
? TypeParam[typeof prismaModelKey]
|
|
93
102
|
: TypeParam extends keyof Types['PrismaTypes']
|
|
94
103
|
? Types['PrismaTypes'][TypeParam]
|
|
95
104
|
: never),
|
|
@@ -109,11 +118,13 @@ declare global {
|
|
|
109
118
|
|
|
110
119
|
prismaConnection: 'relay' extends PluginName
|
|
111
120
|
? <
|
|
112
|
-
Type extends keyof Types['PrismaTypes'],
|
|
121
|
+
Type extends PrismaObjectRef<PrismaModelTypes> | keyof Types['PrismaTypes'],
|
|
113
122
|
Nullable extends boolean,
|
|
114
123
|
ResolveReturnShape,
|
|
115
124
|
Args extends InputFieldMap = {},
|
|
116
|
-
Model extends PrismaModelTypes =
|
|
125
|
+
Model extends PrismaModelTypes = Type extends PrismaObjectRef<infer T>
|
|
126
|
+
? T
|
|
127
|
+
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
|
|
117
128
|
>(
|
|
118
129
|
...args: NormalizeArgs<
|
|
119
130
|
[
|
|
@@ -131,16 +142,19 @@ declare global {
|
|
|
131
142
|
connectionOptions?: ConnectionObjectOptions<
|
|
132
143
|
Types,
|
|
133
144
|
ObjectRef<Model['Shape']>,
|
|
145
|
+
false,
|
|
146
|
+
false,
|
|
134
147
|
ResolveReturnShape
|
|
135
148
|
>,
|
|
136
149
|
edgeOptions?: ConnectionEdgeObjectOptions<
|
|
137
150
|
Types,
|
|
138
151
|
ObjectRef<Model['Shape']>,
|
|
152
|
+
false,
|
|
139
153
|
ResolveReturnShape
|
|
140
154
|
>,
|
|
141
155
|
]
|
|
142
156
|
>
|
|
143
|
-
) => FieldRef<ConnectionShapeHelper<Types, Model['Shape'], Nullable
|
|
157
|
+
) => FieldRef<ShapeFromConnection<ConnectionShapeHelper<Types, Model['Shape'], Nullable>>>
|
|
144
158
|
: '@pothos/plugin-relay is required to use this method';
|
|
145
159
|
}
|
|
146
160
|
|
|
@@ -149,6 +163,8 @@ declare global {
|
|
|
149
163
|
ParentShape,
|
|
150
164
|
Type extends OutputType<Types>,
|
|
151
165
|
Nullable extends boolean,
|
|
166
|
+
EdgeNullability extends FieldNullability<[unknown]>,
|
|
167
|
+
NodeNullability extends boolean,
|
|
152
168
|
Args extends InputFieldMap,
|
|
153
169
|
ResolveReturnShape,
|
|
154
170
|
> {}
|
|
@@ -156,12 +172,15 @@ declare global {
|
|
|
156
172
|
export interface ConnectionObjectOptions<
|
|
157
173
|
Types extends SchemaTypes,
|
|
158
174
|
Type extends OutputType<Types>,
|
|
175
|
+
EdgeNullability extends FieldNullability<[unknown]>,
|
|
176
|
+
NodeNullability extends boolean,
|
|
159
177
|
Resolved,
|
|
160
178
|
> {}
|
|
161
179
|
|
|
162
180
|
export interface ConnectionEdgeObjectOptions<
|
|
163
181
|
Types extends SchemaTypes,
|
|
164
182
|
Type extends OutputType<Types>,
|
|
183
|
+
NodeNullability extends boolean,
|
|
165
184
|
Resolved,
|
|
166
185
|
> {}
|
|
167
186
|
|
|
@@ -172,8 +191,6 @@ declare global {
|
|
|
172
191
|
after?: string | null | undefined;
|
|
173
192
|
}
|
|
174
193
|
|
|
175
|
-
export interface ConnectionShapeHelper<Types extends SchemaTypes, T, Nullable> {
|
|
176
|
-
shape: unknown;
|
|
177
|
-
}
|
|
194
|
+
export interface ConnectionShapeHelper<Types extends SchemaTypes, T, Nullable> {}
|
|
178
195
|
}
|
|
179
196
|
}
|
package/src/model-loader.ts
CHANGED
|
@@ -66,6 +66,20 @@ export class ModelLoader {
|
|
|
66
66
|
return (result._count as Record<string, number>)[relation];
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
async loadSelf(include: unknown, context: {}) {
|
|
70
|
+
for (const entry of this.staged) {
|
|
71
|
+
const merged = mergeIncludes(entry.include, include as Record<string, unknown>);
|
|
72
|
+
|
|
73
|
+
if (merged) {
|
|
74
|
+
entry.include = merged as Record<string, unknown>;
|
|
75
|
+
|
|
76
|
+
return entry.promise;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return this.initLoad(null, include, context);
|
|
81
|
+
}
|
|
82
|
+
|
|
69
83
|
async loadRelation(relation: string, include: unknown, context: {}) {
|
|
70
84
|
let promise;
|
|
71
85
|
for (const entry of this.staged) {
|
|
@@ -96,18 +110,21 @@ export class ModelLoader {
|
|
|
96
110
|
return result[relation];
|
|
97
111
|
}
|
|
98
112
|
|
|
99
|
-
async initLoad(relation: string, includeArg: unknown, context: {}, count = false) {
|
|
100
|
-
const include: Record<string, unknown> =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
async initLoad(relation: string | null, includeArg: unknown, context: {}, count = false) {
|
|
114
|
+
const include: Record<string, unknown> =
|
|
115
|
+
(relation &&
|
|
116
|
+
(count
|
|
117
|
+
? {
|
|
118
|
+
_count: {
|
|
119
|
+
select: {
|
|
120
|
+
[relation]: true,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
: {
|
|
125
|
+
[relation]: includeArg,
|
|
126
|
+
})) ||
|
|
127
|
+
{};
|
|
111
128
|
|
|
112
129
|
const promise = new Promise<Record<string, unknown>>((resolve, reject) => {
|
|
113
130
|
setTimeout(() => {
|
|
@@ -117,7 +134,7 @@ export class ModelLoader {
|
|
|
117
134
|
this.delegate.findUnique({
|
|
118
135
|
rejectOnNotFound: true,
|
|
119
136
|
where: { ...(this.findUnique(this.model, context) as {}) },
|
|
120
|
-
include,
|
|
137
|
+
include: Object.keys(include).length > 0 ? include : undefined,
|
|
121
138
|
} as never) as Promise<Record<string, unknown>>,
|
|
122
139
|
);
|
|
123
140
|
}, 0);
|
package/src/node-ref.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { abstractReturnShapeKey, brandWithType,
|
|
1
|
+
import { abstractReturnShapeKey, brandWithType, typeBrandKey } from '@pothos/core';
|
|
2
|
+
import { PrismaObjectRef } from './object-ref';
|
|
2
3
|
import { WithBrand } from './types';
|
|
4
|
+
import { PrismaModelTypes } from '.';
|
|
3
5
|
|
|
4
|
-
export default class PrismaNodeRef<
|
|
6
|
+
export default class PrismaNodeRef<Model extends PrismaModelTypes, T> extends PrismaObjectRef<
|
|
7
|
+
Model,
|
|
8
|
+
T
|
|
9
|
+
> {
|
|
5
10
|
[abstractReturnShapeKey]: WithBrand<T>;
|
|
6
11
|
|
|
7
12
|
addBrand<V extends T | T[]>(
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ObjectRef } from '@pothos/core';
|
|
2
|
+
import { PrismaModelTypes } from '.';
|
|
3
|
+
|
|
4
|
+
export const prismaModelKey = Symbol.for('Pothos.prismaModelKey');
|
|
5
|
+
|
|
6
|
+
export class PrismaObjectRef<Model extends PrismaModelTypes, T = {}> extends ObjectRef<T> {
|
|
7
|
+
[prismaModelKey]: Model;
|
|
8
|
+
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { prismaCursorConnectionQuery, wrapConnectionResult } from './cursors';
|
|
14
14
|
import { getLoaderMapping, setLoaderMappings } from './loader-map';
|
|
15
15
|
import { ModelLoader } from './model-loader';
|
|
16
|
+
import { PrismaObjectRef } from './object-ref';
|
|
16
17
|
import { getDelegateFromModel, getFindUniqueForRef, getRefFromModel, getRelation } from './refs';
|
|
17
18
|
import {
|
|
18
19
|
PrismaDelegate,
|
|
@@ -20,8 +21,10 @@ import {
|
|
|
20
21
|
RelatedConnectionOptions,
|
|
21
22
|
RelatedFieldOptions,
|
|
22
23
|
RelationCountOptions,
|
|
24
|
+
ShapeFromConnection,
|
|
23
25
|
} from './types';
|
|
24
|
-
import { queryFromInfo } from './util';
|
|
26
|
+
import { queryFromInfo, SELF_RELATION } from './util';
|
|
27
|
+
import { VariantFieldOptions } from '.';
|
|
25
28
|
|
|
26
29
|
export class PrismaObjectFieldBuilder<
|
|
27
30
|
Types extends SchemaTypes,
|
|
@@ -46,16 +49,21 @@ export class PrismaObjectFieldBuilder<
|
|
|
46
49
|
connectionOptions?: PothosSchemaTypes.ConnectionObjectOptions<
|
|
47
50
|
Types,
|
|
48
51
|
ObjectRef<Shape>,
|
|
52
|
+
false,
|
|
53
|
+
false,
|
|
49
54
|
ResolveReturnShape
|
|
50
55
|
>,
|
|
51
56
|
edgeOptions?: PothosSchemaTypes.ConnectionEdgeObjectOptions<
|
|
52
57
|
Types,
|
|
53
58
|
ObjectRef<Shape>,
|
|
59
|
+
false,
|
|
54
60
|
ResolveReturnShape
|
|
55
61
|
>,
|
|
56
62
|
]
|
|
57
63
|
>
|
|
58
|
-
) => FieldRef<
|
|
64
|
+
) => FieldRef<
|
|
65
|
+
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, Nullable>>
|
|
66
|
+
>
|
|
59
67
|
: '@pothos/plugin-relay is required to use this method' = function relatedConnection(
|
|
60
68
|
this: PrismaObjectFieldBuilder<SchemaTypes, Model, boolean>,
|
|
61
69
|
name: string,
|
|
@@ -69,6 +77,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
69
77
|
totalCount,
|
|
70
78
|
...options
|
|
71
79
|
}: {
|
|
80
|
+
type?: ObjectRef<unknown, unknown>;
|
|
72
81
|
totalCount?: boolean;
|
|
73
82
|
maxSize?: number;
|
|
74
83
|
defaultSize?: number;
|
|
@@ -82,9 +91,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
82
91
|
) {
|
|
83
92
|
const relationField = getRelation(this.model, this.builder, name);
|
|
84
93
|
const parentRef = getRefFromModel(this.model, this.builder);
|
|
85
|
-
const
|
|
86
|
-
typeof relationField.type === 'string' ? relationField.type : relationField.type.name;
|
|
87
|
-
const ref = getRefFromModel(relationTypeName, this.builder);
|
|
94
|
+
const ref = options.type ?? getRefFromModel(relationField.type, this.builder);
|
|
88
95
|
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
89
96
|
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
90
97
|
let typeName: string | undefined;
|
|
@@ -230,9 +237,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
230
237
|
const [name, options = {} as never] = allArgs;
|
|
231
238
|
const relationField = getRelation(this.model, this.builder, name);
|
|
232
239
|
const parentRef = getRefFromModel(this.model, this.builder);
|
|
233
|
-
const
|
|
234
|
-
typeof relationField.type === 'string' ? relationField.type : relationField.type.name;
|
|
235
|
-
const ref = getRefFromModel(relationTypeName, this.builder);
|
|
240
|
+
const ref = options.type ?? getRefFromModel(relationField.type, this.builder);
|
|
236
241
|
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
237
242
|
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
238
243
|
|
|
@@ -321,4 +326,50 @@ export class PrismaObjectFieldBuilder<
|
|
|
321
326
|
},
|
|
322
327
|
}) as FieldRef<number, 'Object'>;
|
|
323
328
|
}
|
|
329
|
+
|
|
330
|
+
variant<Variant extends Model['Name'] | PrismaObjectRef<Model>>(
|
|
331
|
+
...allArgs: NormalizeArgs<
|
|
332
|
+
[
|
|
333
|
+
variant: Variant,
|
|
334
|
+
options?: VariantFieldOptions<
|
|
335
|
+
Types,
|
|
336
|
+
Model,
|
|
337
|
+
Variant extends PrismaObjectRef<Model> ? Variant : PrismaObjectRef<Model>
|
|
338
|
+
>,
|
|
339
|
+
]
|
|
340
|
+
>
|
|
341
|
+
): FieldRef<Model['Shape'], 'Object'> {
|
|
342
|
+
const [variant, options = {} as never] = allArgs;
|
|
343
|
+
const ref: PrismaObjectRef<PrismaModelTypes> =
|
|
344
|
+
typeof variant === 'string' ? getRefFromModel(variant, this.builder) : variant;
|
|
345
|
+
const parentRef = getRefFromModel(this.model, this.builder);
|
|
346
|
+
const findUnique = getFindUniqueForRef(parentRef, this.builder);
|
|
347
|
+
const loaderCache = ModelLoader.forModel(this.model, this.builder);
|
|
348
|
+
|
|
349
|
+
return this.field({
|
|
350
|
+
...options,
|
|
351
|
+
type: ref,
|
|
352
|
+
extensions: {
|
|
353
|
+
...options.extensions,
|
|
354
|
+
pothosPrismaRelation: SELF_RELATION,
|
|
355
|
+
},
|
|
356
|
+
resolve: (parent, args, context, info) => {
|
|
357
|
+
const mapping = getLoaderMapping(context, info.path);
|
|
358
|
+
|
|
359
|
+
if (mapping) {
|
|
360
|
+
setLoaderMappings(context, info.path, mapping);
|
|
361
|
+
|
|
362
|
+
return parent as never;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const queryOptions = queryFromInfo(context, info);
|
|
366
|
+
|
|
367
|
+
if (!findUnique) {
|
|
368
|
+
throw new Error(`Missing findUnique for Prisma type ${this.model}`);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return loaderCache(parent).loadSelf(queryOptions, context) as never;
|
|
372
|
+
},
|
|
373
|
+
}) as FieldRef<Model['Shape'], 'Object'>;
|
|
374
|
+
}
|
|
324
375
|
}
|
package/src/refs.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ObjectRef, SchemaTypes } from '@pothos/core';
|
|
2
2
|
import { Prisma } from '../tests/client';
|
|
3
|
+
import { PrismaObjectRef } from './object-ref';
|
|
3
4
|
import { PrismaDelegate } from './types';
|
|
5
|
+
import { PrismaModelTypes } from '.';
|
|
4
6
|
|
|
5
|
-
export const refMap = new WeakMap<object, Map<string,
|
|
7
|
+
export const refMap = new WeakMap<object, Map<string, PrismaObjectRef<PrismaModelTypes>>>();
|
|
6
8
|
export const findUniqueMap = new WeakMap<
|
|
7
9
|
object,
|
|
8
10
|
Map<ObjectRef<unknown>, ((args: unknown, ctx: {}) => unknown) | null>
|
|
@@ -16,14 +18,14 @@ export const includeForRefMap = new WeakMap<
|
|
|
16
18
|
export function getRefFromModel<Types extends SchemaTypes>(
|
|
17
19
|
name: string,
|
|
18
20
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
19
|
-
):
|
|
21
|
+
): PrismaObjectRef<PrismaModelTypes> {
|
|
20
22
|
if (!refMap.has(builder)) {
|
|
21
23
|
refMap.set(builder, new Map());
|
|
22
24
|
}
|
|
23
25
|
const cache = refMap.get(builder)!;
|
|
24
26
|
|
|
25
27
|
if (!cache.has(name)) {
|
|
26
|
-
cache.set(name,
|
|
28
|
+
cache.set(name, new PrismaObjectRef(name));
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
return cache.get(name)!;
|
package/src/schema-builder.ts
CHANGED
|
@@ -18,8 +18,8 @@ import { queryFromInfo } from './util';
|
|
|
18
18
|
const schemaBuilderProto = SchemaBuilder.prototype as PothosSchemaTypes.SchemaBuilder<SchemaTypes>;
|
|
19
19
|
|
|
20
20
|
schemaBuilderProto.prismaObject = function prismaObject(type, { fields, findUnique, ...options }) {
|
|
21
|
-
const ref = getRefFromModel(type, this);
|
|
22
|
-
const name = options.name ?? type;
|
|
21
|
+
const ref = options.variant ? this.objectRef(options.variant) : getRefFromModel(type, this);
|
|
22
|
+
const name = options.variant ?? options.name ?? type;
|
|
23
23
|
|
|
24
24
|
ref.name = name;
|
|
25
25
|
|
|
@@ -53,6 +53,7 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
53
53
|
{
|
|
54
54
|
findUnique,
|
|
55
55
|
name,
|
|
56
|
+
variant,
|
|
56
57
|
...options
|
|
57
58
|
}: PrismaNodeOptions<SchemaTypes, ModelTypes<PrismaDelegate>, [], never, {}>,
|
|
58
59
|
) {
|
|
@@ -62,16 +63,13 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
62
63
|
throw new TypeError('builder.prismaNode requires @pothos/plugin-relay to be installed');
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
const typeName = name ?? type;
|
|
66
|
+
const typeName = variant ?? name ?? type;
|
|
66
67
|
const delegate = getDelegateFromModel(this.options.prisma.client, type);
|
|
67
68
|
const nodeRef = new PrismaNodeRef(typeName);
|
|
68
69
|
const extendedOptions = {
|
|
69
70
|
...options,
|
|
71
|
+
variant,
|
|
70
72
|
interfaces: [interfaceRef, ...(options.interfaces ?? [])],
|
|
71
|
-
extensions: {
|
|
72
|
-
...options.extensions,
|
|
73
|
-
pothosPrismaInclude: options.include,
|
|
74
|
-
},
|
|
75
73
|
isTypeOf: (val: unknown) => nodeRef.hasBrand(val),
|
|
76
74
|
findUnique: (parent: unknown, context: {}) =>
|
|
77
75
|
findUnique(options.id.resolve(parent as never, context) as string, context),
|