@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.
Files changed (168) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +403 -308
  3. package/esm/field-builder.js +12 -14
  4. package/esm/field-builder.js.map +1 -1
  5. package/esm/generator.js +4 -0
  6. package/esm/generator.js.map +1 -1
  7. package/esm/global-types.d.ts +23 -5
  8. package/esm/global-types.d.ts.map +1 -1
  9. package/esm/index.d.ts +4 -1
  10. package/esm/index.d.ts.map +1 -1
  11. package/esm/index.js +46 -1
  12. package/esm/index.js.map +1 -1
  13. package/esm/model-loader.d.ts +5 -6
  14. package/esm/model-loader.d.ts.map +1 -1
  15. package/esm/model-loader.js +12 -69
  16. package/esm/model-loader.js.map +1 -1
  17. package/esm/prisma-field-builder.d.ts +25 -6
  18. package/esm/prisma-field-builder.d.ts.map +1 -1
  19. package/esm/prisma-field-builder.js +86 -117
  20. package/esm/prisma-field-builder.js.map +1 -1
  21. package/esm/schema-builder.js +15 -4
  22. package/esm/schema-builder.js.map +1 -1
  23. package/esm/types.d.ts +73 -77
  24. package/esm/types.d.ts.map +1 -1
  25. package/esm/types.js +1 -0
  26. package/esm/types.js.map +1 -1
  27. package/esm/{cursors.d.ts → util/cursors.d.ts} +10 -8
  28. package/esm/util/cursors.d.ts.map +1 -0
  29. package/esm/{cursors.js → util/cursors.js} +34 -13
  30. package/esm/util/cursors.js.map +1 -0
  31. package/{lib/refs.d.ts → esm/util/datamodel.d.ts} +9 -8
  32. package/esm/util/datamodel.d.ts.map +1 -0
  33. package/esm/{refs.js → util/datamodel.js} +27 -30
  34. package/esm/util/datamodel.js.map +1 -0
  35. package/esm/util/deep-equal.d.ts +2 -0
  36. package/esm/util/deep-equal.d.ts.map +1 -0
  37. package/esm/util/deep-equal.js +39 -0
  38. package/esm/util/deep-equal.js.map +1 -0
  39. package/esm/util/loader-map.d.ts +6 -0
  40. package/esm/util/loader-map.d.ts.map +1 -0
  41. package/esm/{loader-map.js → util/loader-map.js} +10 -12
  42. package/esm/util/loader-map.js.map +1 -0
  43. package/esm/util/map-query.d.ts +6 -0
  44. package/esm/util/map-query.d.ts.map +1 -0
  45. package/esm/util/map-query.js +169 -0
  46. package/esm/util/map-query.js.map +1 -0
  47. package/esm/util/relation-map.d.ts +9 -0
  48. package/esm/util/relation-map.d.ts.map +1 -0
  49. package/esm/util/relation-map.js +20 -0
  50. package/esm/util/relation-map.js.map +1 -0
  51. package/esm/util/selections.d.ts +20 -0
  52. package/esm/util/selections.d.ts.map +1 -0
  53. package/esm/util/selections.js +139 -0
  54. package/esm/util/selections.js.map +1 -0
  55. package/lib/field-builder.js +16 -18
  56. package/lib/field-builder.js.map +1 -1
  57. package/lib/generator.js +4 -0
  58. package/lib/generator.js.map +1 -1
  59. package/lib/global-types.d.ts +23 -5
  60. package/lib/global-types.d.ts.map +1 -1
  61. package/lib/index.d.ts +4 -1
  62. package/lib/index.d.ts.map +1 -1
  63. package/lib/index.js +45 -0
  64. package/lib/index.js.map +1 -1
  65. package/lib/model-loader.d.ts +5 -6
  66. package/lib/model-loader.d.ts.map +1 -1
  67. package/lib/model-loader.js +13 -70
  68. package/lib/model-loader.js.map +1 -1
  69. package/lib/prisma-field-builder.d.ts +25 -6
  70. package/lib/prisma-field-builder.d.ts.map +1 -1
  71. package/lib/prisma-field-builder.js +90 -121
  72. package/lib/prisma-field-builder.js.map +1 -1
  73. package/lib/schema-builder.js +18 -7
  74. package/lib/schema-builder.js.map +1 -1
  75. package/lib/types.d.ts +73 -77
  76. package/lib/types.d.ts.map +1 -1
  77. package/lib/types.js +2 -0
  78. package/lib/types.js.map +1 -1
  79. package/lib/{cursors.d.ts → util/cursors.d.ts} +10 -8
  80. package/lib/util/cursors.d.ts.map +1 -0
  81. package/lib/{cursors.js → util/cursors.js} +39 -14
  82. package/lib/util/cursors.js.map +1 -0
  83. package/{esm/refs.d.ts → lib/util/datamodel.d.ts} +9 -8
  84. package/lib/util/datamodel.d.ts.map +1 -0
  85. package/lib/{refs.js → util/datamodel.js} +32 -35
  86. package/lib/util/datamodel.js.map +1 -0
  87. package/lib/util/deep-equal.d.ts +2 -0
  88. package/lib/util/deep-equal.d.ts.map +1 -0
  89. package/lib/util/deep-equal.js +43 -0
  90. package/lib/util/deep-equal.js.map +1 -0
  91. package/lib/util/loader-map.d.ts +6 -0
  92. package/lib/util/loader-map.d.ts.map +1 -0
  93. package/lib/{loader-map.js → util/loader-map.js} +10 -12
  94. package/lib/util/loader-map.js.map +1 -0
  95. package/lib/util/map-query.d.ts +6 -0
  96. package/lib/util/map-query.d.ts.map +1 -0
  97. package/lib/util/map-query.js +175 -0
  98. package/lib/util/map-query.js.map +1 -0
  99. package/lib/util/relation-map.d.ts +9 -0
  100. package/lib/util/relation-map.d.ts.map +1 -0
  101. package/lib/util/relation-map.js +24 -0
  102. package/lib/util/relation-map.js.map +1 -0
  103. package/lib/util/selections.d.ts +20 -0
  104. package/lib/util/selections.d.ts.map +1 -0
  105. package/lib/util/selections.js +148 -0
  106. package/lib/util/selections.js.map +1 -0
  107. package/package.json +7 -7
  108. package/src/field-builder.ts +12 -12
  109. package/src/generator.ts +18 -0
  110. package/src/global-types.ts +59 -12
  111. package/src/index.ts +75 -1
  112. package/src/model-loader.ts +19 -92
  113. package/src/prisma-field-builder.ts +199 -147
  114. package/src/schema-builder.ts +29 -7
  115. package/src/types.ts +138 -102
  116. package/src/{cursors.ts → util/cursors.ts} +45 -20
  117. package/src/{refs.ts → util/datamodel.ts} +36 -40
  118. package/src/util/deep-equal.ts +51 -0
  119. package/src/{loader-map.ts → util/loader-map.ts} +13 -13
  120. package/src/util/map-query.ts +327 -0
  121. package/src/util/relation-map.ts +36 -0
  122. package/src/util/selections.ts +192 -0
  123. package/.turbo/turbo-build.log +0 -17
  124. package/.turbo/turbo-test.log +0 -18
  125. package/.turbo/turbo-type.log +0 -5
  126. package/babel.config.js +0 -3
  127. package/esm/cursors.d.ts.map +0 -1
  128. package/esm/cursors.js.map +0 -1
  129. package/esm/loader-map.d.ts +0 -6
  130. package/esm/loader-map.d.ts.map +0 -1
  131. package/esm/loader-map.js.map +0 -1
  132. package/esm/refs.d.ts.map +0 -1
  133. package/esm/refs.js.map +0 -1
  134. package/esm/util/index.d.ts +0 -5
  135. package/esm/util/index.d.ts.map +0 -1
  136. package/esm/util/index.js +0 -16
  137. package/esm/util/index.js.map +0 -1
  138. package/esm/util/map-includes.d.ts +0 -6
  139. package/esm/util/map-includes.d.ts.map +0 -1
  140. package/esm/util/map-includes.js +0 -184
  141. package/esm/util/map-includes.js.map +0 -1
  142. package/esm/util/merge-includes.d.ts +0 -3
  143. package/esm/util/merge-includes.d.ts.map +0 -1
  144. package/esm/util/merge-includes.js +0 -91
  145. package/esm/util/merge-includes.js.map +0 -1
  146. package/lib/cursors.d.ts.map +0 -1
  147. package/lib/cursors.js.map +0 -1
  148. package/lib/loader-map.d.ts +0 -6
  149. package/lib/loader-map.d.ts.map +0 -1
  150. package/lib/loader-map.js.map +0 -1
  151. package/lib/refs.d.ts.map +0 -1
  152. package/lib/refs.js.map +0 -1
  153. package/lib/util/index.d.ts +0 -5
  154. package/lib/util/index.d.ts.map +0 -1
  155. package/lib/util/index.js +0 -30
  156. package/lib/util/index.js.map +0 -1
  157. package/lib/util/map-includes.d.ts +0 -6
  158. package/lib/util/map-includes.d.ts.map +0 -1
  159. package/lib/util/map-includes.js +0 -189
  160. package/lib/util/map-includes.js.map +0 -1
  161. package/lib/util/merge-includes.d.ts +0 -3
  162. package/lib/util/merge-includes.d.ts.map +0 -1
  163. package/lib/util/merge-includes.js +0 -96
  164. package/lib/util/merge-includes.js.map +0 -1
  165. package/src/util/index.ts +0 -26
  166. package/src/util/map-includes.ts +0 -328
  167. package/src/util/merge-includes.ts +0 -121
  168. package/tsconfig.tsbuildinfo +0 -1
