@pothos/plugin-prisma 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +403 -308
- package/esm/field-builder.js +3 -3
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +4 -0
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts +23 -5
- package/esm/global-types.d.ts.map +1 -1
- package/esm/index.d.ts +4 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +46 -1
- package/esm/index.js.map +1 -1
- package/esm/model-loader.d.ts +5 -6
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +12 -69
- package/esm/model-loader.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +25 -6
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +83 -116
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/schema-builder.js +14 -4
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +73 -77
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +1 -0
- package/esm/types.js.map +1 -1
- package/esm/{cursors.d.ts → util/cursors.d.ts} +1 -1
- package/esm/util/cursors.d.ts.map +1 -0
- package/esm/{cursors.js → util/cursors.js} +0 -0
- package/esm/util/cursors.js.map +1 -0
- package/{lib/refs.d.ts → esm/util/datamodel.d.ts} +4 -8
- package/esm/util/datamodel.d.ts.map +1 -0
- package/esm/{refs.js → util/datamodel.js} +2 -25
- package/esm/util/datamodel.js.map +1 -0
- package/esm/util/deep-equal.d.ts +2 -0
- package/esm/util/deep-equal.d.ts.map +1 -0
- package/esm/util/deep-equal.js +39 -0
- package/esm/util/deep-equal.js.map +1 -0
- package/esm/util/loader-map.d.ts +6 -0
- package/esm/util/loader-map.d.ts.map +1 -0
- package/esm/{loader-map.js → util/loader-map.js} +10 -12
- package/esm/util/loader-map.js.map +1 -0
- package/esm/util/map-query.d.ts +6 -0
- package/esm/util/map-query.d.ts.map +1 -0
- package/esm/util/map-query.js +169 -0
- package/esm/util/map-query.js.map +1 -0
- package/esm/util/relation-map.d.ts +9 -0
- package/esm/util/relation-map.d.ts.map +1 -0
- package/esm/util/relation-map.js +20 -0
- package/esm/util/relation-map.js.map +1 -0
- package/esm/util/selections.d.ts +20 -0
- package/esm/util/selections.d.ts.map +1 -0
- package/esm/util/selections.js +139 -0
- package/esm/util/selections.js.map +1 -0
- package/lib/field-builder.js +9 -9
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +4 -0
- package/lib/generator.js.map +1 -1
- package/lib/global-types.d.ts +23 -5
- package/lib/global-types.d.ts.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +45 -0
- package/lib/index.js.map +1 -1
- package/lib/model-loader.d.ts +5 -6
- package/lib/model-loader.d.ts.map +1 -1
- package/lib/model-loader.js +13 -70
- package/lib/model-loader.js.map +1 -1
- package/lib/prisma-field-builder.d.ts +25 -6
- package/lib/prisma-field-builder.d.ts.map +1 -1
- package/lib/prisma-field-builder.js +89 -122
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +17 -7
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.d.ts +73 -77
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -1
- package/lib/{cursors.d.ts → util/cursors.d.ts} +1 -1
- package/lib/util/cursors.d.ts.map +1 -0
- package/lib/{cursors.js → util/cursors.js} +0 -0
- package/lib/util/cursors.js.map +1 -0
- package/{esm/refs.d.ts → lib/util/datamodel.d.ts} +4 -8
- package/lib/util/datamodel.d.ts.map +1 -0
- package/lib/{refs.js → util/datamodel.js} +3 -29
- package/lib/util/datamodel.js.map +1 -0
- package/lib/util/deep-equal.d.ts +2 -0
- package/lib/util/deep-equal.d.ts.map +1 -0
- package/lib/util/deep-equal.js +43 -0
- package/lib/util/deep-equal.js.map +1 -0
- package/lib/util/loader-map.d.ts +6 -0
- package/lib/util/loader-map.d.ts.map +1 -0
- package/lib/{loader-map.js → util/loader-map.js} +10 -12
- package/lib/util/loader-map.js.map +1 -0
- package/lib/util/map-query.d.ts +6 -0
- package/lib/util/map-query.d.ts.map +1 -0
- package/lib/util/map-query.js +175 -0
- package/lib/util/map-query.js.map +1 -0
- package/lib/util/relation-map.d.ts +9 -0
- package/lib/util/relation-map.d.ts.map +1 -0
- package/lib/util/relation-map.js +24 -0
- package/lib/util/relation-map.js.map +1 -0
- package/lib/util/selections.d.ts +20 -0
- package/lib/util/selections.d.ts.map +1 -0
- package/lib/util/selections.js +148 -0
- package/lib/util/selections.js.map +1 -0
- package/package.json +5 -5
- package/src/field-builder.ts +3 -3
- package/src/generator.ts +18 -0
- package/src/global-types.ts +59 -12
- package/src/index.ts +75 -1
- package/src/model-loader.ts +19 -92
- package/src/prisma-field-builder.ts +194 -152
- package/src/schema-builder.ts +28 -7
- package/src/types.ts +138 -102
- package/src/{cursors.ts → util/cursors.ts} +1 -1
- package/src/{refs.ts → util/datamodel.ts} +3 -44
- package/src/util/deep-equal.ts +51 -0
- package/src/{loader-map.ts → util/loader-map.ts} +13 -13
- package/src/util/map-query.ts +327 -0
- package/src/util/relation-map.ts +36 -0
- package/src/util/selections.ts +192 -0
- package/esm/cursors.d.ts.map +0 -1
- package/esm/cursors.js.map +0 -1
- package/esm/loader-map.d.ts +0 -6
- package/esm/loader-map.d.ts.map +0 -1
- package/esm/loader-map.js.map +0 -1
- package/esm/refs.d.ts.map +0 -1
- package/esm/refs.js.map +0 -1
- package/esm/util/index.d.ts +0 -5
- package/esm/util/index.d.ts.map +0 -1
- package/esm/util/index.js +0 -16
- package/esm/util/index.js.map +0 -1
- package/esm/util/map-includes.d.ts +0 -6
- package/esm/util/map-includes.d.ts.map +0 -1
- package/esm/util/map-includes.js +0 -184
- package/esm/util/map-includes.js.map +0 -1
- package/esm/util/merge-includes.d.ts +0 -3
- package/esm/util/merge-includes.d.ts.map +0 -1
- package/esm/util/merge-includes.js +0 -91
- package/esm/util/merge-includes.js.map +0 -1
- package/lib/cursors.d.ts.map +0 -1
- package/lib/cursors.js.map +0 -1
- package/lib/loader-map.d.ts +0 -6
- package/lib/loader-map.d.ts.map +0 -1
- package/lib/loader-map.js.map +0 -1
- package/lib/refs.d.ts.map +0 -1
- package/lib/refs.js.map +0 -1
- package/lib/util/index.d.ts +0 -5
- package/lib/util/index.d.ts.map +0 -1
- package/lib/util/index.js +0 -30
- package/lib/util/index.js.map +0 -1
- package/lib/util/map-includes.d.ts +0 -6
- package/lib/util/map-includes.d.ts.map +0 -1
- package/lib/util/map-includes.js +0 -189
- package/lib/util/map-includes.js.map +0 -1
- package/lib/util/merge-includes.d.ts +0 -3
- package/lib/util/merge-includes.d.ts.map +0 -1
- package/lib/util/merge-includes.js +0 -96
- package/lib/util/merge-includes.js.map +0 -1
- package/src/util/index.ts +0 -26
- package/src/util/map-includes.ts +0 -328
- package/src/util/merge-includes.ts +0 -121
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeIncludes = exports.deepEqual = void 0;
|
|
4
|
-
/* eslint-disable no-continue */
|
|
5
|
-
function deepEqual(left, right, ignore) {
|
|
6
|
-
if (left === right) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (left && right && typeof left === 'object' && typeof right === 'object') {
|
|
10
|
-
if (Array.isArray(left)) {
|
|
11
|
-
if (!Array.isArray(right)) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const { length } = left;
|
|
15
|
-
if (right.length !== length) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
for (let i = 0; i < length; i += 1) {
|
|
19
|
-
if (!deepEqual(left[i], right[i])) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
const keys = Object.keys(left);
|
|
26
|
-
const keyLength = keys.length;
|
|
27
|
-
if (keyLength !== Object.keys(right).length) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
for (const key of keys) {
|
|
31
|
-
if (ignore === null || ignore === void 0 ? void 0 : ignore.has(key)) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (!deepEqual(left[key], right[key])) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
exports.deepEqual = deepEqual;
|
|
43
|
-
const ignoreInclude = new Set(['include']);
|
|
44
|
-
function mergeIncludes(existing, newQuery) {
|
|
45
|
-
if (!deepEqual(existing, newQuery, ignoreInclude)) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
if (!existing) {
|
|
49
|
-
return newQuery;
|
|
50
|
-
}
|
|
51
|
-
if (newQuery === true) {
|
|
52
|
-
return existing;
|
|
53
|
-
}
|
|
54
|
-
if (existing === true) {
|
|
55
|
-
return newQuery || existing;
|
|
56
|
-
}
|
|
57
|
-
if (!newQuery) {
|
|
58
|
-
return existing;
|
|
59
|
-
}
|
|
60
|
-
if (!existing.include) {
|
|
61
|
-
return { ...existing, include: newQuery.include };
|
|
62
|
-
}
|
|
63
|
-
if (!newQuery.include) {
|
|
64
|
-
return existing;
|
|
65
|
-
}
|
|
66
|
-
const merged = {
|
|
67
|
-
...existing.include,
|
|
68
|
-
};
|
|
69
|
-
const newInclude = newQuery.include;
|
|
70
|
-
const keys = Object.keys(newQuery.include);
|
|
71
|
-
for (const key of keys) {
|
|
72
|
-
const current = merged[key];
|
|
73
|
-
const newVal = newInclude[key];
|
|
74
|
-
if (!current) {
|
|
75
|
-
merged[key] = newVal;
|
|
76
|
-
}
|
|
77
|
-
else if (typeof newVal === 'boolean') {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
else if (merged[key] === true) {
|
|
81
|
-
if (newVal) {
|
|
82
|
-
merged[key] = newVal;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else if (typeof current === 'object' && typeof newVal === 'object' && current && newVal) {
|
|
86
|
-
const mergedVal = mergeIncludes(current, newVal);
|
|
87
|
-
if (!mergedVal) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
merged[key] = mergedVal;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return { ...existing, include: merged };
|
|
94
|
-
}
|
|
95
|
-
exports.mergeIncludes = mergeIncludes;
|
|
96
|
-
//# sourceMappingURL=merge-includes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-includes.js","sourceRoot":"","sources":["../../src/util/merge-includes.ts"],"names":[],"mappings":";;;AAAA,gCAAgC;AAChC,SAAgB,SAAS,CAAC,IAAa,EAAE,KAAc,EAAE,MAAoB;IAC3E,IAAI,IAAI,KAAK,KAAK,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAI,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC1E,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACzB,OAAO,KAAK,CAAC;aACd;YAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;YAExB,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE;gBAC3B,OAAO,KAAK,CAAC;aACd;YAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;gBAClC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;oBACjC,OAAO,KA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|
|
4
|
-
export * from './merge-includes';
|
|
5
|
-
|
|
6
|
-
export function resolveIndirectType(
|
|
7
|
-
type: GraphQLNamedType,
|
|
8
|
-
info: GraphQLResolveInfo,
|
|
9
|
-
): GraphQLNamedType {
|
|
10
|
-
const indirectInclude = type.extensions?.pothosPrismaIndirectInclude as
|
|
11
|
-
| { getType: () => string }
|
|
12
|
-
| undefined;
|
|
13
|
-
|
|
14
|
-
if (indirectInclude) {
|
|
15
|
-
const includeTypeName = indirectInclude.getType();
|
|
16
|
-
const resolvedType = info.schema.getType(includeTypeName);
|
|
17
|
-
|
|
18
|
-
if (!resolvedType) {
|
|
19
|
-
throw new Error(`Could not find type ${includeTypeName}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return resolveIndirectType(resolvedType, info);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return type;
|
|
26
|
-
}
|
package/src/util/map-includes.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
/* eslint-disable no-param-reassign */
|
|
3
|
-
/* eslint-disable no-continue */
|
|
4
|
-
import {
|
|
5
|
-
FieldNode,
|
|
6
|
-
getNamedType,
|
|
7
|
-
GraphQLFieldMap,
|
|
8
|
-
GraphQLNamedType,
|
|
9
|
-
GraphQLObjectType,
|
|
10
|
-
GraphQLResolveInfo,
|
|
11
|
-
SelectionSetNode,
|
|
12
|
-
} from 'graphql';
|
|
13
|
-
import { getArgumentValues } from 'graphql/execution/values';
|
|
14
|
-
import { setLoaderMappings } from '../loader-map';
|
|
15
|
-
import {
|
|
16
|
-
IncludeCounts,
|
|
17
|
-
IncludeMap,
|
|
18
|
-
IndirectLoadMap,
|
|
19
|
-
LoaderMappings,
|
|
20
|
-
SubFieldInclude,
|
|
21
|
-
} from '../types';
|
|
22
|
-
import { mergeIncludes, resolveIndirectType } from '.';
|
|
23
|
-
|
|
24
|
-
export const SELF_RELATION = '@self';
|
|
25
|
-
|
|
26
|
-
function handleField(
|
|
27
|
-
ctx: object,
|
|
28
|
-
info: GraphQLResolveInfo,
|
|
29
|
-
fields: GraphQLFieldMap<unknown, unknown>,
|
|
30
|
-
selection: FieldNode,
|
|
31
|
-
includes: IncludeMap,
|
|
32
|
-
counts: IncludeCounts,
|
|
33
|
-
mappings: LoaderMappings,
|
|
34
|
-
indirectMap?: IndirectLoadMap,
|
|
35
|
-
) {
|
|
36
|
-
if (selection.name.value.startsWith('__')) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const field = fields[selection.name.value];
|
|
41
|
-
|
|
42
|
-
if (!field) {
|
|
43
|
-
throw new Error(`Unknown field ${selection.name.value}`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const countName = field.extensions?.pothosPrismaRelationCount as string | undefined;
|
|
47
|
-
const parentCountName = field.extensions?.pothosPrismaRelationCountForParent as
|
|
48
|
-
| string
|
|
49
|
-
| undefined;
|
|
50
|
-
const relationName = field.extensions?.pothosPrismaRelation as string | undefined;
|
|
51
|
-
|
|
52
|
-
if (countName) {
|
|
53
|
-
counts.current[countName] = true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (parentCountName) {
|
|
57
|
-
counts.parent[parentCountName] = true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (indirectMap?.subFields.length) {
|
|
61
|
-
const subField = indirectMap.subFields[0];
|
|
62
|
-
|
|
63
|
-
if (field.name === subField.name && selection.selectionSet) {
|
|
64
|
-
const type = getNamedType(field.type);
|
|
65
|
-
|
|
66
|
-
if (!(type.name !== subField.type)) {
|
|
67
|
-
throw new TypeError(`Expected ${field.name} to be ${subField.type} but got ${type.name}`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
includesFromSelectionSet(
|
|
71
|
-
ctx,
|
|
72
|
-
type,
|
|
73
|
-
info,
|
|
74
|
-
includes,
|
|
75
|
-
counts,
|
|
76
|
-
mappings,
|
|
77
|
-
selection.selectionSet,
|
|
78
|
-
indirectMap.subFields.length > 0
|
|
79
|
-
? {
|
|
80
|
-
subFields: indirectMap.subFields.slice(1),
|
|
81
|
-
path: [...indirectMap.path, selection.alias?.value ?? selection.name.value],
|
|
82
|
-
}
|
|
83
|
-
: undefined,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!relationName) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const type = getNamedType(field.type);
|
|
95
|
-
const includeType = resolveIndirectType(type, info);
|
|
96
|
-
|
|
97
|
-
const newIncludes: IncludeMap = {
|
|
98
|
-
...(includeType.extensions?.pothosPrismaInclude as IncludeMap),
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
let query = field.extensions?.pothosPrismaQuery ?? {};
|
|
102
|
-
|
|
103
|
-
if (typeof query === 'function') {
|
|
104
|
-
const args = getArgumentValues(field, selection, info.variableValues) as Record<
|
|
105
|
-
string,
|
|
106
|
-
unknown
|
|
107
|
-
>;
|
|
108
|
-
|
|
109
|
-
query = query(args, ctx);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const existingInclude =
|
|
113
|
-
relationName === SELF_RELATION ? { include: includes } : includes[relationName];
|
|
114
|
-
|
|
115
|
-
query = { ...(query as {}), include: newIncludes };
|
|
116
|
-
|
|
117
|
-
if (typeof existingInclude === 'object') {
|
|
118
|
-
query = mergeIncludes(existingInclude, query as Record<string, unknown>);
|
|
119
|
-
|
|
120
|
-
if (!query) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!mappings[relationName]) {
|
|
126
|
-
mappings[relationName] = [];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const nestedIncludes = (query as { include: IncludeMap }).include;
|
|
130
|
-
const nestedMappings: LoaderMappings = {};
|
|
131
|
-
const nestedCounts: IncludeCounts = {
|
|
132
|
-
current: {},
|
|
133
|
-
parent: counts.current,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
if (relationName === SELF_RELATION) {
|
|
137
|
-
mappings[relationName].push({
|
|
138
|
-
field: selection.name.value,
|
|
139
|
-
alias: selection.alias?.value,
|
|
140
|
-
mappings: nestedMappings,
|
|
141
|
-
indirectPath: indirectMap?.path ?? [],
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const { include } = query as { include: Record<string, IncludeMap> };
|
|
145
|
-
|
|
146
|
-
if (selection.selectionSet) {
|
|
147
|
-
includesFromSelectionSet(
|
|
148
|
-
ctx,
|
|
149
|
-
type,
|
|
150
|
-
info,
|
|
151
|
-
includes,
|
|
152
|
-
counts,
|
|
153
|
-
nestedMappings,
|
|
154
|
-
selection.selectionSet,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
Object.keys(include).forEach((key) => {
|
|
159
|
-
includes[key] = include[key];
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
mappings[relationName].push({
|
|
166
|
-
field: selection.name.value,
|
|
167
|
-
alias: selection.alias?.value,
|
|
168
|
-
mappings: nestedMappings,
|
|
169
|
-
indirectPath: indirectMap?.path ?? [],
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
if (selection.selectionSet) {
|
|
173
|
-
includesFromSelectionSet(
|
|
174
|
-
ctx,
|
|
175
|
-
type,
|
|
176
|
-
info,
|
|
177
|
-
nestedIncludes,
|
|
178
|
-
nestedCounts,
|
|
179
|
-
nestedMappings,
|
|
180
|
-
selection.selectionSet,
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (Object.keys(nestedCounts.current).length > 0) {
|
|
185
|
-
nestedIncludes._count = { select: nestedCounts.current };
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (Object.keys(nestedIncludes).length === 0) {
|
|
189
|
-
delete (query as { include?: unknown }).include;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
includes[relationName] =
|
|
193
|
-
Object.keys(query as {}).length > 0 ? (query as Record<string, unknown>) : true;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function includesFromSelectionSet(
|
|
197
|
-
ctx: object,
|
|
198
|
-
type: GraphQLNamedType,
|
|
199
|
-
info: GraphQLResolveInfo,
|
|
200
|
-
includes: IncludeMap,
|
|
201
|
-
counts: IncludeCounts,
|
|
202
|
-
mappings: LoaderMappings,
|
|
203
|
-
selectionSet: SelectionSetNode,
|
|
204
|
-
prevIndirectMap?: IndirectLoadMap,
|
|
205
|
-
) {
|
|
206
|
-
const indirectInclude = type.extensions?.pothosPrismaIndirectInclude as
|
|
207
|
-
| { path: SubFieldInclude[] }
|
|
208
|
-
| undefined;
|
|
209
|
-
|
|
210
|
-
const indirectMap = prevIndirectMap
|
|
211
|
-
? {
|
|
212
|
-
path: [...prevIndirectMap.path],
|
|
213
|
-
subFields:
|
|
214
|
-
prevIndirectMap.subFields.length > 0
|
|
215
|
-
? prevIndirectMap.subFields
|
|
216
|
-
: indirectInclude?.path ?? [],
|
|
217
|
-
}
|
|
218
|
-
: indirectInclude && { subFields: indirectInclude.path ?? [], path: [] };
|
|
219
|
-
|
|
220
|
-
const firstSubFieldType =
|
|
221
|
-
indirectMap &&
|
|
222
|
-
indirectMap?.subFields.length > 0 &&
|
|
223
|
-
indirectMap.subFields?.length > 0 &&
|
|
224
|
-
indirectMap.subFields[0].type;
|
|
225
|
-
|
|
226
|
-
const expectedType = firstSubFieldType ? info.schema.getType(firstSubFieldType) : type;
|
|
227
|
-
|
|
228
|
-
if (!(expectedType instanceof GraphQLObjectType)) {
|
|
229
|
-
throw new TypeError('Expected returnType to be an object type');
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
for (const selection of selectionSet.selections) {
|
|
233
|
-
switch (selection.kind) {
|
|
234
|
-
case 'Field':
|
|
235
|
-
if (!(type === expectedType)) {
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
handleField(
|
|
240
|
-
ctx,
|
|
241
|
-
info,
|
|
242
|
-
type.getFields(),
|
|
243
|
-
selection,
|
|
244
|
-
includes,
|
|
245
|
-
counts,
|
|
246
|
-
mappings,
|
|
247
|
-
indirectMap,
|
|
248
|
-
);
|
|
249
|
-
break;
|
|
250
|
-
case 'FragmentSpread':
|
|
251
|
-
if (!info.fragments[selection.name.value]) {
|
|
252
|
-
throw new Error(`Missing fragment ${selection.name.value}`);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (info.fragments[selection.name.value].typeCondition.name.value !== expectedType.name) {
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
includesFromSelectionSet(
|
|
260
|
-
ctx,
|
|
261
|
-
expectedType,
|
|
262
|
-
info,
|
|
263
|
-
includes,
|
|
264
|
-
counts,
|
|
265
|
-
mappings,
|
|
266
|
-
info.fragments[selection.name.value].selectionSet,
|
|
267
|
-
indirectMap,
|
|
268
|
-
);
|
|
269
|
-
break;
|
|
270
|
-
case 'InlineFragment':
|
|
271
|
-
if (selection.typeCondition && selection.typeCondition.name.value !== expectedType.name) {
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
includesFromSelectionSet(
|
|
276
|
-
ctx,
|
|
277
|
-
selection.typeCondition ? expectedType : type,
|
|
278
|
-
info,
|
|
279
|
-
includes,
|
|
280
|
-
counts,
|
|
281
|
-
mappings,
|
|
282
|
-
selection.selectionSet,
|
|
283
|
-
indirectMap,
|
|
284
|
-
);
|
|
285
|
-
break;
|
|
286
|
-
default:
|
|
287
|
-
throw new Error(`Unexpected selection kind ${(selection as { kind: string }).kind}`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export function queryFromInfo(ctx: object, info: GraphQLResolveInfo, typeName?: string): {} {
|
|
293
|
-
const { fieldNodes } = info;
|
|
294
|
-
const type = typeName ? info.schema.getTypeMap()[typeName] : getNamedType(info.returnType);
|
|
295
|
-
const includeType = resolveIndirectType(type, info);
|
|
296
|
-
|
|
297
|
-
const includes: IncludeMap = {
|
|
298
|
-
...(includeType.extensions?.pothosPrismaInclude as IncludeMap),
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
const counts = {
|
|
302
|
-
parent: {},
|
|
303
|
-
current: {},
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
const mappings: LoaderMappings = {};
|
|
307
|
-
for (const node of fieldNodes) {
|
|
308
|
-
if (!node.selectionSet) {
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
includesFromSelectionSet(ctx, type, info, includes, counts, mappings, node.selectionSet);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (Object.keys(counts.current).length > 0) {
|
|
316
|
-
includes._count = { select: counts.current };
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (Object.keys(includes).length > 0) {
|
|
320
|
-
if (mappings) {
|
|
321
|
-
setLoaderMappings(ctx, info.path, mappings);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
return { include: includes };
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
return {};
|
|
328
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-continue */
|
|
2
|
-
export function deepEqual(left: unknown, right: unknown, ignore?: Set<string>) {
|
|
3
|
-
if (left === right) {
|
|
4
|
-
return true;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
if (left && right && typeof left === 'object' && typeof right === 'object') {
|
|
8
|
-
if (Array.isArray(left)) {
|
|
9
|
-
if (!Array.isArray(right)) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const { length } = left;
|
|
14
|
-
|
|
15
|
-
if (right.length !== length) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
for (let i = 0; i < length; i += 1) {
|
|
20
|
-
if (!deepEqual(left[i], right[i])) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const keys = Object.keys(left);
|
|
29
|
-
const keyLength = keys.length;
|
|
30
|
-
|
|
31
|
-
if (keyLength !== Object.keys(right).length) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
for (const key of keys) {
|
|
36
|
-
if (ignore?.has(key)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
!deepEqual((left as Record<string, unknown>)[key], (right as Record<string, unknown>)[key])
|
|
42
|
-
) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const ignoreInclude = new Set(['include']);
|
|
54
|
-
|
|
55
|
-
export function mergeIncludes(
|
|
56
|
-
existing: Record<string, unknown> | boolean,
|
|
57
|
-
newQuery: Record<string, unknown> | boolean,
|
|
58
|
-
): Record<string, unknown> | boolean {
|
|
59
|
-
if (!deepEqual(existing, newQuery, ignoreInclude)) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!existing) {
|
|
64
|
-
return newQuery;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (newQuery === true) {
|
|
68
|
-
return existing;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (existing === true) {
|
|
72
|
-
return newQuery || existing;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!newQuery) {
|
|
76
|
-
return existing;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!existing.include) {
|
|
80
|
-
return { ...existing, include: newQuery.include };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!newQuery.include) {
|
|
84
|
-
return existing;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const merged: Record<string, unknown> = {
|
|
88
|
-
...(existing.include as object),
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const newInclude = newQuery.include as Record<string, unknown>;
|
|
92
|
-
const keys = Object.keys(newQuery.include as object);
|
|
93
|
-
|
|
94
|
-
for (const key of keys) {
|
|
95
|
-
const current = merged[key];
|
|
96
|
-
const newVal = newInclude[key];
|
|
97
|
-
|
|
98
|
-
if (!current) {
|
|
99
|
-
merged[key] = newVal;
|
|
100
|
-
} else if (typeof newVal === 'boolean') {
|
|
101
|
-
continue;
|
|
102
|
-
} else if (merged[key] === true) {
|
|
103
|
-
if (newVal) {
|
|
104
|
-
merged[key] = newVal;
|
|
105
|
-
}
|
|
106
|
-
} else if (typeof current === 'object' && typeof newVal === 'object' && current && newVal) {
|
|
107
|
-
const mergedVal = mergeIncludes(
|
|
108
|
-
current as Record<string, unknown>,
|
|
109
|
-
newVal as Record<string, unknown>,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
if (!mergedVal) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
merged[key] = mergedVal;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return { ...existing, include: merged };
|
|
121
|
-
}
|