@@ -1,189 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.queryFromInfo = exports.includesFromSelectionSet = exports.SELF_RELATION = void 0;
4
- /* eslint-disable no-underscore-dangle */
5
- /* eslint-disable no-param-reassign */
6
- /* eslint-disable no-continue */
7
- const graphql_1 = require("graphql");
8
- const values_1 = require("graphql/execution/values");
9
- const loader_map_1 = require("../loader-map");
10
- const _1 = require(".");
11
- exports.SELF_RELATION = '@self';
12
- function handleField(ctx, info, fields, selection, includes, counts, mappings, indirectMap) {
13
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
14
- if (selection.name.value.startsWith('__')) {
15
- return;
16
- }
17
- const field = fields[selection.name.value];
18
- if (!field) {
19
- throw new Error(`Unknown field ${selection.name.value}`);
20
- }
21
- const countName = (_a = field.extensions) === null || _a === void 0 ? void 0 : _a.pothosPrismaRelationCount;
22
- const parentCountName = (_b = field.extensions) === null || _b === void 0 ? void 0 : _b.pothosPrismaRelationCountForParent;
23
- const relationName = (_c = field.extensions) === null || _c === void 0 ? void 0 : _c.pothosPrismaRelation;
24
- if (countName) {
25
- counts.current[countName] = true;
26
- }
27
- if (parentCountName) {
28
- counts.parent[parentCountName] = true;
29
- }
30
- if (indirectMap === null || indirectMap === void 0 ? void 0 : indirectMap.subFields.length) {
31
- const subField = indirectMap.subFields[0];
32
- if (field.name === subField.name && selection.selectionSet) {
33
- const type = (0, graphql_1.getNamedType)(field.type);
34
- if (!(type.name !== subField.type)) {
35
- throw new TypeError(`Expected ${field.name} to be ${subField.type} but got ${type.name}`);
36
- }
37
- includesFromSelectionSet(ctx, type, info, includes, counts, mappings, selection.selectionSet, indirectMap.subFields.length > 0
38
- ? {
39
- subFields: indirectMap.subFields.slice(1),
40
- path: [...indirectMap.path, (_e = (_d = selection.alias) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : selection.name.value],
41
- }
42
- : undefined);
43
- }
44
- return;
45
- }
46
- if (!relationName) {
47
- return;
48
- }
49
- const type = (0, graphql_1.getNamedType)(field.type);
50
- const includeType = (0, _1.resolveIndirectType)(type, info);
51
- const newIncludes = {
52
- ...(_f = includeType.extensions) === null || _f === void 0 ? void 0 : _f.pothosPrismaInclude,
53
- };
54
- let query = (_h = (_g = field.extensions) === null || _g === void 0 ? void 0 : _g.pothosPrismaQuery) !== null && _h !== void 0 ? _h : {};
55
- if (typeof query === 'function') {
56
- const args = (0, values_1.getArgumentValues)(field, selection, info.variableValues);
57
- query = query(args, ctx);
58
- }
59
- const existingInclude = relationName === exports.SELF_RELATION ? { include: includes } : includes[relationName];
60
- query = { ...query, include: newIncludes };
61
- if (typeof existingInclude === 'object') {
62
- query = (0, _1.mergeIncludes)(existingInclude, query);
63
- if (!query) {
64
- return;
65
- }
66
- }
67
- if (!mappings[relationName]) {
68
- mappings[relationName] = [];
69
- }
70
- const nestedIncludes = query.include;
71
- const nestedMappings = {};
72
- const nestedCounts = {
73
- current: {},
74
- parent: counts.current,
75
- };
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;
91
- }
92
- mappings[relationName].push({
93
- field: selection.name.value,
94
- alias: (_l = selection.alias) === null || _l === void 0 ? void 0 : _l.value,
95
- mappings: nestedMappings,
96
- indirectPath: (_m = indirectMap === null || indirectMap === void 0 ? void 0 : indirectMap.path) !== null && _m !== void 0 ? _m : [],
97
- });
98
- if (selection.selectionSet) {
99
- includesFromSelectionSet(ctx, type, info, nestedIncludes, nestedCounts, nestedMappings, selection.selectionSet);
100
- }
101
- if (Object.keys(nestedCounts.current).length > 0) {
102
- nestedIncludes._count = { select: nestedCounts.current };
103
- }
104
- if (Object.keys(nestedIncludes).length === 0) {
105
- delete query.include;
106
- }
107
- includes[relationName] =
108
- Object.keys(query).length > 0 ? query : true;
109
- }
110
- function includesFromSelectionSet(ctx, type, info, includes, counts, mappings, selectionSet, prevIndirectMap) {
111
- var _a, _b, _c, _d;
112
- const indirectInclude = (_a = type.extensions) === null || _a === void 0 ? void 0 : _a.pothosPrismaIndirectInclude;
113
- const indirectMap = prevIndirectMap
114
- ? {
115
- path: [...prevIndirectMap.path],
116
- subFields: prevIndirectMap.subFields.length > 0
117
- ? prevIndirectMap.subFields
118
- : (_b = indirectInclude === null || indirectInclude === void 0 ? void 0 : indirectInclude.path) !== null && _b !== void 0 ? _b : [],
119
- }
120
- : indirectInclude && { subFields: (_c = indirectInclude.path) !== null && _c !== void 0 ? _c : [], path: [] };
121
- const firstSubFieldType = indirectMap &&
122
- (indirectMap === null || indirectMap === void 0 ? void 0 : indirectMap.subFields.length) > 0 &&
123
- ((_d = indirectMap.subFields) === null || _d === void 0 ? void 0 : _d.length) > 0 &&
124
- indirectMap.subFields[0].type;
125
- const expectedType = firstSubFieldType ? info.schema.getType(firstSubFieldType) : type;
126
- if (!(expectedType instanceof graphql_1.GraphQLObjectType)) {
127
- throw new TypeError('Expected returnType to be an object type');
128
- }
129
- for (const selection of selectionSet.selections) {
130
- switch (selection.kind) {
131
- case 'Field':
132
- if (!(type === expectedType)) {
133
- continue;
134
- }
135
- handleField(ctx, info, type.getFields(), selection, includes, counts, mappings, indirectMap);
136
- break;
137
- case 'FragmentSpread':
138
- if (!info.fragments[selection.name.value]) {
139
- throw new Error(`Missing fragment ${selection.name.value}`);
140
- }
141
- if (info.fragments[selection.name.value].typeCondition.name.value !== expectedType.name) {
142
- continue;
143
- }
144
- includesFromSelectionSet(ctx, expectedType, info, includes, counts, mappings, info.fragments[selection.name.value].selectionSet, indirectMap);
145
- break;
146
- case 'InlineFragment':
147
- if (selection.typeCondition && selection.typeCondition.name.value !== expectedType.name) {
148
- continue;
149
- }
150
- includesFromSelectionSet(ctx, selection.typeCondition ? expectedType : type, info, includes, counts, mappings, selection.selectionSet, indirectMap);
151
- break;
152
- default:
153
- throw new Error(`Unexpected selection kind ${selection.kind}`);
154
- }
155
- }
156
- }
157
- exports.includesFromSelectionSet = includesFromSelectionSet;
158
- function queryFromInfo(ctx, info, typeName) {
159
- var _a;
160
- const { fieldNodes } = info;
161
- const type = typeName ? info.schema.getTypeMap()[typeName] : (0, graphql_1.getNamedType)(info.returnType);
162
- const includeType = (0, _1.resolveIndirectType)(type, info);
163
- const includes = {
164
- ...(_a = includeType.extensions) === null || _a === void 0 ? void 0 : _a.pothosPrismaInclude,
165
- };
166
- const counts = {
167
- parent: {},
168
- current: {},
169
- };
170
- const mappings = {};
171
- for (const node of fieldNodes) {
172
- if (!node.selectionSet) {
173
- continue;
174
- }
175
- includesFromSelectionSet(ctx, type, info, includes, counts, mappings, node.selectionSet);
176
- }
177
- if (Object.keys(counts.current).length > 0) {
178
- includes._count = { select: counts.current };
179
- }
180
- if (Object.keys(includes).length > 0) {
181
- if (mappings) {
182
- (0, loader_map_1.setLoaderMappings)(ctx, info.path, mappings);
183
- }
184
- return { include: includes };
185
- }
186
- return {};
187
- }
188
- exports.queryFromInfo = queryFromInfo;
189
- //# sourceMappingURL=map-includes.js.map
@@ -1 +0,0 @@
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,CAAC;AAErC,SAAS,WAAW,CAClB,GAAW,EACX,IAAwB,EACxB,MAAyC,EACzC,SAAoB,EACpB,QAAoB,EACpB,MAAqB,EACrB,QAAwB,EACxB,WAA6B;;IAE7B,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,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AAM,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,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;AApCD,sCAoCC"}
@@ -1,3 +0,0 @@
1
- export declare function deepEqual(left: unknown, right: unknown, ignore?: Set<string>): boolean;
2
- export declare function mergeIncludes(existing: Record<string, unknown> | boolean, newQuery: Record<string, unknown> | boolean): Record<string, unknown> | boolean;
3
- //# sourceMappingURL=merge-includes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge-includes.d.ts","sourceRoot":"","sources":["../../src/util/merge-includes.ts"],"names":[],"mappings":"AACA,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,WAiD5E;AAID,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAC3C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,GAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CA+DnC"}
@@ -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,KAAK,CAAC;iBACd;aACF;YAED,OAAO,I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,CAAC,OAAO,EAAE;QACrB,OAAO,QAAQ,CAAC;KACjB;IAED,MAAM,MAAM,GAA4B;QACtC,GAAI,QAAQ,CAAC,OAAkB;KAChC,CAAC;IAEF,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAkC,CAAC;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAiB,CAAC,CAAC;IAErD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAE/B,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;SACtB;aAAM,IAAI,OAAO,MAAM,KAAK,SAAS,EAAE;YACtC,SAAS;SACV;aAAM,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YAC/B,IAAI,MAAM,EAAE;gBACV,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;aACtB;SACF;aAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE;YACzF,MAAM,SAAS,GAAG,aAAa,CAC7B,OAAkC,EAClC,MAAiC,CAClC,CAAC;YAEF,IAAI,CAAC,SAAS,EAAE;gBACd,OAAO,KAAK,CAAC;aACd;YAED,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;SACzB;KACF;IAED,OAAO,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC;AAlED,sCAkEC"}
package/src/util/index.ts DELETED
@@ -1,26 +0,0 @@
1
- import { GraphQLNamedType, GraphQLResolveInfo } from 'graphql';
2
-
3
- export * from './map-includes';
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
- }
@@ -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
- }