@gqloom/core 0.10.1 → 0.11.1
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/dist/chunk-CTAAG5j7.js +13 -0
- package/dist/context-BtR7FTYT.js +301 -0
- package/dist/context-CnY_BFnk.cjs +415 -0
- package/dist/context.cjs +236 -437
- package/dist/context.d.cts +114 -111
- package/dist/context.d.ts +114 -111
- package/dist/context.js +224 -219
- package/dist/index-DXUAbzqx.d.cts +1254 -0
- package/dist/index-t3pO8DK2.d.ts +1252 -0
- package/dist/index.cjs +1684 -2019
- package/dist/index.d.cts +2 -484
- package/dist/index.d.ts +2 -484
- package/dist/index.js +1608 -1780
- package/package.json +11 -11
- package/dist/chunk-JWAIAFGL.js +0 -220
- package/dist/context-ljWuL8VA.d.cts +0 -772
- package/dist/context-ljWuL8VA.d.ts +0 -772
package/dist/index.cjs
CHANGED
|
@@ -1,2155 +1,1820 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
BaseChainFactory: () => BaseChainFactory,
|
|
24
|
-
ChainResolver: () => ChainResolver,
|
|
25
|
-
EasyDataLoader: () => EasyDataLoader,
|
|
26
|
-
FieldChainFactory: () => FieldChainFactory,
|
|
27
|
-
FieldFactoryWithResolve: () => FieldFactoryWithResolve,
|
|
28
|
-
GraphQLSchemaLoom: () => GraphQLSchemaLoom,
|
|
29
|
-
LoomDataLoader: () => LoomDataLoader,
|
|
30
|
-
LoomObjectType: () => LoomObjectType,
|
|
31
|
-
MutationChainFactory: () => MutationChainFactory,
|
|
32
|
-
MutationFactoryWithResolve: () => MutationFactoryWithResolve,
|
|
33
|
-
OPERATION_OBJECT_NAMES: () => OPERATION_OBJECT_NAMES,
|
|
34
|
-
ObjectChainResolver: () => ObjectChainResolver,
|
|
35
|
-
QueryChainFactory: () => QueryChainFactory,
|
|
36
|
-
QueryFactoryWithResolve: () => QueryFactoryWithResolve,
|
|
37
|
-
SYMBOLS: () => symbols_exports,
|
|
38
|
-
SubscriptionChainFactory: () => SubscriptionChainFactory,
|
|
39
|
-
applyMiddlewares: () => applyMiddlewares,
|
|
40
|
-
assignContextMap: () => assignContextMap,
|
|
41
|
-
capitalize: () => capitalize,
|
|
42
|
-
collectName: () => collectName,
|
|
43
|
-
collectNames: () => collectNames,
|
|
44
|
-
createField: () => createField,
|
|
45
|
-
createInputParser: () => createInputParser,
|
|
46
|
-
createMutation: () => createMutation,
|
|
47
|
-
createQuery: () => createQuery,
|
|
48
|
-
createSubscription: () => createSubscription,
|
|
49
|
-
deepMerge: () => deepMerge,
|
|
50
|
-
defaultSubscriptionResolve: () => defaultSubscriptionResolve,
|
|
51
|
-
ensureInputObjectType: () => ensureInputObjectType,
|
|
52
|
-
ensureInputType: () => ensureInputType,
|
|
53
|
-
ensureInterfaceType: () => ensureInterfaceType,
|
|
54
|
-
field: () => field,
|
|
55
|
-
filterMiddlewares: () => filterMiddlewares,
|
|
56
|
-
getCacheType: () => getCacheType,
|
|
57
|
-
getFieldOptions: () => getFieldOptions,
|
|
58
|
-
getGraphQLType: () => getGraphQLType,
|
|
59
|
-
getMemoizationMap: () => getMemoizationMap,
|
|
60
|
-
getOperationOptions: () => getOperationOptions,
|
|
61
|
-
getResolvingFields: () => getResolvingFields,
|
|
62
|
-
getStandardValue: () => getStandardValue,
|
|
63
|
-
getSubscriptionOptions: () => getSubscriptionOptions,
|
|
64
|
-
initWeaverContext: () => initWeaverContext,
|
|
65
|
-
inputToArgs: () => inputToArgs,
|
|
66
|
-
isOnlyMemoryPayload: () => isOnlyMemoryPayload,
|
|
67
|
-
isSchemaVendorWeaver: () => isSchemaVendorWeaver,
|
|
68
|
-
isSilk: () => isSilk,
|
|
69
|
-
listSilk: () => listSilk,
|
|
70
|
-
loom: () => loom,
|
|
71
|
-
mapValue: () => mapValue,
|
|
72
|
-
markErrorLocation: () => markErrorLocation,
|
|
73
|
-
markLocation: () => markLocation,
|
|
74
|
-
meta: () => meta,
|
|
75
|
-
mutation: () => mutation,
|
|
76
|
-
nonNullSilk: () => nonNullSilk,
|
|
77
|
-
notNullish: () => notNullish,
|
|
78
|
-
nullableSilk: () => nullableSilk,
|
|
79
|
-
onlyMemoization: () => onlyMemoization,
|
|
80
|
-
parseInputValue: () => parseInputValue,
|
|
81
|
-
parseResolvingFields: () => parseResolvingFields,
|
|
82
|
-
parseSilk: () => parseSilk,
|
|
83
|
-
pascalCase: () => pascalCase,
|
|
84
|
-
provideWeaverContext: () => provideWeaverContext,
|
|
85
|
-
query: () => query,
|
|
86
|
-
resolver: () => resolver,
|
|
87
|
-
screamingSnakeCase: () => screamingSnakeCase,
|
|
88
|
-
silk: () => silk,
|
|
89
|
-
subscription: () => subscription,
|
|
90
|
-
toObjMap: () => toObjMap,
|
|
91
|
-
tryIn: () => tryIn,
|
|
92
|
-
weave: () => weave,
|
|
93
|
-
weaverContext: () => weaverContext
|
|
94
|
-
});
|
|
95
|
-
module.exports = __toCommonJS(src_exports);
|
|
1
|
+
const require_context = require('./context-CnY_BFnk.cjs');
|
|
2
|
+
let graphql = require("graphql");
|
|
3
|
+
graphql = require_context.__toESM(graphql);
|
|
96
4
|
|
|
97
|
-
|
|
5
|
+
//#region src/utils/args.ts
|
|
98
6
|
function getOperationOptions(resolveOrOptions) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
return resolveOrOptions;
|
|
7
|
+
if (typeof resolveOrOptions === "function") return { resolve: resolveOrOptions };
|
|
8
|
+
return resolveOrOptions;
|
|
103
9
|
}
|
|
104
10
|
function getSubscriptionOptions(subscribeOrOptions) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
return subscribeOrOptions;
|
|
11
|
+
if (typeof subscribeOrOptions === "function") return { subscribe: subscribeOrOptions };
|
|
12
|
+
return subscribeOrOptions;
|
|
109
13
|
}
|
|
110
14
|
function getFieldOptions({ description, deprecationReason, extensions }, extraExtensions) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
15
|
+
return {
|
|
16
|
+
description,
|
|
17
|
+
deprecationReason,
|
|
18
|
+
extensions: extraExtensions ? {
|
|
19
|
+
...extensions,
|
|
20
|
+
...extraExtensions
|
|
21
|
+
} : extensions
|
|
22
|
+
};
|
|
116
23
|
}
|
|
117
24
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/utils/middleware.ts
|
|
27
|
+
const defaultOperations = [
|
|
28
|
+
"field",
|
|
29
|
+
"mutation",
|
|
30
|
+
"query",
|
|
31
|
+
"subscription.subscribe"
|
|
124
32
|
];
|
|
125
33
|
function applyMiddlewares(options, resolveFunction, middlewares) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
return next(0);
|
|
34
|
+
const next = (index) => {
|
|
35
|
+
if (index >= middlewares.length) return resolveFunction();
|
|
36
|
+
const middleware = middlewares[index];
|
|
37
|
+
const callableOptions = Object.assign(() => next(index + 1), {
|
|
38
|
+
...options,
|
|
39
|
+
next: () => next(index + 1)
|
|
40
|
+
});
|
|
41
|
+
return middleware(callableOptions);
|
|
42
|
+
};
|
|
43
|
+
return next(0);
|
|
138
44
|
}
|
|
139
45
|
function filterMiddlewares(operation, ...middlewareList) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
);
|
|
148
|
-
return acc;
|
|
149
|
-
}, []);
|
|
46
|
+
return middlewareList.reduce((acc, m) => {
|
|
47
|
+
if (!m) return acc;
|
|
48
|
+
acc.push(...ensureArray(m).filter((m$1) => {
|
|
49
|
+
return (m$1.operations ?? defaultOperations).includes(operation);
|
|
50
|
+
}));
|
|
51
|
+
return acc;
|
|
52
|
+
}, []);
|
|
150
53
|
}
|
|
151
54
|
function ensureArray(value) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
return [value];
|
|
55
|
+
if (value != null && typeof value === "object" && Symbol.iterator in value) return Array.from(value);
|
|
56
|
+
return [value];
|
|
156
57
|
}
|
|
157
58
|
|
|
158
|
-
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/utils/object.ts
|
|
61
|
+
/**
|
|
62
|
+
* Creates an object map with the same keys as `map` and values generated by
|
|
63
|
+
* running each value of `record` thru `fn`.
|
|
64
|
+
*/
|
|
159
65
|
function mapValue(record, fn) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
66
|
+
const result = Object.create(null);
|
|
67
|
+
for (const key of Object.keys(record)) {
|
|
68
|
+
const value = fn(record[key], key);
|
|
69
|
+
if (value === SKIP) continue;
|
|
70
|
+
result[key] = value;
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
167
73
|
}
|
|
168
|
-
|
|
74
|
+
const SKIP = Symbol.for("mapValue.skip");
|
|
169
75
|
mapValue.SKIP = SKIP;
|
|
170
76
|
function toObjMap(obj) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
const map = /* @__PURE__ */ Object.create(null);
|
|
178
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
179
|
-
map[key] = value;
|
|
180
|
-
}
|
|
181
|
-
return map;
|
|
77
|
+
if (obj == null) return Object.create(null);
|
|
78
|
+
if (Object.getPrototypeOf(obj) === null) return obj;
|
|
79
|
+
const map = Object.create(null);
|
|
80
|
+
for (const [key, value] of Object.entries(obj)) map[key] = value;
|
|
81
|
+
return map;
|
|
182
82
|
}
|
|
183
83
|
function notNullish(x) {
|
|
184
|
-
|
|
84
|
+
return x != null;
|
|
185
85
|
}
|
|
186
86
|
function deepMerge(...objects) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
} else {
|
|
198
|
-
result[key] = deepMerge(result[key], value);
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
result[key] = value;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
87
|
+
const result = {};
|
|
88
|
+
for (const obj of objects) {
|
|
89
|
+
if (obj == null) continue;
|
|
90
|
+
for (const [key, value] of Object.entries(obj)) if (value !== null && typeof value === "object") if (Array.isArray(value)) {
|
|
91
|
+
if (!Array.isArray(result[key])) result[key] = [];
|
|
92
|
+
result[key] = [...result[key], ...value];
|
|
93
|
+
} else result[key] = deepMerge(result[key], value);
|
|
94
|
+
else result[key] = value;
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
206
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Wraps the provided data in an object with a single key `"~meta"`.
|
|
100
|
+
*
|
|
101
|
+
* @template T - The type of the data to be wrapped.
|
|
102
|
+
* @param {T} data - The data to be wrapped.
|
|
103
|
+
* @returns {{ "~meta": T }} - An object with a single key `"~meta"` containing the provided data.
|
|
104
|
+
* @example
|
|
105
|
+
* const originalData = { key: "value" };
|
|
106
|
+
* const metaData = meta(originalData);
|
|
107
|
+
* console.log(metaData); // Output: { "~meta": { key: "value" } }
|
|
108
|
+
*/
|
|
207
109
|
function meta(data) {
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/utils/parse-resolving-fields.ts
|
|
212
|
-
var import_graphql3 = require("graphql");
|
|
213
|
-
|
|
214
|
-
// src/utils/constants.ts
|
|
215
|
-
var DERIVED_DEPENDENCIES = "loom.derived-from-dependencies";
|
|
216
|
-
|
|
217
|
-
// src/utils/type.ts
|
|
218
|
-
var import_graphql = require("graphql");
|
|
219
|
-
var import_graphql2 = require("graphql");
|
|
220
|
-
function unwrapType(gqlType) {
|
|
221
|
-
if ((0, import_graphql2.isNonNullType)(gqlType)) {
|
|
222
|
-
return unwrapType(gqlType.ofType);
|
|
223
|
-
}
|
|
224
|
-
if ((0, import_graphql.isListType)(gqlType)) {
|
|
225
|
-
return unwrapType(gqlType.ofType);
|
|
226
|
-
}
|
|
227
|
-
return gqlType;
|
|
110
|
+
return { "~meta": data };
|
|
228
111
|
}
|
|
229
112
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const requestedFields = parseResolvingFields(payload.info);
|
|
233
|
-
const derivedFields = /* @__PURE__ */ new Set();
|
|
234
|
-
const derivedDependencies = /* @__PURE__ */ new Set();
|
|
235
|
-
const resolvingObject = unwrapType(payload.info.returnType);
|
|
236
|
-
if ((0, import_graphql3.isObjectType)(resolvingObject)) {
|
|
237
|
-
const objectFields = resolvingObject.getFields();
|
|
238
|
-
for (const requestedFieldName of requestedFields) {
|
|
239
|
-
const field2 = objectFields[requestedFieldName];
|
|
240
|
-
if (field2) {
|
|
241
|
-
const deps = field2.extensions?.[DERIVED_DEPENDENCIES];
|
|
242
|
-
if (deps && Array.isArray(deps) && deps.length > 0) {
|
|
243
|
-
derivedFields.add(requestedFieldName);
|
|
244
|
-
for (const d of deps) derivedDependencies.add(d);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const selectedFields = new Set(requestedFields);
|
|
250
|
-
for (const f of derivedFields) selectedFields.delete(f);
|
|
251
|
-
for (const d of derivedDependencies) selectedFields.add(d);
|
|
252
|
-
return { requestedFields, derivedFields, derivedDependencies, selectedFields };
|
|
253
|
-
}
|
|
254
|
-
function parseResolvingFields(info, maxDepth = 1) {
|
|
255
|
-
return new ResolvingFieldsParser(info, maxDepth).parse();
|
|
256
|
-
}
|
|
257
|
-
var ResolvingFieldsParser = class {
|
|
258
|
-
/** Store unique field paths */
|
|
259
|
-
fields = /* @__PURE__ */ new Set();
|
|
260
|
-
/** Track visited fragments to prevent circular references */
|
|
261
|
-
visitedFragments = /* @__PURE__ */ new Set();
|
|
262
|
-
/** The GraphQL resolve info object */
|
|
263
|
-
info;
|
|
264
|
-
/** Maximum depth of nested fields to parse */
|
|
265
|
-
maxDepth;
|
|
266
|
-
constructor(info, maxDepth) {
|
|
267
|
-
this.info = info;
|
|
268
|
-
this.maxDepth = maxDepth;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Parses the GraphQL resolve info to extract all requested fields.
|
|
272
|
-
* @returns A Set of field paths
|
|
273
|
-
*/
|
|
274
|
-
parse() {
|
|
275
|
-
for (const fieldNode of this.info.fieldNodes) {
|
|
276
|
-
this.collectFields(fieldNode.selectionSet);
|
|
277
|
-
}
|
|
278
|
-
return this.fields;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Recursively collects fields from a selection set.
|
|
282
|
-
* Handles fields, inline fragments, and fragment spreads.
|
|
283
|
-
*
|
|
284
|
-
* @param selectionSet - The selection set to process
|
|
285
|
-
* @param parentPath - The path of the parent field (for nested fields)
|
|
286
|
-
* @param currentDepth - Current depth of recursion
|
|
287
|
-
*/
|
|
288
|
-
collectFields(selectionSet, parentPath = "", currentDepth = 0) {
|
|
289
|
-
if (!selectionSet?.selections.length || currentDepth >= this.maxDepth)
|
|
290
|
-
return;
|
|
291
|
-
for (const selection of selectionSet.selections) {
|
|
292
|
-
if (!this.shouldIncludeNode(selection)) continue;
|
|
293
|
-
switch (selection.kind) {
|
|
294
|
-
case import_graphql3.Kind.FIELD: {
|
|
295
|
-
const fieldName = selection.name.value;
|
|
296
|
-
const fieldPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
|
|
297
|
-
this.fields.add(fieldPath);
|
|
298
|
-
const hasSelectionSet = selection.selectionSet != null;
|
|
299
|
-
if (hasSelectionSet) {
|
|
300
|
-
this.collectFields(
|
|
301
|
-
selection.selectionSet,
|
|
302
|
-
fieldPath,
|
|
303
|
-
currentDepth + 1
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
case import_graphql3.Kind.INLINE_FRAGMENT: {
|
|
309
|
-
if (selection.selectionSet) {
|
|
310
|
-
this.collectFields(selection.selectionSet, parentPath, currentDepth);
|
|
311
|
-
}
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
case import_graphql3.Kind.FRAGMENT_SPREAD: {
|
|
315
|
-
const fragmentName = selection.name.value;
|
|
316
|
-
if (this.visitedFragments.has(fragmentName)) continue;
|
|
317
|
-
this.visitedFragments.add(fragmentName);
|
|
318
|
-
const fragment = this.info.fragments[fragmentName];
|
|
319
|
-
if (fragment) {
|
|
320
|
-
this.collectFields(fragment.selectionSet, parentPath, currentDepth);
|
|
321
|
-
}
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Extracts the boolean value from a directive's 'if' argument.
|
|
329
|
-
* Handles both literal boolean values and variables.
|
|
330
|
-
*
|
|
331
|
-
* @param directive - The directive node to extract value from
|
|
332
|
-
* @returns The boolean value of the directive's condition
|
|
333
|
-
*/
|
|
334
|
-
getDirectiveValue(directive) {
|
|
335
|
-
const ifArg = directive.arguments?.find(
|
|
336
|
-
(arg) => arg.name.value === "if"
|
|
337
|
-
);
|
|
338
|
-
if (!ifArg) return true;
|
|
339
|
-
const value = ifArg.value;
|
|
340
|
-
if (value.kind === import_graphql3.Kind.BOOLEAN) {
|
|
341
|
-
return value.value;
|
|
342
|
-
}
|
|
343
|
-
if (value.kind === import_graphql3.Kind.VARIABLE) {
|
|
344
|
-
const variableName = value.name.value;
|
|
345
|
-
const variableValue = this.info.variableValues?.[variableName];
|
|
346
|
-
return variableValue === true;
|
|
347
|
-
}
|
|
348
|
-
return true;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Determines if a selection node should be included based on its directives.
|
|
352
|
-
* Handles both @include and @skip directives.
|
|
353
|
-
*
|
|
354
|
-
* @param node - The selection node to check
|
|
355
|
-
* @returns Whether the node should be included
|
|
356
|
-
*/
|
|
357
|
-
shouldIncludeNode(node) {
|
|
358
|
-
if (!node.directives?.length) return true;
|
|
359
|
-
return node.directives.every((directive) => {
|
|
360
|
-
const isIncludeDirective = directive.name.value === "include";
|
|
361
|
-
if (isIncludeDirective) {
|
|
362
|
-
return this.getDirectiveValue(directive);
|
|
363
|
-
}
|
|
364
|
-
if (directive.name.value === "skip") {
|
|
365
|
-
return !this.getDirectiveValue(directive);
|
|
366
|
-
}
|
|
367
|
-
return true;
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
// src/utils/string.ts
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/utils/string.ts
|
|
373
115
|
function pascalCase(str) {
|
|
374
|
-
|
|
375
|
-
(word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)
|
|
376
|
-
).join("");
|
|
116
|
+
return str.split(/[\s-_]+/).map((word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
377
117
|
}
|
|
378
118
|
function capitalize(str) {
|
|
379
|
-
|
|
119
|
+
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
380
120
|
}
|
|
381
121
|
function screamingSnakeCase(str) {
|
|
382
|
-
|
|
122
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").split(/[\s-_]+/).map((word) => word.toUpperCase()).join("_");
|
|
383
123
|
}
|
|
384
124
|
|
|
385
|
-
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/utils/error.ts
|
|
386
127
|
function markErrorLocation(error, ...locations) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
return error;
|
|
128
|
+
if (error instanceof Error) error.message = markLocation(error.message, ...locations);
|
|
129
|
+
return error;
|
|
391
130
|
}
|
|
392
131
|
function tryIn(func, ...locations) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
132
|
+
try {
|
|
133
|
+
return func();
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw markErrorLocation(error, ...locations);
|
|
136
|
+
}
|
|
398
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* mark message with location
|
|
140
|
+
* @param message origin message
|
|
141
|
+
* @param locations where error happened
|
|
142
|
+
* @returns message with location
|
|
143
|
+
* @example markLocation("error", "banana") // "[banana] hello"
|
|
144
|
+
* @example markLocation("error", fruit, banana) // "[fruit.banana] error"
|
|
145
|
+
* @example markLocation("[banana] error", "fruit") // "[fruit.banana] error"
|
|
146
|
+
* @example markLocation("[fruit.banana] error", "favorite") // "[favorite.fruit.banana] error"
|
|
147
|
+
*/
|
|
399
148
|
function markLocation(message, ...locations) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
return [void 0, message];
|
|
408
|
-
})();
|
|
409
|
-
const combinedLocation = locations.concat(existingPrefix ? [existingPrefix] : []).join(".");
|
|
410
|
-
return `[${combinedLocation}] ${newMessage}`;
|
|
149
|
+
if (locations.length === 0) return message;
|
|
150
|
+
const [existingPrefix, newMessage] = (() => {
|
|
151
|
+
const match = /^\[(.*?)\]/.exec(message);
|
|
152
|
+
if (match) return [match[1], message.slice(match[0].length).trim()];
|
|
153
|
+
return [void 0, message];
|
|
154
|
+
})();
|
|
155
|
+
return `[${locations.concat(existingPrefix ? [existingPrefix] : []).join(".")}] ${newMessage}`;
|
|
411
156
|
}
|
|
412
157
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/utils/loader.ts
|
|
160
|
+
/**
|
|
161
|
+
* GraphQL Loom built-in data loader.
|
|
162
|
+
*/
|
|
163
|
+
var LoomDataLoader = class LoomDataLoader {
|
|
164
|
+
results;
|
|
165
|
+
resolvers;
|
|
166
|
+
constructor() {
|
|
167
|
+
this.results = /* @__PURE__ */ new Map();
|
|
168
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Load data for a given key.
|
|
172
|
+
* @param key - The key to load data for.
|
|
173
|
+
* @returns A promise that resolves to the loaded data.
|
|
174
|
+
*/
|
|
175
|
+
load(key) {
|
|
176
|
+
const existing = this.results.get(key);
|
|
177
|
+
if (existing) return existing;
|
|
178
|
+
const promise = new Promise((resolve, reject) => {
|
|
179
|
+
this.resolvers.set(key, [resolve, reject]);
|
|
180
|
+
this.nextTickBatchLoad();
|
|
181
|
+
});
|
|
182
|
+
this.results.set(key, promise);
|
|
183
|
+
return promise;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Clear the cache and reset the loader.
|
|
187
|
+
*/
|
|
188
|
+
clear() {
|
|
189
|
+
this.results = /* @__PURE__ */ new Map();
|
|
190
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
191
|
+
}
|
|
192
|
+
async executeBatchLoad() {
|
|
193
|
+
if (this.resolvers.size === 0) return;
|
|
194
|
+
const resolvers = this.resolvers;
|
|
195
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
196
|
+
const keys = Array.from(resolvers.keys());
|
|
197
|
+
try {
|
|
198
|
+
const list = await this.batchLoad(keys);
|
|
199
|
+
for (let i = 0; i < list.length; i++) {
|
|
200
|
+
const data = list[i];
|
|
201
|
+
const [resolve, reject] = resolvers.get(keys[i]) ?? [];
|
|
202
|
+
if (data instanceof Error) reject?.(data);
|
|
203
|
+
else resolve?.(data);
|
|
204
|
+
}
|
|
205
|
+
} catch (error) {
|
|
206
|
+
for (const key of keys) {
|
|
207
|
+
const reject = resolvers.get(key)?.[1];
|
|
208
|
+
reject?.(error);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
nextTickPromise;
|
|
213
|
+
nextTickBatchLoad() {
|
|
214
|
+
const load = async () => {
|
|
215
|
+
try {
|
|
216
|
+
while (this.resolvers.size > 0) {
|
|
217
|
+
await LoomDataLoader.nextTick();
|
|
218
|
+
await this.executeBatchLoad();
|
|
219
|
+
}
|
|
220
|
+
} finally {
|
|
221
|
+
this.nextTickPromise = void 0;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
this.nextTickPromise ??= load();
|
|
225
|
+
return this.nextTickPromise;
|
|
226
|
+
}
|
|
227
|
+
static nextTick() {
|
|
228
|
+
return new Promise((resolve) => setTimeout(resolve));
|
|
229
|
+
}
|
|
484
230
|
};
|
|
485
231
|
var EasyDataLoader = class extends LoomDataLoader {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
232
|
+
batchLoad(keys) {
|
|
233
|
+
return this.batchLoadFn(keys);
|
|
234
|
+
}
|
|
235
|
+
constructor(batchLoadFn) {
|
|
236
|
+
super();
|
|
237
|
+
this.batchLoadFn = batchLoadFn;
|
|
238
|
+
}
|
|
493
239
|
};
|
|
494
240
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
FIELD_HIDDEN: () => FIELD_HIDDEN,
|
|
500
|
-
GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
|
|
501
|
-
IS_RESOLVER: () => IS_RESOLVER,
|
|
502
|
-
RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
|
|
503
|
-
WEAVER_CONFIG: () => WEAVER_CONFIG
|
|
504
|
-
});
|
|
505
|
-
var GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
|
|
506
|
-
var WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
|
|
507
|
-
var RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
|
|
508
|
-
var IS_RESOLVER = Symbol.for("gqloom.is-resolver");
|
|
509
|
-
var CONTEXT_MAP_KEY = Symbol.for("gqloom.context-map");
|
|
510
|
-
var FIELD_HIDDEN = false;
|
|
511
|
-
|
|
512
|
-
// src/utils/context.ts
|
|
513
|
-
function onlyMemoization() {
|
|
514
|
-
return { memoization: /* @__PURE__ */ new WeakMap(), isMemoization: true };
|
|
515
|
-
}
|
|
516
|
-
function isOnlyMemoryPayload(payload) {
|
|
517
|
-
return payload.isMemoization === true;
|
|
518
|
-
}
|
|
519
|
-
function getMemoizationMap(payload) {
|
|
520
|
-
if (isOnlyMemoryPayload(payload)) return payload.memoization;
|
|
521
|
-
if (typeof payload.context === "undefined") {
|
|
522
|
-
Object.defineProperty(payload, "context", { value: {} });
|
|
523
|
-
}
|
|
524
|
-
return assignContextMap(payload.context);
|
|
525
|
-
}
|
|
526
|
-
function assignContextMap(target) {
|
|
527
|
-
target[CONTEXT_MAP_KEY] ??= /* @__PURE__ */ new WeakMap();
|
|
528
|
-
return target[CONTEXT_MAP_KEY];
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// src/resolver/silk.ts
|
|
532
|
-
var import_graphql5 = require("graphql");
|
|
533
|
-
|
|
534
|
-
// src/schema/weaver-context.ts
|
|
535
|
-
var import_graphql4 = require("graphql");
|
|
536
|
-
var ref;
|
|
537
|
-
var names = /* @__PURE__ */ new WeakMap();
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/schema/weaver-context.ts
|
|
243
|
+
let ref;
|
|
244
|
+
const names = /* @__PURE__ */ new WeakMap();
|
|
538
245
|
function initWeaverContext() {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
vendorWeavers: /* @__PURE__ */ new Map()
|
|
569
|
-
};
|
|
246
|
+
return {
|
|
247
|
+
id: initWeaverContext.increasingID++,
|
|
248
|
+
loomObjectMap: /* @__PURE__ */ new Map(),
|
|
249
|
+
loomUnionMap: /* @__PURE__ */ new Map(),
|
|
250
|
+
inputMap: /* @__PURE__ */ new Map(),
|
|
251
|
+
interfaceMap: /* @__PURE__ */ new Map(),
|
|
252
|
+
configs: /* @__PURE__ */ new Map(),
|
|
253
|
+
getConfig(key) {
|
|
254
|
+
return this.configs.get(key);
|
|
255
|
+
},
|
|
256
|
+
setConfig(config) {
|
|
257
|
+
const key = config[require_context.WEAVER_CONFIG];
|
|
258
|
+
this.configs.set(key, config);
|
|
259
|
+
},
|
|
260
|
+
deleteConfig(key) {
|
|
261
|
+
this.configs.delete(key);
|
|
262
|
+
},
|
|
263
|
+
names,
|
|
264
|
+
namedTypes: /* @__PURE__ */ new Map(),
|
|
265
|
+
memoNamedType(gqlTypeValue) {
|
|
266
|
+
const gqlType = gqlTypeValue;
|
|
267
|
+
if ((0, graphql.isObjectType)(gqlType) || (0, graphql.isUnionType)(gqlType) || (0, graphql.isEnumType)(gqlType) || (0, graphql.isScalarType)(gqlType)) this.namedTypes.set(gqlType.name, gqlType);
|
|
268
|
+
return gqlTypeValue;
|
|
269
|
+
},
|
|
270
|
+
getNamedType(name) {
|
|
271
|
+
return this.namedTypes.get(name);
|
|
272
|
+
},
|
|
273
|
+
vendorWeavers: /* @__PURE__ */ new Map()
|
|
274
|
+
};
|
|
570
275
|
}
|
|
571
276
|
initWeaverContext.increasingID = 1;
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
277
|
+
const weaverContext = {
|
|
278
|
+
get id() {
|
|
279
|
+
return ref?.id;
|
|
280
|
+
},
|
|
281
|
+
get loomObjectMap() {
|
|
282
|
+
return ref?.loomObjectMap;
|
|
283
|
+
},
|
|
284
|
+
get loomUnionMap() {
|
|
285
|
+
return ref?.loomUnionMap;
|
|
286
|
+
},
|
|
287
|
+
get inputMap() {
|
|
288
|
+
return ref?.inputMap;
|
|
289
|
+
},
|
|
290
|
+
get interfaceMap() {
|
|
291
|
+
return ref?.interfaceMap;
|
|
292
|
+
},
|
|
293
|
+
get configs() {
|
|
294
|
+
return ref?.configs;
|
|
295
|
+
},
|
|
296
|
+
get vendorWeavers() {
|
|
297
|
+
return ref?.vendorWeavers;
|
|
298
|
+
},
|
|
299
|
+
getConfig(key) {
|
|
300
|
+
return ref?.getConfig(key);
|
|
301
|
+
},
|
|
302
|
+
setConfig(config) {
|
|
303
|
+
ref?.setConfig(config);
|
|
304
|
+
},
|
|
305
|
+
deleteConfig(key) {
|
|
306
|
+
ref?.deleteConfig(key);
|
|
307
|
+
},
|
|
308
|
+
get value() {
|
|
309
|
+
return ref;
|
|
310
|
+
},
|
|
311
|
+
useConfig(config, callback) {
|
|
312
|
+
const context = weaverContext.value ?? initWeaverContext();
|
|
313
|
+
context.setConfig(config);
|
|
314
|
+
const result = provideWeaverContext(callback, context);
|
|
315
|
+
context.deleteConfig(config[require_context.WEAVER_CONFIG]);
|
|
316
|
+
return result;
|
|
317
|
+
},
|
|
318
|
+
names,
|
|
319
|
+
getNamedType(name) {
|
|
320
|
+
return ref?.getNamedType(name);
|
|
321
|
+
},
|
|
322
|
+
memoNamedType(gqlType) {
|
|
323
|
+
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
324
|
+
},
|
|
325
|
+
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
326
|
+
getGraphQLType(origin) {
|
|
327
|
+
return this.GraphQLTypes.get(origin);
|
|
328
|
+
},
|
|
329
|
+
memoGraphQLType(origin, gqlType) {
|
|
330
|
+
this.GraphQLTypes.set(origin, gqlType);
|
|
331
|
+
return gqlType;
|
|
332
|
+
}
|
|
628
333
|
};
|
|
629
334
|
function provideWeaverContext(func, value) {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
335
|
+
const lastRef = ref;
|
|
336
|
+
ref = value;
|
|
337
|
+
try {
|
|
338
|
+
return func();
|
|
339
|
+
} finally {
|
|
340
|
+
ref = lastRef;
|
|
341
|
+
}
|
|
637
342
|
}
|
|
638
343
|
provideWeaverContext.inherit = (func) => {
|
|
639
|
-
|
|
640
|
-
|
|
344
|
+
const weaverContextRef = weaverContext.value;
|
|
345
|
+
return () => provideWeaverContext(func, weaverContextRef);
|
|
641
346
|
};
|
|
347
|
+
/**
|
|
348
|
+
* collect names for schemas
|
|
349
|
+
* @param namesList - names to collect
|
|
350
|
+
* @returns namesRecord
|
|
351
|
+
*/
|
|
642
352
|
function collectNames(...namesList) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
}
|
|
650
|
-
return namesRecord;
|
|
353
|
+
const namesRecord = {};
|
|
354
|
+
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
355
|
+
names.set(schema, name);
|
|
356
|
+
namesRecord[name] = schema;
|
|
357
|
+
}
|
|
358
|
+
return namesRecord;
|
|
651
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* collect name for schema
|
|
362
|
+
* @param name - name for
|
|
363
|
+
* @param schema - schema to be named
|
|
364
|
+
* @returns schema
|
|
365
|
+
*/
|
|
652
366
|
function collectName(name, schema) {
|
|
653
|
-
|
|
654
|
-
|
|
367
|
+
names.set(schema, name);
|
|
368
|
+
return schema;
|
|
655
369
|
}
|
|
656
370
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
};
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/resolver/silk.ts
|
|
373
|
+
function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
|
|
374
|
+
return {
|
|
375
|
+
[require_context.GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
376
|
+
"~standard": {
|
|
377
|
+
version: 1,
|
|
378
|
+
vendor: "gqloom.silk",
|
|
379
|
+
validate
|
|
380
|
+
}
|
|
381
|
+
};
|
|
669
382
|
}
|
|
670
383
|
silk.parse = parseSilk;
|
|
671
384
|
silk.getType = getGraphQLType;
|
|
672
385
|
silk.nonNull = nonNullSilk;
|
|
673
386
|
silk.list = listSilk;
|
|
674
387
|
silk.nullable = nullableSilk;
|
|
388
|
+
/**
|
|
389
|
+
* Non-nullable Silk.
|
|
390
|
+
*/
|
|
675
391
|
function nonNullSilk(origin) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
};
|
|
392
|
+
return {
|
|
393
|
+
...origin,
|
|
394
|
+
[require_context.GET_GRAPHQL_TYPE]: () => {
|
|
395
|
+
const originType = getGraphQLType(origin);
|
|
396
|
+
if (originType instanceof graphql.GraphQLNonNull) return originType;
|
|
397
|
+
else return new graphql.GraphQLNonNull(originType);
|
|
398
|
+
}
|
|
399
|
+
};
|
|
687
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* List Silk.
|
|
403
|
+
*/
|
|
688
404
|
function listSilk(origin) {
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
return new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(originType));
|
|
700
|
-
}
|
|
701
|
-
};
|
|
405
|
+
return {
|
|
406
|
+
...origin,
|
|
407
|
+
[require_context.GET_GRAPHQL_TYPE]: () => {
|
|
408
|
+
let originType = getGraphQLType(origin);
|
|
409
|
+
if (originType instanceof graphql.GraphQLNonNull && originType.ofType instanceof graphql.GraphQLList) originType = originType.ofType.ofType;
|
|
410
|
+
if (originType instanceof graphql.GraphQLList) originType = originType.ofType;
|
|
411
|
+
return new graphql.GraphQLNonNull(new graphql.GraphQLList(originType));
|
|
412
|
+
}
|
|
413
|
+
};
|
|
702
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Nullable Silk.
|
|
417
|
+
*/
|
|
703
418
|
function nullableSilk(origin) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
};
|
|
419
|
+
return {
|
|
420
|
+
...origin,
|
|
421
|
+
[require_context.GET_GRAPHQL_TYPE]: () => {
|
|
422
|
+
const originType = getGraphQLType(origin);
|
|
423
|
+
if (originType instanceof graphql.GraphQLNonNull) return originType.ofType;
|
|
424
|
+
else return originType;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
715
427
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
428
|
+
/**
|
|
429
|
+
* Get GraphQL Output Type from Silk.
|
|
430
|
+
* @param silk GraphQL Silk
|
|
431
|
+
* @returns GraphQL Output Type
|
|
432
|
+
*/
|
|
433
|
+
function getGraphQLType(silk$1) {
|
|
434
|
+
if (require_context.GET_GRAPHQL_TYPE in silk$1 && silk$1[require_context.GET_GRAPHQL_TYPE] != null) return silk$1[require_context.GET_GRAPHQL_TYPE]();
|
|
435
|
+
const vendorWeavers = weaverContext.vendorWeavers;
|
|
436
|
+
if (vendorWeavers == null) throw new Error("Schema Weaver is not initialized");
|
|
437
|
+
const weaver = vendorWeavers.get(silk$1["~standard"].vendor);
|
|
438
|
+
if (weaver == null) throw new Error(`Schema Weaver for ${silk$1["~standard"].vendor} is not found`);
|
|
439
|
+
return weaver.getGraphQLType(silk$1);
|
|
727
440
|
}
|
|
728
|
-
|
|
729
|
-
|
|
441
|
+
/**
|
|
442
|
+
* Validate and transform input to output
|
|
443
|
+
* @param silk silk GraphQL Silk
|
|
444
|
+
* @param input
|
|
445
|
+
* @returns output
|
|
446
|
+
*/
|
|
447
|
+
function parseSilk(silk$1, input) {
|
|
448
|
+
return silk$1["~standard"].validate(input);
|
|
730
449
|
}
|
|
731
450
|
function isSilk(target) {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
451
|
+
if (typeof target !== "object" && typeof target !== "function") return false;
|
|
452
|
+
if (target == null) return false;
|
|
453
|
+
if (require_context.GET_GRAPHQL_TYPE in target) return true;
|
|
454
|
+
if (!("~standard" in target)) return false;
|
|
455
|
+
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
737
456
|
}
|
|
738
457
|
|
|
739
|
-
|
|
740
|
-
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region src/resolver/input.ts
|
|
741
460
|
function createInputParser(schema, value) {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
value: () => result = void 0
|
|
761
|
-
});
|
|
762
|
-
return parse;
|
|
461
|
+
let result;
|
|
462
|
+
const parse = async () => {
|
|
463
|
+
if (result !== void 0) return result;
|
|
464
|
+
result = await parseInputValue(schema, value);
|
|
465
|
+
return result;
|
|
466
|
+
};
|
|
467
|
+
Object.assign(parse, {
|
|
468
|
+
schema,
|
|
469
|
+
value
|
|
470
|
+
});
|
|
471
|
+
Object.defineProperty(parse, "result", {
|
|
472
|
+
get: () => result,
|
|
473
|
+
set: (value$1) => result = value$1
|
|
474
|
+
});
|
|
475
|
+
Object.defineProperty(parse, "getResult", { value: async () => getStandardValue(await parse()) });
|
|
476
|
+
Object.defineProperty(parse, "setResult", { value: (value$1) => result = { value: value$1 } });
|
|
477
|
+
Object.defineProperty(parse, "clearResult", { value: () => result = void 0 });
|
|
478
|
+
return parse;
|
|
763
479
|
}
|
|
764
480
|
function parseInputValue(inputSchema, input) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
if (isSilk(inputSchema)) {
|
|
769
|
-
return inputSchema["~standard"].validate(input);
|
|
770
|
-
}
|
|
771
|
-
return parseInputEntries(inputSchema, input);
|
|
481
|
+
if (inputSchema === void 0) return { value: input };
|
|
482
|
+
if (isSilk(inputSchema)) return inputSchema["~standard"].validate(input);
|
|
483
|
+
return parseInputEntries(inputSchema, input);
|
|
772
484
|
}
|
|
773
485
|
async function parseInputEntries(inputSchema, input = {}) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
})
|
|
786
|
-
);
|
|
787
|
-
return { value: result, ...issues.length > 0 ? { issues } : null };
|
|
486
|
+
const result = {};
|
|
487
|
+
const issues = [];
|
|
488
|
+
await Promise.all(Object.entries(inputSchema).map(async ([key, value]) => {
|
|
489
|
+
const res = await value["~standard"].validate(input[key]);
|
|
490
|
+
if ("value" in res) result[key] = res.value;
|
|
491
|
+
if (res.issues) issues.push(...res.issues.slice());
|
|
492
|
+
}));
|
|
493
|
+
return {
|
|
494
|
+
value: result,
|
|
495
|
+
...issues.length > 0 ? { issues } : null
|
|
496
|
+
};
|
|
788
497
|
}
|
|
789
498
|
function getStandardValue(result) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
if ("value" in result) return result.value;
|
|
798
|
-
else throw new import_graphql6.GraphQLError("Invalid input");
|
|
499
|
+
if (result == null) return result;
|
|
500
|
+
const { issues } = result;
|
|
501
|
+
if (issues?.length) throw new graphql.GraphQLError(issues?.[0]?.message ?? "Invalid input", { extensions: { issues } });
|
|
502
|
+
if ("value" in result) return result.value;
|
|
503
|
+
else throw new graphql.GraphQLError("Invalid input");
|
|
799
504
|
}
|
|
800
505
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
506
|
+
//#endregion
|
|
507
|
+
//#region src/resolver/resolver-chain-factory.ts
|
|
508
|
+
/**
|
|
509
|
+
* Base class for all chain factories
|
|
510
|
+
* @template TField - The type of field being created
|
|
511
|
+
*/
|
|
512
|
+
var BaseChainFactory = class BaseChainFactory {
|
|
513
|
+
/**
|
|
514
|
+
* Returns the available methods for the chain factory
|
|
515
|
+
*/
|
|
516
|
+
static methods() {
|
|
517
|
+
return {
|
|
518
|
+
description: BaseChainFactory.prototype.description,
|
|
519
|
+
deprecationReason: BaseChainFactory.prototype.deprecationReason,
|
|
520
|
+
extensions: BaseChainFactory.prototype.extensions
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Creates a new instance of the chain factory
|
|
525
|
+
* @param options - Configuration options for the factory
|
|
526
|
+
*/
|
|
527
|
+
constructor(options) {
|
|
528
|
+
this.options = options;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Sets the description for the field
|
|
532
|
+
* @param description - The description text
|
|
533
|
+
*/
|
|
534
|
+
description(description) {
|
|
535
|
+
return this.clone({ description });
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Sets the deprecation reason for the field
|
|
539
|
+
* @param deprecationReason - The reason for deprecation
|
|
540
|
+
*/
|
|
541
|
+
deprecationReason(deprecationReason) {
|
|
542
|
+
return this.clone({ deprecationReason });
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Sets custom extensions for the field
|
|
546
|
+
* @param extensions - Custom extensions to add
|
|
547
|
+
*/
|
|
548
|
+
extensions(extensions) {
|
|
549
|
+
return this.clone({ extensions });
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Adds middleware functions to the field
|
|
553
|
+
* @param middlewares - Middleware functions to add
|
|
554
|
+
*/
|
|
555
|
+
use(...middlewares) {
|
|
556
|
+
return this.clone({ middlewares: [...this.options?.middlewares ?? [], ...middlewares] });
|
|
557
|
+
}
|
|
850
558
|
};
|
|
851
|
-
var FieldLoader = class
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
559
|
+
var FieldLoader = class FieldLoader extends LoomDataLoader {
|
|
560
|
+
static getByPath(payload, resolve, getByPath = true) {
|
|
561
|
+
if (!payload) return new FieldLoader(resolve);
|
|
562
|
+
const memoMap = require_context.getMemoizationMap(payload);
|
|
563
|
+
if (!getByPath) {
|
|
564
|
+
const loader = memoMap.get(resolve) ?? new FieldLoader(resolve);
|
|
565
|
+
memoMap.set(resolve, loader);
|
|
566
|
+
return loader;
|
|
567
|
+
}
|
|
568
|
+
const fullPath = [];
|
|
569
|
+
let path = payload.info.path;
|
|
570
|
+
while (path) {
|
|
571
|
+
fullPath.push(path);
|
|
572
|
+
path = path.prev;
|
|
573
|
+
}
|
|
574
|
+
const pathKey = fullPath.reverse().map((p) => typeof p.key === "number" ? "[n]" : p.key).join(".");
|
|
575
|
+
const fieldLoaders = memoMap.get(resolve) ?? /* @__PURE__ */ new Map();
|
|
576
|
+
memoMap.set(resolve, fieldLoaders);
|
|
577
|
+
const fieldLoader = fieldLoaders.get(pathKey) ?? new FieldLoader(resolve);
|
|
578
|
+
fieldLoaders.set(pathKey, fieldLoader);
|
|
579
|
+
return fieldLoader;
|
|
580
|
+
}
|
|
581
|
+
constructor(resolve) {
|
|
582
|
+
super();
|
|
583
|
+
this.resolve = resolve;
|
|
584
|
+
}
|
|
585
|
+
batchLoad(args) {
|
|
586
|
+
const parents = args.map(([parent]) => parent);
|
|
587
|
+
const payloads = args.map(([, , payload]) => payload);
|
|
588
|
+
return this.resolve(parents, args[0]?.[1], payloads);
|
|
589
|
+
}
|
|
882
590
|
};
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
591
|
+
/**
|
|
592
|
+
* Factory for creating field resolvers with chainable configuration
|
|
593
|
+
* @template TOutput - The output type of the field
|
|
594
|
+
* @template TInput - The input type of the field
|
|
595
|
+
* @template TDependencies - The dependencies of the field
|
|
596
|
+
*/
|
|
597
|
+
var FieldChainFactory = class FieldChainFactory extends BaseChainFactory {
|
|
598
|
+
/**
|
|
599
|
+
* Returns the available methods for the field chain factory
|
|
600
|
+
*/
|
|
601
|
+
static methods() {
|
|
602
|
+
return {
|
|
603
|
+
...BaseChainFactory.methods(),
|
|
604
|
+
output: FieldChainFactory.prototype.output,
|
|
605
|
+
input: FieldChainFactory.prototype.input,
|
|
606
|
+
resolve: FieldChainFactory.prototype.resolve,
|
|
607
|
+
clone: FieldChainFactory.prototype.clone
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Creates a clone of the current factory with new options
|
|
612
|
+
* @param options - New options to apply to the clone
|
|
613
|
+
*/
|
|
614
|
+
clone(options) {
|
|
615
|
+
return new FieldChainFactory({
|
|
616
|
+
...this.options,
|
|
617
|
+
...options
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Sets the output type for the field
|
|
622
|
+
* @template TOutputNew - The new output type
|
|
623
|
+
* @param output - The output type definition
|
|
624
|
+
*/
|
|
625
|
+
output(output) {
|
|
626
|
+
return new FieldChainFactory({
|
|
627
|
+
...this.options,
|
|
628
|
+
output
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Sets the input type for the field
|
|
633
|
+
* @template TInputNew - The new input type
|
|
634
|
+
* @param input - The input type definition
|
|
635
|
+
*/
|
|
636
|
+
input(input) {
|
|
637
|
+
return new FieldChainFactory({
|
|
638
|
+
...this.options,
|
|
639
|
+
input
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Specifies the dependencies for the field
|
|
644
|
+
* @template TDependencies - The dependencies type
|
|
645
|
+
* @param dependencies - The dependencies to add
|
|
646
|
+
*/
|
|
647
|
+
derivedFrom(...dependencies) {
|
|
648
|
+
return this.clone({ dependencies });
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Sets the resolve function for the field
|
|
652
|
+
* @template TParent - The parent type
|
|
653
|
+
* @param resolve - The resolve function
|
|
654
|
+
*/
|
|
655
|
+
resolve(resolve) {
|
|
656
|
+
if (!this.options?.output) throw new Error("Output is required");
|
|
657
|
+
return createField(this.options.output, {
|
|
658
|
+
...this.options,
|
|
659
|
+
resolve
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Creates a field resolver that uses DataLoader for batch loading data.
|
|
664
|
+
* This method is particularly useful for optimizing performance when dealing with multiple data requests
|
|
665
|
+
* by batching them together and handling caching automatically.
|
|
666
|
+
*
|
|
667
|
+
* @template TParent - The parent type that extends GraphQLSilk
|
|
668
|
+
* @param resolve - A function that handles batch loading of data.
|
|
669
|
+
* @returns A GraphQL field resolver that implements batch loading
|
|
670
|
+
*/
|
|
671
|
+
load(resolve) {
|
|
672
|
+
if (!this.options?.output) throw new Error("Output is required");
|
|
673
|
+
return createField(this.options.output, {
|
|
674
|
+
...this.options,
|
|
675
|
+
resolve: (parent, input, payload) => {
|
|
676
|
+
return FieldLoader.getByPath(payload, resolve, this.options?.input != null).load([
|
|
677
|
+
parent,
|
|
678
|
+
input,
|
|
679
|
+
payload
|
|
680
|
+
]);
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
962
684
|
};
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
685
|
+
/**
|
|
686
|
+
* Factory for creating query resolvers with chainable configuration
|
|
687
|
+
* @template TOutput - The output type of the query
|
|
688
|
+
* @template TInput - The input type of the query
|
|
689
|
+
*/
|
|
690
|
+
var QueryChainFactory = class QueryChainFactory extends BaseChainFactory {
|
|
691
|
+
/**
|
|
692
|
+
* Returns the available methods for the query chain factory
|
|
693
|
+
* @returns An object containing all available methods
|
|
694
|
+
*/
|
|
695
|
+
static methods() {
|
|
696
|
+
return {
|
|
697
|
+
...BaseChainFactory.methods(),
|
|
698
|
+
output: QueryChainFactory.prototype.output,
|
|
699
|
+
input: QueryChainFactory.prototype.input,
|
|
700
|
+
resolve: QueryChainFactory.prototype.resolve,
|
|
701
|
+
clone: QueryChainFactory.prototype.clone
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Creates a clone of the current factory with new options
|
|
706
|
+
* @param options - New options to apply to the clone
|
|
707
|
+
* @returns A new instance of QueryChainFactory with the updated options
|
|
708
|
+
*/
|
|
709
|
+
clone(options) {
|
|
710
|
+
return new QueryChainFactory({
|
|
711
|
+
...this.options,
|
|
712
|
+
...options
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Sets the output type for the query
|
|
717
|
+
* @template TOutputNew - The new output type
|
|
718
|
+
* @param output - The output type definition
|
|
719
|
+
* @returns A new QueryChainFactory instance with the updated output type
|
|
720
|
+
*/
|
|
721
|
+
output(output) {
|
|
722
|
+
return new QueryChainFactory({
|
|
723
|
+
...this.options,
|
|
724
|
+
output
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Sets the input type for the query
|
|
729
|
+
* @template TInputNew - The new input type
|
|
730
|
+
* @param input - The input type definition
|
|
731
|
+
* @returns A new QueryChainFactory instance with the updated input type
|
|
732
|
+
*/
|
|
733
|
+
input(input) {
|
|
734
|
+
return new QueryChainFactory({
|
|
735
|
+
...this.options,
|
|
736
|
+
input
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Sets the resolve function for the query
|
|
741
|
+
* @param resolve - The resolve function that processes the input and returns the output
|
|
742
|
+
* @returns A GraphQL query resolver
|
|
743
|
+
* @throws {Error} If output type is not set
|
|
744
|
+
*/
|
|
745
|
+
resolve(resolve) {
|
|
746
|
+
if (!this.options?.output) throw new Error("Output is required");
|
|
747
|
+
return createQuery(this.options.output, {
|
|
748
|
+
...this.options,
|
|
749
|
+
resolve
|
|
750
|
+
});
|
|
751
|
+
}
|
|
1016
752
|
};
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
753
|
+
/**
|
|
754
|
+
* Factory for creating mutation resolvers with chainable configuration
|
|
755
|
+
* @template TOutput - The output type of the mutation
|
|
756
|
+
* @template TInput - The input type of the mutation
|
|
757
|
+
*/
|
|
758
|
+
var MutationChainFactory = class MutationChainFactory extends BaseChainFactory {
|
|
759
|
+
/**
|
|
760
|
+
* Returns the available methods for the mutation chain factory
|
|
761
|
+
* @returns An object containing all available methods
|
|
762
|
+
*/
|
|
763
|
+
static methods() {
|
|
764
|
+
return {
|
|
765
|
+
...BaseChainFactory.methods(),
|
|
766
|
+
output: MutationChainFactory.prototype.output,
|
|
767
|
+
input: MutationChainFactory.prototype.input,
|
|
768
|
+
resolve: MutationChainFactory.prototype.resolve,
|
|
769
|
+
clone: MutationChainFactory.prototype.clone
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Creates a clone of the current factory with new options
|
|
774
|
+
* @param options - New options to apply to the clone
|
|
775
|
+
* @returns A new instance of MutationChainFactory with the updated options
|
|
776
|
+
*/
|
|
777
|
+
clone(options) {
|
|
778
|
+
return new MutationChainFactory({
|
|
779
|
+
...this.options,
|
|
780
|
+
...options
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Sets the output type for the mutation
|
|
785
|
+
* @template TOutputNew - The new output type
|
|
786
|
+
* @param output - The output type definition
|
|
787
|
+
* @returns A new MutationChainFactory instance with the updated output type
|
|
788
|
+
*/
|
|
789
|
+
output(output) {
|
|
790
|
+
return new MutationChainFactory({
|
|
791
|
+
...this.options,
|
|
792
|
+
output
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Sets the input type for the mutation
|
|
797
|
+
* @template TInputNew - The new input type
|
|
798
|
+
* @param input - The input type definition
|
|
799
|
+
* @returns A new MutationChainFactory instance with the updated input type
|
|
800
|
+
*/
|
|
801
|
+
input(input) {
|
|
802
|
+
return new MutationChainFactory({
|
|
803
|
+
...this.options,
|
|
804
|
+
input
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Sets the resolve function for the mutation
|
|
809
|
+
* @param resolve - The resolve function that processes the input and returns the output
|
|
810
|
+
* @returns A GraphQL mutation resolver
|
|
811
|
+
* @throws {Error} If output type is not set
|
|
812
|
+
*/
|
|
813
|
+
resolve(resolve) {
|
|
814
|
+
if (!this.options?.output) throw new Error("Output is required");
|
|
815
|
+
return createMutation(this.options.output, {
|
|
816
|
+
...this.options,
|
|
817
|
+
resolve
|
|
818
|
+
});
|
|
819
|
+
}
|
|
1070
820
|
};
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
821
|
+
/**
|
|
822
|
+
* Factory for creating subscription resolvers with chainable configuration
|
|
823
|
+
* @template TOutput - The output type of the subscription
|
|
824
|
+
* @template TInput - The input type of the subscription
|
|
825
|
+
*/
|
|
826
|
+
var SubscriptionChainFactory = class SubscriptionChainFactory extends BaseChainFactory {
|
|
827
|
+
/**
|
|
828
|
+
* Returns the available methods for the subscription chain factory
|
|
829
|
+
* @returns An object containing all available methods
|
|
830
|
+
*/
|
|
831
|
+
static methods() {
|
|
832
|
+
return {
|
|
833
|
+
...BaseChainFactory.methods(),
|
|
834
|
+
output: SubscriptionChainFactory.prototype.output,
|
|
835
|
+
input: SubscriptionChainFactory.prototype.input,
|
|
836
|
+
subscribe: SubscriptionChainFactory.prototype.subscribe,
|
|
837
|
+
clone: SubscriptionChainFactory.prototype.clone
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Creates a clone of the current factory with new options
|
|
842
|
+
* @param options - New options to apply to the clone
|
|
843
|
+
* @returns A new instance of SubscriptionChainFactory with the updated options
|
|
844
|
+
*/
|
|
845
|
+
clone(options) {
|
|
846
|
+
return new SubscriptionChainFactory({
|
|
847
|
+
...this.options,
|
|
848
|
+
...options
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Sets the output type for the subscription
|
|
853
|
+
* @template TOutputNew - The new output type
|
|
854
|
+
* @param output - The output type definition
|
|
855
|
+
* @returns A new SubscriptionChainFactory instance with the updated output type
|
|
856
|
+
*/
|
|
857
|
+
output(output) {
|
|
858
|
+
return new SubscriptionChainFactory({
|
|
859
|
+
...this.options,
|
|
860
|
+
output
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Sets the input type for the subscription
|
|
865
|
+
* @template TInputNew - The new input type
|
|
866
|
+
* @param input - The input type definition
|
|
867
|
+
* @returns A new SubscriptionChainFactory instance with the updated input type
|
|
868
|
+
*/
|
|
869
|
+
input(input) {
|
|
870
|
+
return new SubscriptionChainFactory({
|
|
871
|
+
...this.options,
|
|
872
|
+
input
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Sets the subscribe function for the subscription
|
|
877
|
+
* @template TValue - The value type of the subscription
|
|
878
|
+
* @param subscribe - The subscribe function that returns an AsyncIterator
|
|
879
|
+
* @returns A subscription resolver that can be further configured with a resolve function
|
|
880
|
+
* @throws {Error} If output type is not set
|
|
881
|
+
*/
|
|
882
|
+
subscribe(subscribe) {
|
|
883
|
+
const options = this.options;
|
|
884
|
+
const output = this.options?.output;
|
|
885
|
+
if (!output) throw new Error("Output is required");
|
|
886
|
+
const subscription$1 = createSubscription(output, {
|
|
887
|
+
...options,
|
|
888
|
+
subscribe
|
|
889
|
+
});
|
|
890
|
+
const subscriptionResolve = subscription$1["~meta"].resolve;
|
|
891
|
+
const resolve = (...args) => {
|
|
892
|
+
if (args.length === 1 && typeof args[0] === "function") return createSubscription(output, {
|
|
893
|
+
...options,
|
|
894
|
+
resolve: args[0],
|
|
895
|
+
subscribe
|
|
896
|
+
});
|
|
897
|
+
return subscriptionResolve(...args);
|
|
898
|
+
};
|
|
899
|
+
return Object.assign(subscription$1, { resolve });
|
|
900
|
+
}
|
|
1139
901
|
};
|
|
1140
|
-
var QueryFactoryWithResolve = class
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
]
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
902
|
+
var QueryFactoryWithResolve = class QueryFactoryWithResolve extends BaseChainFactory {
|
|
903
|
+
get "~meta"() {
|
|
904
|
+
return loom.query(this.outputSilk, this.options)["~meta"];
|
|
905
|
+
}
|
|
906
|
+
constructor(outputSilk, options) {
|
|
907
|
+
super(options);
|
|
908
|
+
this.outputSilk = outputSilk;
|
|
909
|
+
this.options = options;
|
|
910
|
+
}
|
|
911
|
+
clone(options) {
|
|
912
|
+
return new QueryFactoryWithResolve(this.outputSilk, {
|
|
913
|
+
...this.options,
|
|
914
|
+
...options
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
input(input) {
|
|
918
|
+
return new QueryFactoryWithResolve(this.outputSilk, {
|
|
919
|
+
...this.options,
|
|
920
|
+
input
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
output(output, transform) {
|
|
924
|
+
return new QueryFactoryWithResolve(output, {
|
|
925
|
+
...this.options,
|
|
926
|
+
middlewares: [...this.options.middlewares ?? [], async (next) => transform(await next())]
|
|
927
|
+
});
|
|
928
|
+
}
|
|
1170
929
|
};
|
|
1171
|
-
var MutationFactoryWithResolve = class
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
]
|
|
1199
|
-
});
|
|
1200
|
-
}
|
|
930
|
+
var MutationFactoryWithResolve = class MutationFactoryWithResolve extends BaseChainFactory {
|
|
931
|
+
get "~meta"() {
|
|
932
|
+
return loom.mutation(this.outputSilk, this.options)["~meta"];
|
|
933
|
+
}
|
|
934
|
+
constructor(outputSilk, options) {
|
|
935
|
+
super(options);
|
|
936
|
+
this.outputSilk = outputSilk;
|
|
937
|
+
this.options = options;
|
|
938
|
+
}
|
|
939
|
+
clone(options) {
|
|
940
|
+
return new MutationFactoryWithResolve(this.outputSilk, {
|
|
941
|
+
...this.options,
|
|
942
|
+
...options
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
input(input) {
|
|
946
|
+
return new MutationFactoryWithResolve(this.outputSilk, {
|
|
947
|
+
...this.options,
|
|
948
|
+
input
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
output(output, transform) {
|
|
952
|
+
return new MutationFactoryWithResolve(output, {
|
|
953
|
+
...this.options,
|
|
954
|
+
middlewares: [...this.options.middlewares ?? [], async (next) => transform(await next())]
|
|
955
|
+
});
|
|
956
|
+
}
|
|
1201
957
|
};
|
|
1202
|
-
var FieldFactoryWithResolve = class
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
middlewares: [
|
|
1230
|
-
...this.options.middlewares ?? [],
|
|
1231
|
-
async (next) => transform(await next())
|
|
1232
|
-
]
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
958
|
+
var FieldFactoryWithResolve = class FieldFactoryWithResolve extends BaseChainFactory {
|
|
959
|
+
get "~meta"() {
|
|
960
|
+
return loom.field(this.outputSilk, this.options)["~meta"];
|
|
961
|
+
}
|
|
962
|
+
constructor(outputSilk, options) {
|
|
963
|
+
super(options);
|
|
964
|
+
this.outputSilk = outputSilk;
|
|
965
|
+
this.options = options;
|
|
966
|
+
}
|
|
967
|
+
clone(options) {
|
|
968
|
+
return new FieldFactoryWithResolve(this.outputSilk, {
|
|
969
|
+
...this.options,
|
|
970
|
+
...options
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
input(input) {
|
|
974
|
+
return new FieldFactoryWithResolve(this.outputSilk, {
|
|
975
|
+
...this.options,
|
|
976
|
+
input
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
output(output, transform) {
|
|
980
|
+
return new FieldFactoryWithResolve(output, {
|
|
981
|
+
...this.options,
|
|
982
|
+
middlewares: [...this.options.middlewares ?? [], async (next) => transform(await next())]
|
|
983
|
+
});
|
|
984
|
+
}
|
|
1235
985
|
};
|
|
1236
986
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
987
|
+
//#endregion
|
|
988
|
+
//#region src/resolver/resolver.ts
|
|
989
|
+
/**
|
|
990
|
+
* Creates a GraphQL query resolver
|
|
991
|
+
* @param output - The output type definition for the query
|
|
992
|
+
* @param resolveOrOptions - Either a resolve function or options object
|
|
993
|
+
* @returns A GraphQL query resolver
|
|
994
|
+
*/
|
|
995
|
+
const createQuery = (output, resolveOrOptions) => {
|
|
996
|
+
if (resolveOrOptions == null) return new QueryChainFactory({ output });
|
|
997
|
+
const options = getOperationOptions(resolveOrOptions);
|
|
998
|
+
return meta({
|
|
999
|
+
...getFieldOptions(options),
|
|
1000
|
+
input: options.input,
|
|
1001
|
+
output,
|
|
1002
|
+
resolve: options.resolve,
|
|
1003
|
+
middlewares: options.middlewares,
|
|
1004
|
+
operation: "query"
|
|
1005
|
+
});
|
|
1251
1006
|
};
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
);
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1007
|
+
/**
|
|
1008
|
+
* Factory function for creating GraphQL queries with chainable configuration
|
|
1009
|
+
*/
|
|
1010
|
+
const query = Object.assign(createQuery, QueryChainFactory.methods());
|
|
1011
|
+
/**
|
|
1012
|
+
* Creates a GraphQL mutation resolver
|
|
1013
|
+
* @param output - The output type definition for the mutation
|
|
1014
|
+
* @param resolveOrOptions - Either a resolve function or options object
|
|
1015
|
+
* @returns A GraphQL mutation resolver
|
|
1016
|
+
*/
|
|
1017
|
+
const createMutation = (output, resolveOrOptions) => {
|
|
1018
|
+
if (resolveOrOptions == null) return new MutationChainFactory({ output });
|
|
1019
|
+
const options = getOperationOptions(resolveOrOptions);
|
|
1020
|
+
return meta({
|
|
1021
|
+
...getFieldOptions(options),
|
|
1022
|
+
input: options.input,
|
|
1023
|
+
output,
|
|
1024
|
+
resolve: options.resolve,
|
|
1025
|
+
middlewares: options.middlewares,
|
|
1026
|
+
operation: "mutation"
|
|
1027
|
+
});
|
|
1269
1028
|
};
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
);
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1029
|
+
/**
|
|
1030
|
+
* Factory function for creating GraphQL mutations with chainable configuration
|
|
1031
|
+
*/
|
|
1032
|
+
const mutation = Object.assign(createMutation, MutationChainFactory.methods());
|
|
1033
|
+
/**
|
|
1034
|
+
* Creates a GraphQL field resolver
|
|
1035
|
+
* @param output - The output type definition for the field
|
|
1036
|
+
* @param resolveOrOptions - Either a resolve function or options object
|
|
1037
|
+
* @returns A GraphQL field resolver
|
|
1038
|
+
*/
|
|
1039
|
+
const createField = (output, resolveOrOptions) => {
|
|
1040
|
+
if (resolveOrOptions == null) return new FieldChainFactory({ output });
|
|
1041
|
+
const options = getOperationOptions(resolveOrOptions);
|
|
1042
|
+
return meta({
|
|
1043
|
+
...getFieldOptions(options, { [require_context.DERIVED_DEPENDENCIES]: options.dependencies }),
|
|
1044
|
+
input: options.input,
|
|
1045
|
+
dependencies: options.dependencies,
|
|
1046
|
+
output,
|
|
1047
|
+
resolve: options.resolve,
|
|
1048
|
+
middlewares: options.middlewares,
|
|
1049
|
+
operation: "field"
|
|
1050
|
+
});
|
|
1290
1051
|
};
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1052
|
+
/**
|
|
1053
|
+
* Factory function for creating GraphQL fields with chainable configuration
|
|
1054
|
+
*/
|
|
1055
|
+
const field = Object.assign(createField, { hidden: require_context.FIELD_HIDDEN }, FieldChainFactory.methods());
|
|
1056
|
+
/**
|
|
1057
|
+
* Default subscription resolver that returns the source value
|
|
1058
|
+
* @param source - The source value to resolve
|
|
1059
|
+
*/
|
|
1060
|
+
const defaultSubscriptionResolve = (source) => source;
|
|
1061
|
+
/**
|
|
1062
|
+
* Creates a GraphQL subscription resolver
|
|
1063
|
+
* @param output - The output type definition for the subscription
|
|
1064
|
+
* @param subscribeOrOptions - Optional subscribe function or options object
|
|
1065
|
+
* @returns A GraphQL subscription resolver or chain factory
|
|
1066
|
+
*/
|
|
1297
1067
|
function createSubscription(output, subscribeOrOptions) {
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
operation: "subscription"
|
|
1310
|
-
});
|
|
1068
|
+
if (subscribeOrOptions == null) return new SubscriptionChainFactory({ output });
|
|
1069
|
+
const options = getSubscriptionOptions(subscribeOrOptions);
|
|
1070
|
+
return meta({
|
|
1071
|
+
...getFieldOptions(options),
|
|
1072
|
+
input: options.input,
|
|
1073
|
+
output,
|
|
1074
|
+
subscribe: options.subscribe,
|
|
1075
|
+
resolve: options.resolve ?? defaultSubscriptionResolve,
|
|
1076
|
+
middlewares: options.middlewares,
|
|
1077
|
+
operation: "subscription"
|
|
1078
|
+
});
|
|
1311
1079
|
}
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
);
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
var loom = {
|
|
1327
|
-
query,
|
|
1328
|
-
resolver,
|
|
1329
|
-
field,
|
|
1330
|
-
subscription,
|
|
1331
|
-
mutation
|
|
1080
|
+
/**
|
|
1081
|
+
* Factory function for creating GraphQL subscriptions with chainable configuration
|
|
1082
|
+
*/
|
|
1083
|
+
const subscription = Object.assign(createSubscription, SubscriptionChainFactory.methods());
|
|
1084
|
+
const resolver = Object.assign(((operations, options) => new ChainResolver(operations, options)), { of: ((parent, operations, options) => new ObjectChainResolver(parent, operations, options)) });
|
|
1085
|
+
/**
|
|
1086
|
+
* Collection of factory functions for creating GraphQL operations
|
|
1087
|
+
*/
|
|
1088
|
+
const loom = {
|
|
1089
|
+
query,
|
|
1090
|
+
resolver,
|
|
1091
|
+
field,
|
|
1092
|
+
subscription,
|
|
1093
|
+
mutation
|
|
1332
1094
|
};
|
|
1095
|
+
/**
|
|
1096
|
+
* Base class for chain resolvers
|
|
1097
|
+
* @template TFields - The fields or operations to resolve
|
|
1098
|
+
*/
|
|
1333
1099
|
var ChainResolver = class {
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
};
|
|
1397
|
-
} else {
|
|
1398
|
-
const resolve = field2["~meta"].resolve;
|
|
1399
|
-
return (args, payload) => {
|
|
1400
|
-
const parseInput = createInputParser(field2["~meta"].input, args);
|
|
1401
|
-
return applyMiddlewares(
|
|
1402
|
-
{
|
|
1403
|
-
outputSilk: field2["~meta"].output,
|
|
1404
|
-
parent: void 0,
|
|
1405
|
-
payload,
|
|
1406
|
-
parseInput,
|
|
1407
|
-
operation
|
|
1408
|
-
},
|
|
1409
|
-
async () => resolve(await parseInput.getResult(), payload),
|
|
1410
|
-
middlewares
|
|
1411
|
-
);
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1100
|
+
meta;
|
|
1101
|
+
/**
|
|
1102
|
+
* Creates a new chain resolver
|
|
1103
|
+
* @param fields - The fields or operations to resolve
|
|
1104
|
+
* @param options - Optional resolver options
|
|
1105
|
+
*/
|
|
1106
|
+
constructor(fields, options) {
|
|
1107
|
+
this.meta = {
|
|
1108
|
+
[require_context.IS_RESOLVER]: true,
|
|
1109
|
+
fields,
|
|
1110
|
+
options
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Gets the metadata for the resolver
|
|
1115
|
+
*/
|
|
1116
|
+
get "~meta"() {
|
|
1117
|
+
return this.meta;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Adds middleware functions to the resolver
|
|
1121
|
+
* @param middlewares - The middleware functions to add
|
|
1122
|
+
*/
|
|
1123
|
+
use(...middlewares) {
|
|
1124
|
+
this.meta.options ??= {};
|
|
1125
|
+
this.meta.options.middlewares ??= [];
|
|
1126
|
+
this.meta.options.middlewares.push(...middlewares);
|
|
1127
|
+
return this;
|
|
1128
|
+
}
|
|
1129
|
+
toExecutor(...middlewares) {
|
|
1130
|
+
return mapValue(this["~meta"].fields, (field$1) => this.toExecutorOperation(field$1, middlewares) ?? mapValue.SKIP);
|
|
1131
|
+
}
|
|
1132
|
+
toExecutorOperation(field$1, executorMiddlewares) {
|
|
1133
|
+
if (field$1 === require_context.FIELD_HIDDEN || field$1["~meta"].operation === "subscription") return;
|
|
1134
|
+
const operation = field$1["~meta"].operation;
|
|
1135
|
+
const middlewares = filterMiddlewares(operation, executorMiddlewares, this.meta.options?.middlewares, field$1["~meta"].middlewares);
|
|
1136
|
+
if (field$1["~meta"].operation === "field") {
|
|
1137
|
+
const resolve = field$1["~meta"].resolve;
|
|
1138
|
+
return (parent, args, payload) => {
|
|
1139
|
+
const parseInput = createInputParser(field$1["~meta"].input, args);
|
|
1140
|
+
return applyMiddlewares({
|
|
1141
|
+
outputSilk: field$1["~meta"].output,
|
|
1142
|
+
parent,
|
|
1143
|
+
payload,
|
|
1144
|
+
parseInput,
|
|
1145
|
+
operation
|
|
1146
|
+
}, async () => resolve(parent, await parseInput.getResult(), payload), middlewares);
|
|
1147
|
+
};
|
|
1148
|
+
} else {
|
|
1149
|
+
const resolve = field$1["~meta"].resolve;
|
|
1150
|
+
return (args, payload) => {
|
|
1151
|
+
const parseInput = createInputParser(field$1["~meta"].input, args);
|
|
1152
|
+
return applyMiddlewares({
|
|
1153
|
+
outputSilk: field$1["~meta"].output,
|
|
1154
|
+
parent: void 0,
|
|
1155
|
+
payload,
|
|
1156
|
+
parseInput,
|
|
1157
|
+
operation
|
|
1158
|
+
}, async () => resolve(await parseInput.getResult(), payload), middlewares);
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1415
1162
|
};
|
|
1163
|
+
/**
|
|
1164
|
+
* Class for resolving object types
|
|
1165
|
+
* @template TParent - The parent type
|
|
1166
|
+
* @template TFields - The fields to resolve
|
|
1167
|
+
*/
|
|
1416
1168
|
var ObjectChainResolver = class extends ChainResolver {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1169
|
+
meta;
|
|
1170
|
+
/**
|
|
1171
|
+
* Creates a new object chain resolver
|
|
1172
|
+
* @param parent - The parent type definition
|
|
1173
|
+
* @param fields - The fields to resolve
|
|
1174
|
+
* @param options - Optional resolver options
|
|
1175
|
+
*/
|
|
1176
|
+
constructor(parent, fields, options) {
|
|
1177
|
+
super(fields, options);
|
|
1178
|
+
this.meta = {
|
|
1179
|
+
[require_context.IS_RESOLVER]: true,
|
|
1180
|
+
fields,
|
|
1181
|
+
parent,
|
|
1182
|
+
options
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Gets the metadata for the resolver
|
|
1187
|
+
*/
|
|
1188
|
+
get "~meta"() {
|
|
1189
|
+
return super["~meta"];
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Sets custom extensions for the resolver
|
|
1193
|
+
* @param extensions - The extensions to add
|
|
1194
|
+
*/
|
|
1195
|
+
extensions(extensions) {
|
|
1196
|
+
this.meta.options ??= {};
|
|
1197
|
+
this.meta.options.extensions ??= {};
|
|
1198
|
+
this.meta.options.extensions = {
|
|
1199
|
+
...this.meta.options.extensions,
|
|
1200
|
+
...extensions
|
|
1201
|
+
};
|
|
1202
|
+
return this;
|
|
1203
|
+
}
|
|
1452
1204
|
};
|
|
1453
1205
|
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
// src/schema/input.ts
|
|
1458
|
-
var import_graphql7 = require("graphql");
|
|
1206
|
+
//#endregion
|
|
1207
|
+
//#region src/schema/input.ts
|
|
1459
1208
|
function inputToArgs(input, options) {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
...field2,
|
|
1484
|
-
type: ensureInputType(field2, { fieldName })
|
|
1485
|
-
};
|
|
1486
|
-
}, name);
|
|
1487
|
-
});
|
|
1488
|
-
return args;
|
|
1209
|
+
if (input === void 0) return void 0;
|
|
1210
|
+
if (isSilk(input)) {
|
|
1211
|
+
let inputType = getGraphQLType(input);
|
|
1212
|
+
if ((0, graphql.isNonNullType)(inputType)) inputType = inputType.ofType;
|
|
1213
|
+
if ((0, graphql.isObjectType)(inputType)) return mapValue(inputType.toConfig().fields, (it, key) => {
|
|
1214
|
+
let fieldName;
|
|
1215
|
+
if (options?.fieldName) fieldName = `${pascalCase(options.fieldName)}${pascalCase(key)}`;
|
|
1216
|
+
return toInputFieldConfig(it, { fieldName });
|
|
1217
|
+
});
|
|
1218
|
+
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
1219
|
+
}
|
|
1220
|
+
const args = {};
|
|
1221
|
+
Object.entries(input).forEach(([name, field$1]) => {
|
|
1222
|
+
tryIn(() => {
|
|
1223
|
+
let fieldName;
|
|
1224
|
+
if (options?.fieldName) fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
|
|
1225
|
+
args[name] = {
|
|
1226
|
+
...field$1,
|
|
1227
|
+
type: ensureInputType(field$1, { fieldName })
|
|
1228
|
+
};
|
|
1229
|
+
}, name);
|
|
1230
|
+
});
|
|
1231
|
+
return args;
|
|
1489
1232
|
}
|
|
1490
1233
|
function ensureInputType(silkOrType, options) {
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
return new import_graphql7.GraphQLNonNull(ensureInputType(gqlType.ofType, options));
|
|
1501
|
-
}
|
|
1502
|
-
if ((0, import_graphql7.isListType)(gqlType)) {
|
|
1503
|
-
return new import_graphql7.GraphQLList(ensureInputType(gqlType.ofType, options));
|
|
1504
|
-
}
|
|
1505
|
-
if ((0, import_graphql7.isObjectType)(gqlType) || (0, import_graphql7.isInterfaceType)(gqlType))
|
|
1506
|
-
return ensureInputObjectType(gqlType, options);
|
|
1507
|
-
return gqlType;
|
|
1234
|
+
const gqlType = (() => {
|
|
1235
|
+
if (isSilk(silkOrType)) return getGraphQLType(silkOrType);
|
|
1236
|
+
return silkOrType;
|
|
1237
|
+
})();
|
|
1238
|
+
if ((0, graphql.isUnionType)(gqlType)) throw new Error(`Cannot convert union type ${gqlType.name} to input type`);
|
|
1239
|
+
if ((0, graphql.isNonNullType)(gqlType)) return new graphql.GraphQLNonNull(ensureInputType(gqlType.ofType, options));
|
|
1240
|
+
if ((0, graphql.isListType)(gqlType)) return new graphql.GraphQLList(ensureInputType(gqlType.ofType, options));
|
|
1241
|
+
if ((0, graphql.isObjectType)(gqlType) || (0, graphql.isInterfaceType)(gqlType)) return ensureInputObjectType(gqlType, options);
|
|
1242
|
+
return gqlType;
|
|
1508
1243
|
}
|
|
1509
1244
|
function ensureInputObjectType(object, options) {
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
() => mapValue(
|
|
1525
|
-
fields,
|
|
1526
|
-
(it, key) => toInputFieldConfig(it, {
|
|
1527
|
-
fieldName: inputFieldName(name) + pascalCase(key)
|
|
1528
|
-
})
|
|
1529
|
-
)
|
|
1530
|
-
)
|
|
1531
|
-
});
|
|
1532
|
-
weaverContext.inputMap?.set(object, input);
|
|
1533
|
-
return input;
|
|
1245
|
+
if ((0, graphql.isInputObjectType)(object)) return object;
|
|
1246
|
+
const existing = weaverContext.inputMap?.get(object);
|
|
1247
|
+
if (existing != null) return existing;
|
|
1248
|
+
const { astNode, extensionASTNodes, fields,...config } = object.toConfig();
|
|
1249
|
+
let name = object.name;
|
|
1250
|
+
if (name === LoomObjectType.AUTO_ALIASING) name = `${pascalCase(options?.fieldName ?? "")}Input`;
|
|
1251
|
+
name = (weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n))(name);
|
|
1252
|
+
const input = new graphql.GraphQLInputObjectType({
|
|
1253
|
+
...config,
|
|
1254
|
+
name,
|
|
1255
|
+
fields: provideWeaverContext.inherit(() => mapValue(fields, (it, key) => toInputFieldConfig(it, { fieldName: inputFieldName(name) + pascalCase(key) })))
|
|
1256
|
+
});
|
|
1257
|
+
weaverContext.inputMap?.set(object, input);
|
|
1258
|
+
return input;
|
|
1534
1259
|
}
|
|
1535
|
-
function toInputFieldConfig({ astNode, resolve
|
|
1536
|
-
|
|
1260
|
+
function toInputFieldConfig({ astNode, resolve,...config }, options) {
|
|
1261
|
+
return {
|
|
1262
|
+
...config,
|
|
1263
|
+
type: ensureInputType(config.type, options)
|
|
1264
|
+
};
|
|
1537
1265
|
}
|
|
1538
1266
|
function inputFieldName(name) {
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
}
|
|
1542
|
-
return name;
|
|
1267
|
+
while (name.endsWith("Input")) name = name.slice(0, -5);
|
|
1268
|
+
return name;
|
|
1543
1269
|
}
|
|
1544
1270
|
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
);
|
|
1734
|
-
};
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
provideForSubscribe(field2, fieldName) {
|
|
1739
|
-
if (field2?.["~meta"]?.subscribe == null)
|
|
1740
|
-
return;
|
|
1741
|
-
const resolverMiddlewares = this.resolvers.get(fieldName)?.["~meta"].options?.middlewares;
|
|
1742
|
-
const middlewares = filterMiddlewares(
|
|
1743
|
-
"subscription.subscribe",
|
|
1744
|
-
this.globalOptions?.middlewares,
|
|
1745
|
-
resolverMiddlewares,
|
|
1746
|
-
field2["~meta"].middlewares
|
|
1747
|
-
);
|
|
1748
|
-
return (source, args, context, info) => {
|
|
1749
|
-
const payload = { root: source, args, context, info, field: field2 };
|
|
1750
|
-
const parseInput = createInputParser(field2["~meta"].input, args);
|
|
1751
|
-
return applyMiddlewares(
|
|
1752
|
-
{
|
|
1753
|
-
operation: "subscription.subscribe",
|
|
1754
|
-
outputSilk: field2["~meta"].output,
|
|
1755
|
-
parent: void 0,
|
|
1756
|
-
parseInput,
|
|
1757
|
-
payload
|
|
1758
|
-
},
|
|
1759
|
-
async () => field2["~meta"].subscribe(
|
|
1760
|
-
await parseInput.getResult(),
|
|
1761
|
-
payload
|
|
1762
|
-
),
|
|
1763
|
-
middlewares
|
|
1764
|
-
);
|
|
1765
|
-
};
|
|
1766
|
-
}
|
|
1767
|
-
getCacheType(gqlType, fieldName) {
|
|
1768
|
-
return getCacheType(gqlType, { ...this.options, fieldName, parent: this });
|
|
1769
|
-
}
|
|
1770
|
-
get options() {
|
|
1771
|
-
const { globalOptions: resolverOptions, weaverContext: weaverContext2 } = this;
|
|
1772
|
-
return { resolverOptions, weaverContext: weaverContext2 };
|
|
1773
|
-
}
|
|
1271
|
+
//#endregion
|
|
1272
|
+
//#region src/schema/object.ts
|
|
1273
|
+
var LoomObjectType = class LoomObjectType extends graphql.GraphQLObjectType {
|
|
1274
|
+
extraFields = /* @__PURE__ */ new Map();
|
|
1275
|
+
hiddenFields = /* @__PURE__ */ new Set();
|
|
1276
|
+
static AUTO_ALIASING = "__gqloom_auto_aliasing";
|
|
1277
|
+
weaverContext;
|
|
1278
|
+
globalOptions;
|
|
1279
|
+
/**
|
|
1280
|
+
* field name -> resolver
|
|
1281
|
+
*/
|
|
1282
|
+
resolvers;
|
|
1283
|
+
constructor(objectOrGetter, options = {}) {
|
|
1284
|
+
const origin = typeof objectOrGetter === "function" ? objectOrGetter() : objectOrGetter;
|
|
1285
|
+
const config = (() => {
|
|
1286
|
+
if ((0, graphql.isObjectType)(origin)) return origin.toConfig();
|
|
1287
|
+
else if (typeof origin === "string") return {
|
|
1288
|
+
name: origin,
|
|
1289
|
+
fields: {}
|
|
1290
|
+
};
|
|
1291
|
+
else return origin;
|
|
1292
|
+
})();
|
|
1293
|
+
super(config);
|
|
1294
|
+
this.globalOptions = options.globalOptions;
|
|
1295
|
+
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
1296
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
1297
|
+
if (this.name !== LoomObjectType.AUTO_ALIASING) this.hasExplicitName = true;
|
|
1298
|
+
}
|
|
1299
|
+
hasExplicitName;
|
|
1300
|
+
_aliases = [];
|
|
1301
|
+
get aliases() {
|
|
1302
|
+
return this._aliases;
|
|
1303
|
+
}
|
|
1304
|
+
addAlias(name) {
|
|
1305
|
+
if (this.hasExplicitName) return;
|
|
1306
|
+
this._aliases.push(name);
|
|
1307
|
+
this.renameByAliases();
|
|
1308
|
+
}
|
|
1309
|
+
renameByAliases() {
|
|
1310
|
+
let name;
|
|
1311
|
+
for (const alias of this.aliases) if (name === void 0 || alias.length < name.length) name = alias;
|
|
1312
|
+
if (name) this.name = name;
|
|
1313
|
+
}
|
|
1314
|
+
hideField(name) {
|
|
1315
|
+
this.hiddenFields.add(name);
|
|
1316
|
+
}
|
|
1317
|
+
addField(name, field$1, resolver$1) {
|
|
1318
|
+
const existing = this.extraFields.get(name);
|
|
1319
|
+
if (existing && existing !== field$1) throw new Error(`Field ${name} already exists in ${this.name}`);
|
|
1320
|
+
this.extraFields.set(name, field$1);
|
|
1321
|
+
if (resolver$1) this.resolvers.set(name, resolver$1);
|
|
1322
|
+
}
|
|
1323
|
+
mergeExtensions(extensions) {
|
|
1324
|
+
this.extensions = deepMerge(this.extensions, extensions);
|
|
1325
|
+
}
|
|
1326
|
+
extraFieldMap;
|
|
1327
|
+
getFields() {
|
|
1328
|
+
const fieldsBySuper = super.getFields();
|
|
1329
|
+
Object.entries(fieldsBySuper).forEach(([fieldName, field$1]) => field$1.type = this.getCacheType(field$1.type, fieldName));
|
|
1330
|
+
const extraFields = provideWeaverContext(() => defineFieldMap(this.mapToFieldConfig(this.extraFields)), this.weaverContext);
|
|
1331
|
+
if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) this.extraFieldMap = extraFields;
|
|
1332
|
+
const answer = {
|
|
1333
|
+
...fieldsBySuper,
|
|
1334
|
+
...this.extraFieldMap
|
|
1335
|
+
};
|
|
1336
|
+
for (const fieldName of this.hiddenFields) delete answer[fieldName];
|
|
1337
|
+
return answer;
|
|
1338
|
+
}
|
|
1339
|
+
mapToFieldConfig(map) {
|
|
1340
|
+
const record = {};
|
|
1341
|
+
for (const [name, field$1] of map.entries()) record[name] = this.toFieldConfig(field$1, name);
|
|
1342
|
+
return record;
|
|
1343
|
+
}
|
|
1344
|
+
toFieldConfig(field$1, fieldName) {
|
|
1345
|
+
const outputType = this.getCacheType(getGraphQLType(field$1["~meta"].output), fieldName);
|
|
1346
|
+
const resolve = this.provideForResolve(field$1, fieldName);
|
|
1347
|
+
const subscribe = this.provideForSubscribe(field$1, fieldName);
|
|
1348
|
+
return {
|
|
1349
|
+
...extract(field$1),
|
|
1350
|
+
type: outputType,
|
|
1351
|
+
args: inputToArgs(field$1["~meta"].input, { fieldName: fieldName ? parentName(this.name) + fieldName : void 0 }),
|
|
1352
|
+
resolve,
|
|
1353
|
+
...subscribe ? { subscribe } : {}
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
provideForResolve(field$1, fieldName) {
|
|
1357
|
+
const resolverMiddlewares = this.resolvers.get(fieldName)?.["~meta"].options?.middlewares;
|
|
1358
|
+
switch (field$1["~meta"].operation) {
|
|
1359
|
+
case "query":
|
|
1360
|
+
case "mutation": {
|
|
1361
|
+
const operation = field$1["~meta"].operation;
|
|
1362
|
+
const middlewares = filterMiddlewares(operation, this.globalOptions?.middlewares, resolverMiddlewares, field$1["~meta"].middlewares);
|
|
1363
|
+
return (root, args, context, info) => {
|
|
1364
|
+
const payload = {
|
|
1365
|
+
root,
|
|
1366
|
+
args,
|
|
1367
|
+
context,
|
|
1368
|
+
info,
|
|
1369
|
+
field: field$1
|
|
1370
|
+
};
|
|
1371
|
+
const parseInput = createInputParser(field$1["~meta"].input, args);
|
|
1372
|
+
return applyMiddlewares({
|
|
1373
|
+
operation,
|
|
1374
|
+
outputSilk: field$1["~meta"].output,
|
|
1375
|
+
parent: void 0,
|
|
1376
|
+
parseInput,
|
|
1377
|
+
payload
|
|
1378
|
+
}, async () => field$1["~meta"].resolve(await parseInput.getResult(), payload), middlewares);
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
case "field": {
|
|
1382
|
+
const middlewares = filterMiddlewares("field", this.globalOptions?.middlewares, resolverMiddlewares, field$1["~meta"].middlewares);
|
|
1383
|
+
return (root, args, context, info) => {
|
|
1384
|
+
const payload = {
|
|
1385
|
+
root,
|
|
1386
|
+
args,
|
|
1387
|
+
context,
|
|
1388
|
+
info,
|
|
1389
|
+
field: field$1
|
|
1390
|
+
};
|
|
1391
|
+
const parseInput = createInputParser(field$1["~meta"].input, args);
|
|
1392
|
+
return applyMiddlewares({
|
|
1393
|
+
operation: "field",
|
|
1394
|
+
outputSilk: field$1["~meta"].output,
|
|
1395
|
+
parent: root,
|
|
1396
|
+
parseInput,
|
|
1397
|
+
payload
|
|
1398
|
+
}, async () => field$1["~meta"].resolve(root, await parseInput.getResult(), payload), middlewares);
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
case "subscription": {
|
|
1402
|
+
const middlewares = filterMiddlewares("subscription.resolve", this.globalOptions?.middlewares, resolverMiddlewares, field$1["~meta"].middlewares);
|
|
1403
|
+
return (root, args, context, info) => {
|
|
1404
|
+
const payload = {
|
|
1405
|
+
root,
|
|
1406
|
+
args,
|
|
1407
|
+
context,
|
|
1408
|
+
info,
|
|
1409
|
+
field: field$1
|
|
1410
|
+
};
|
|
1411
|
+
const parseInput = createInputParser(field$1["~meta"].input, args);
|
|
1412
|
+
return applyMiddlewares({
|
|
1413
|
+
operation: "subscription.resolve",
|
|
1414
|
+
outputSilk: field$1["~meta"].output,
|
|
1415
|
+
parent: root,
|
|
1416
|
+
parseInput,
|
|
1417
|
+
payload
|
|
1418
|
+
}, async () => field$1["~meta"].resolve(root, await parseInput.getResult(), payload), middlewares);
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
provideForSubscribe(field$1, fieldName) {
|
|
1424
|
+
if (field$1?.["~meta"]?.subscribe == null) return;
|
|
1425
|
+
const resolverMiddlewares = this.resolvers.get(fieldName)?.["~meta"].options?.middlewares;
|
|
1426
|
+
const middlewares = filterMiddlewares("subscription.subscribe", this.globalOptions?.middlewares, resolverMiddlewares, field$1["~meta"].middlewares);
|
|
1427
|
+
return (source, args, context, info) => {
|
|
1428
|
+
const payload = {
|
|
1429
|
+
root: source,
|
|
1430
|
+
args,
|
|
1431
|
+
context,
|
|
1432
|
+
info,
|
|
1433
|
+
field: field$1
|
|
1434
|
+
};
|
|
1435
|
+
const parseInput = createInputParser(field$1["~meta"].input, args);
|
|
1436
|
+
return applyMiddlewares({
|
|
1437
|
+
operation: "subscription.subscribe",
|
|
1438
|
+
outputSilk: field$1["~meta"].output,
|
|
1439
|
+
parent: void 0,
|
|
1440
|
+
parseInput,
|
|
1441
|
+
payload
|
|
1442
|
+
}, async () => field$1["~meta"].subscribe(await parseInput.getResult(), payload), middlewares);
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
getCacheType(gqlType, fieldName) {
|
|
1446
|
+
return getCacheType(gqlType, {
|
|
1447
|
+
...this.options,
|
|
1448
|
+
fieldName,
|
|
1449
|
+
parent: this
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
get options() {
|
|
1453
|
+
const { globalOptions: resolverOptions, weaverContext: weaverContext$1 } = this;
|
|
1454
|
+
return {
|
|
1455
|
+
resolverOptions,
|
|
1456
|
+
weaverContext: weaverContext$1
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1774
1459
|
};
|
|
1775
|
-
function extract(
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1460
|
+
function extract(field$1) {
|
|
1461
|
+
const { deprecationReason, description, extensions } = field$1["~meta"];
|
|
1462
|
+
return {
|
|
1463
|
+
description,
|
|
1464
|
+
deprecationReason,
|
|
1465
|
+
extensions
|
|
1466
|
+
};
|
|
1782
1467
|
}
|
|
1783
1468
|
function defineFieldMap(fields) {
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1469
|
+
const fieldMap = (0, graphql.resolveObjMapThunk)(fields);
|
|
1470
|
+
return mapValue(fieldMap, (fieldConfig, fieldName) => {
|
|
1471
|
+
const argsConfig = fieldConfig.args ?? {};
|
|
1472
|
+
return {
|
|
1473
|
+
name: (0, graphql.assertName)(fieldName),
|
|
1474
|
+
description: fieldConfig.description,
|
|
1475
|
+
type: fieldConfig.type,
|
|
1476
|
+
args: defineArguments(argsConfig),
|
|
1477
|
+
resolve: fieldConfig.resolve,
|
|
1478
|
+
subscribe: fieldConfig.subscribe,
|
|
1479
|
+
deprecationReason: fieldConfig.deprecationReason,
|
|
1480
|
+
extensions: toObjMap(fieldConfig.extensions),
|
|
1481
|
+
astNode: fieldConfig.astNode
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1799
1484
|
}
|
|
1800
1485
|
function defineArguments(args) {
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1486
|
+
return Object.entries(args).map(([argName, argConfig]) => ({
|
|
1487
|
+
name: (0, graphql.assertName)(argName),
|
|
1488
|
+
description: argConfig.description,
|
|
1489
|
+
type: argConfig.type,
|
|
1490
|
+
defaultValue: argConfig.defaultValue,
|
|
1491
|
+
deprecationReason: argConfig.deprecationReason,
|
|
1492
|
+
extensions: toObjMap(argConfig.extensions),
|
|
1493
|
+
astNode: argConfig.astNode
|
|
1494
|
+
}));
|
|
1810
1495
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1496
|
+
const OPERATION_OBJECT_NAMES = new Set([
|
|
1497
|
+
"Query",
|
|
1498
|
+
"Mutation",
|
|
1499
|
+
"Subscription"
|
|
1815
1500
|
]);
|
|
1816
1501
|
function getCacheType(gqlType, options = {}) {
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
types: config.types.map(
|
|
1841
|
-
(type) => getCacheType(type, options)
|
|
1842
|
-
)
|
|
1843
|
-
});
|
|
1844
|
-
context.loomUnionMap?.set(gqlType, unionType);
|
|
1845
|
-
return unionType;
|
|
1846
|
-
}
|
|
1847
|
-
return gqlType;
|
|
1502
|
+
const context = options.weaverContext ?? weaverContext;
|
|
1503
|
+
if (gqlType instanceof LoomObjectType) return gqlType;
|
|
1504
|
+
if ((0, graphql.isObjectType)(gqlType)) {
|
|
1505
|
+
const gqlObject = context.loomObjectMap?.get(gqlType);
|
|
1506
|
+
if (gqlObject != null) return gqlObject;
|
|
1507
|
+
const loomObject = new LoomObjectType(gqlType, options);
|
|
1508
|
+
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1509
|
+
if (options.fieldName && options.parent) loomObject.addAlias(parentName(options.parent.name) + pascalCase(options.fieldName));
|
|
1510
|
+
return loomObject;
|
|
1511
|
+
} else if ((0, graphql.isListType)(gqlType)) return new graphql.GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1512
|
+
else if ((0, graphql.isNonNullType)(gqlType)) return new graphql.GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
1513
|
+
else if ((0, graphql.isUnionType)(gqlType)) {
|
|
1514
|
+
const existing = context.loomUnionMap?.get(gqlType);
|
|
1515
|
+
if (existing != null) return existing;
|
|
1516
|
+
const config = gqlType.toConfig();
|
|
1517
|
+
const unionType = new graphql.GraphQLUnionType({
|
|
1518
|
+
...config,
|
|
1519
|
+
types: config.types.map((type) => getCacheType(type, options))
|
|
1520
|
+
});
|
|
1521
|
+
context.loomUnionMap?.set(gqlType, unionType);
|
|
1522
|
+
return unionType;
|
|
1523
|
+
}
|
|
1524
|
+
return gqlType;
|
|
1848
1525
|
}
|
|
1849
1526
|
function parentName(name) {
|
|
1850
|
-
|
|
1851
|
-
|
|
1527
|
+
if (OPERATION_OBJECT_NAMES.has(name)) name = "";
|
|
1528
|
+
return name;
|
|
1852
1529
|
}
|
|
1853
1530
|
|
|
1854
|
-
|
|
1531
|
+
//#endregion
|
|
1532
|
+
//#region src/schema/schema-weaver.ts
|
|
1855
1533
|
function isSchemaVendorWeaver(some) {
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
return true;
|
|
1534
|
+
if (some == null) return false;
|
|
1535
|
+
if (typeof some !== "object" && typeof some !== "function") return false;
|
|
1536
|
+
if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function") return false;
|
|
1537
|
+
if (!("vendor" in some) || typeof some.vendor !== "string") return false;
|
|
1538
|
+
return true;
|
|
1862
1539
|
}
|
|
1863
1540
|
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
var GraphQLSchemaLoom = class
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
return { context, configs, middlewares, resolvers, silks, weavers };
|
|
2038
|
-
}
|
|
2039
|
-
/**
|
|
2040
|
-
* Weave a GraphQL Schema from resolvers
|
|
2041
|
-
* @param inputs Resolvers, Global Middlewares, WeaverConfigs Or SchemaWeaver
|
|
2042
|
-
* @returns GraphQL Schema
|
|
2043
|
-
*/
|
|
2044
|
-
static weave(...inputs) {
|
|
2045
|
-
const { context, configs, middlewares, resolvers, silks, weavers } = _GraphQLSchemaLoom.optionsFrom(...inputs);
|
|
2046
|
-
const weaver = new _GraphQLSchemaLoom({}, context);
|
|
2047
|
-
configs.forEach((it) => weaver.setConfig(it));
|
|
2048
|
-
weavers.forEach((it) => weaver.addVendor(it));
|
|
2049
|
-
middlewares.forEach((it) => weaver.use(it));
|
|
2050
|
-
resolvers.forEach((it) => weaver.add(it));
|
|
2051
|
-
silks.forEach((it) => weaver.addType(it));
|
|
2052
|
-
return weaver.weaveGraphQLSchema();
|
|
2053
|
-
}
|
|
1541
|
+
//#endregion
|
|
1542
|
+
//#region src/schema/schema-loom.ts
|
|
1543
|
+
var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
1544
|
+
query;
|
|
1545
|
+
mutation;
|
|
1546
|
+
subscription;
|
|
1547
|
+
types;
|
|
1548
|
+
context;
|
|
1549
|
+
resolverOptions;
|
|
1550
|
+
/**
|
|
1551
|
+
* Create a Schema Weaver config object
|
|
1552
|
+
* @param config Schema Weaver config options
|
|
1553
|
+
* @returns a Schema Weaver config object
|
|
1554
|
+
*/
|
|
1555
|
+
static config(config) {
|
|
1556
|
+
return {
|
|
1557
|
+
...config,
|
|
1558
|
+
[require_context.WEAVER_CONFIG]: "gqloom.core.schema"
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
constructor({ query: query$1, mutation: mutation$1, subscription: subscription$1, types } = {}, context) {
|
|
1562
|
+
if (query$1 != null) this.query = query$1;
|
|
1563
|
+
if (mutation$1 != null) this.mutation = mutation$1;
|
|
1564
|
+
if (subscription$1 != null) this.subscription = subscription$1;
|
|
1565
|
+
this.types = new Set(types ?? []);
|
|
1566
|
+
this.context = context ?? initWeaverContext();
|
|
1567
|
+
}
|
|
1568
|
+
use(...middlewares) {
|
|
1569
|
+
this.resolverOptions ??= {};
|
|
1570
|
+
this.resolverOptions.middlewares ??= [];
|
|
1571
|
+
this.resolverOptions.middlewares.push(...middlewares);
|
|
1572
|
+
return this;
|
|
1573
|
+
}
|
|
1574
|
+
add(resolver$1, modifyParent) {
|
|
1575
|
+
provideWeaverContext(() => this.addResolver(resolver$1, modifyParent), this.context);
|
|
1576
|
+
return this;
|
|
1577
|
+
}
|
|
1578
|
+
addVendor(weaver) {
|
|
1579
|
+
this.context.vendorWeavers.set(weaver.vendor, weaver);
|
|
1580
|
+
return this;
|
|
1581
|
+
}
|
|
1582
|
+
addType(silk$1) {
|
|
1583
|
+
const gqlType = provideWeaverContext(() => {
|
|
1584
|
+
let gqlType$1 = getGraphQLType(silk$1);
|
|
1585
|
+
if ((0, graphql.isNonNullType)(gqlType$1)) gqlType$1 = gqlType$1.ofType;
|
|
1586
|
+
if ((0, graphql.isObjectType)(gqlType$1)) {
|
|
1587
|
+
const existing = this.context.loomObjectMap.get(gqlType$1);
|
|
1588
|
+
if (existing != null) return existing;
|
|
1589
|
+
const extraObject = new LoomObjectType(gqlType$1, this.fieldOptions);
|
|
1590
|
+
this.context.loomObjectMap.set(gqlType$1, extraObject);
|
|
1591
|
+
return extraObject;
|
|
1592
|
+
} else if ((0, graphql.isUnionType)(gqlType$1) || (0, graphql.isEnumType)(gqlType$1)) return gqlType$1;
|
|
1593
|
+
throw new Error(`${gqlType$1?.name ?? gqlType$1.toString()} is not a named type`);
|
|
1594
|
+
}, this.context);
|
|
1595
|
+
this.types.add(gqlType);
|
|
1596
|
+
return this;
|
|
1597
|
+
}
|
|
1598
|
+
setConfig(config) {
|
|
1599
|
+
this.context.setConfig(config);
|
|
1600
|
+
return this;
|
|
1601
|
+
}
|
|
1602
|
+
weaveGraphQLSchema() {
|
|
1603
|
+
const { query: query$1, mutation: mutation$1, subscription: subscription$1, types } = this;
|
|
1604
|
+
const config = this.context.getConfig("gqloom.core.schema");
|
|
1605
|
+
return new graphql.GraphQLSchema({
|
|
1606
|
+
query: query$1,
|
|
1607
|
+
mutation: mutation$1,
|
|
1608
|
+
subscription: subscription$1,
|
|
1609
|
+
types: [...types ?? [], ...config?.types ?? []],
|
|
1610
|
+
...config
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
addResolver(resolver$1, modifyParent) {
|
|
1614
|
+
const resolverOptions = resolver$1["~meta"].options;
|
|
1615
|
+
const parent = resolver$1["~meta"].parent;
|
|
1616
|
+
let parentObject = (() => {
|
|
1617
|
+
if (parent == null) return void 0;
|
|
1618
|
+
let gqlType = getGraphQLType(parent);
|
|
1619
|
+
if ((0, graphql.isNonNullType)(gqlType)) gqlType = gqlType.ofType;
|
|
1620
|
+
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType?.name ?? gqlType.toString()} is not an object type`);
|
|
1621
|
+
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1622
|
+
if (existing != null) return existing;
|
|
1623
|
+
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
1624
|
+
this.context.loomObjectMap.set(gqlType, extraObject);
|
|
1625
|
+
this.types.add(extraObject);
|
|
1626
|
+
return extraObject;
|
|
1627
|
+
})();
|
|
1628
|
+
if (resolverOptions?.extensions && parentObject) parentObject.mergeExtensions(resolverOptions.extensions);
|
|
1629
|
+
if (modifyParent != null && parentObject) parentObject = modifyParent(parentObject);
|
|
1630
|
+
Object.entries(resolver$1["~meta"].fields).forEach(([name, field$1]) => {
|
|
1631
|
+
if (field$1 === require_context.FIELD_HIDDEN) {
|
|
1632
|
+
if (parentObject == null) return;
|
|
1633
|
+
parentObject.hideField(name);
|
|
1634
|
+
} else if (field$1["~meta"].operation === "field") {
|
|
1635
|
+
if (parentObject == null) return;
|
|
1636
|
+
parentObject.addField(name, field$1, resolver$1);
|
|
1637
|
+
} else this.getOperationObject(field$1["~meta"].operation).addField(name, field$1, resolver$1);
|
|
1638
|
+
});
|
|
1639
|
+
return this;
|
|
1640
|
+
}
|
|
1641
|
+
getOperationObject(type) {
|
|
1642
|
+
switch (type) {
|
|
1643
|
+
case "query":
|
|
1644
|
+
this.query ??= new LoomObjectType({
|
|
1645
|
+
name: "Query",
|
|
1646
|
+
fields: {}
|
|
1647
|
+
}, this.fieldOptions);
|
|
1648
|
+
return this.query;
|
|
1649
|
+
case "mutation":
|
|
1650
|
+
this.mutation ??= new LoomObjectType({
|
|
1651
|
+
name: "Mutation",
|
|
1652
|
+
fields: {}
|
|
1653
|
+
}, this.fieldOptions);
|
|
1654
|
+
return this.mutation;
|
|
1655
|
+
case "subscription":
|
|
1656
|
+
this.subscription ??= new LoomObjectType({
|
|
1657
|
+
name: "Subscription",
|
|
1658
|
+
fields: {}
|
|
1659
|
+
}, this.fieldOptions);
|
|
1660
|
+
return this.subscription;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
get fieldOptions() {
|
|
1664
|
+
const { resolverOptions, context } = this;
|
|
1665
|
+
return {
|
|
1666
|
+
globalOptions: resolverOptions,
|
|
1667
|
+
weaverContext: context
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
static optionsFrom(...inputs) {
|
|
1671
|
+
const configs = /* @__PURE__ */ new Set();
|
|
1672
|
+
const middlewares = /* @__PURE__ */ new Set();
|
|
1673
|
+
const resolvers = /* @__PURE__ */ new Set();
|
|
1674
|
+
const silks = /* @__PURE__ */ new Set();
|
|
1675
|
+
const weavers = /* @__PURE__ */ new Set();
|
|
1676
|
+
let context;
|
|
1677
|
+
for (const item of inputs) {
|
|
1678
|
+
if (item == null) continue;
|
|
1679
|
+
if (isSchemaVendorWeaver(item)) weavers.add(item);
|
|
1680
|
+
else if (typeof item === "function") middlewares.add(item);
|
|
1681
|
+
else if (require_context.WEAVER_CONFIG in item) {
|
|
1682
|
+
configs.add(item);
|
|
1683
|
+
if (item.vendorWeaver) weavers.add(item.vendorWeaver);
|
|
1684
|
+
if (item[require_context.WEAVER_CONFIG] === "gqloom.core.schema") context = item.weaverContext;
|
|
1685
|
+
} else if (isSilk(item)) silks.add(item);
|
|
1686
|
+
else if (item["~meta"][require_context.IS_RESOLVER]) resolvers.add(item);
|
|
1687
|
+
}
|
|
1688
|
+
return {
|
|
1689
|
+
context,
|
|
1690
|
+
configs,
|
|
1691
|
+
middlewares,
|
|
1692
|
+
resolvers,
|
|
1693
|
+
silks,
|
|
1694
|
+
weavers
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Weave a GraphQL Schema from resolvers
|
|
1699
|
+
* @param inputs Resolvers, Global Middlewares, WeaverConfigs Or SchemaWeaver
|
|
1700
|
+
* @returns GraphQL Schema
|
|
1701
|
+
*/
|
|
1702
|
+
static weave(...inputs) {
|
|
1703
|
+
const { context, configs, middlewares, resolvers, silks, weavers } = GraphQLSchemaLoom.optionsFrom(...inputs);
|
|
1704
|
+
const weaver = new GraphQLSchemaLoom({}, context);
|
|
1705
|
+
configs.forEach((it) => weaver.setConfig(it));
|
|
1706
|
+
weavers.forEach((it) => weaver.addVendor(it));
|
|
1707
|
+
middlewares.forEach((it) => weaver.use(it));
|
|
1708
|
+
resolvers.forEach((it) => weaver.add(it));
|
|
1709
|
+
silks.forEach((it) => weaver.addType(it));
|
|
1710
|
+
return weaver.weaveGraphQLSchema();
|
|
1711
|
+
}
|
|
2054
1712
|
};
|
|
2055
|
-
|
|
1713
|
+
/**
|
|
1714
|
+
* Weave a GraphQL Schema from resolvers
|
|
1715
|
+
* @param inputs Resolvers, Global Middlewares or WeaverConfigs
|
|
1716
|
+
* @returns GraphQL Schema
|
|
1717
|
+
*/
|
|
1718
|
+
const weave = GraphQLSchemaLoom.weave;
|
|
2056
1719
|
|
|
2057
|
-
|
|
2058
|
-
|
|
1720
|
+
//#endregion
|
|
1721
|
+
//#region src/schema/interface.ts
|
|
2059
1722
|
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
});
|
|
2079
|
-
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
2080
|
-
return interfaceType;
|
|
1723
|
+
if ((0, graphql.isInterfaceType)(gqlType)) return gqlType;
|
|
1724
|
+
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType.toString()} is not an object`);
|
|
1725
|
+
const key = gqlType;
|
|
1726
|
+
const existing = weaverContext.interfaceMap?.get(key);
|
|
1727
|
+
if (existing != null) return existing;
|
|
1728
|
+
const { astNode: _, extensionASTNodes: _1, fields,...config } = gqlType.toConfig();
|
|
1729
|
+
const interfaceType = new graphql.GraphQLInterfaceType({
|
|
1730
|
+
...config,
|
|
1731
|
+
...interfaceConfig,
|
|
1732
|
+
fields: mapValue(fields, (field$1) => {
|
|
1733
|
+
return {
|
|
1734
|
+
...field$1,
|
|
1735
|
+
type: getCacheType(field$1.type)
|
|
1736
|
+
};
|
|
1737
|
+
})
|
|
1738
|
+
});
|
|
1739
|
+
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
1740
|
+
return interfaceType;
|
|
2081
1741
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
collectName,
|
|
2104
|
-
collectNames,
|
|
2105
|
-
createField,
|
|
2106
|
-
createInputParser,
|
|
2107
|
-
createMutation,
|
|
2108
|
-
createQuery,
|
|
2109
|
-
createSubscription,
|
|
2110
|
-
deepMerge,
|
|
2111
|
-
defaultSubscriptionResolve,
|
|
2112
|
-
ensureInputObjectType,
|
|
2113
|
-
ensureInputType,
|
|
2114
|
-
ensureInterfaceType,
|
|
2115
|
-
field,
|
|
2116
|
-
filterMiddlewares,
|
|
2117
|
-
getCacheType,
|
|
2118
|
-
getFieldOptions,
|
|
2119
|
-
getGraphQLType,
|
|
2120
|
-
getMemoizationMap,
|
|
2121
|
-
getOperationOptions,
|
|
2122
|
-
getResolvingFields,
|
|
2123
|
-
getStandardValue,
|
|
2124
|
-
getSubscriptionOptions,
|
|
2125
|
-
initWeaverContext,
|
|
2126
|
-
inputToArgs,
|
|
2127
|
-
isOnlyMemoryPayload,
|
|
2128
|
-
isSchemaVendorWeaver,
|
|
2129
|
-
isSilk,
|
|
2130
|
-
listSilk,
|
|
2131
|
-
loom,
|
|
2132
|
-
mapValue,
|
|
2133
|
-
markErrorLocation,
|
|
2134
|
-
markLocation,
|
|
2135
|
-
meta,
|
|
2136
|
-
mutation,
|
|
2137
|
-
nonNullSilk,
|
|
2138
|
-
notNullish,
|
|
2139
|
-
nullableSilk,
|
|
2140
|
-
onlyMemoization,
|
|
2141
|
-
parseInputValue,
|
|
2142
|
-
parseResolvingFields,
|
|
2143
|
-
parseSilk,
|
|
2144
|
-
pascalCase,
|
|
2145
|
-
provideWeaverContext,
|
|
2146
|
-
query,
|
|
2147
|
-
resolver,
|
|
2148
|
-
screamingSnakeCase,
|
|
2149
|
-
silk,
|
|
2150
|
-
subscription,
|
|
2151
|
-
toObjMap,
|
|
2152
|
-
tryIn,
|
|
2153
|
-
weave,
|
|
2154
|
-
weaverContext
|
|
1742
|
+
|
|
1743
|
+
//#endregion
|
|
1744
|
+
exports.BaseChainFactory = BaseChainFactory;
|
|
1745
|
+
exports.ChainResolver = ChainResolver;
|
|
1746
|
+
exports.EasyDataLoader = EasyDataLoader;
|
|
1747
|
+
exports.FieldChainFactory = FieldChainFactory;
|
|
1748
|
+
exports.FieldFactoryWithResolve = FieldFactoryWithResolve;
|
|
1749
|
+
exports.GraphQLSchemaLoom = GraphQLSchemaLoom;
|
|
1750
|
+
exports.LoomDataLoader = LoomDataLoader;
|
|
1751
|
+
exports.LoomObjectType = LoomObjectType;
|
|
1752
|
+
exports.MutationChainFactory = MutationChainFactory;
|
|
1753
|
+
exports.MutationFactoryWithResolve = MutationFactoryWithResolve;
|
|
1754
|
+
exports.OPERATION_OBJECT_NAMES = OPERATION_OBJECT_NAMES;
|
|
1755
|
+
exports.ObjectChainResolver = ObjectChainResolver;
|
|
1756
|
+
exports.QueryChainFactory = QueryChainFactory;
|
|
1757
|
+
exports.QueryFactoryWithResolve = QueryFactoryWithResolve;
|
|
1758
|
+
Object.defineProperty(exports, 'SYMBOLS', {
|
|
1759
|
+
enumerable: true,
|
|
1760
|
+
get: function () {
|
|
1761
|
+
return require_context.symbols_exports;
|
|
1762
|
+
}
|
|
2155
1763
|
});
|
|
1764
|
+
exports.SubscriptionChainFactory = SubscriptionChainFactory;
|
|
1765
|
+
exports.applyMiddlewares = applyMiddlewares;
|
|
1766
|
+
exports.assignContextMap = require_context.assignContextMap;
|
|
1767
|
+
exports.capitalize = capitalize;
|
|
1768
|
+
exports.collectName = collectName;
|
|
1769
|
+
exports.collectNames = collectNames;
|
|
1770
|
+
exports.createField = createField;
|
|
1771
|
+
exports.createInputParser = createInputParser;
|
|
1772
|
+
exports.createMutation = createMutation;
|
|
1773
|
+
exports.createQuery = createQuery;
|
|
1774
|
+
exports.createSubscription = createSubscription;
|
|
1775
|
+
exports.deepMerge = deepMerge;
|
|
1776
|
+
exports.defaultSubscriptionResolve = defaultSubscriptionResolve;
|
|
1777
|
+
exports.ensureInputObjectType = ensureInputObjectType;
|
|
1778
|
+
exports.ensureInputType = ensureInputType;
|
|
1779
|
+
exports.ensureInterfaceType = ensureInterfaceType;
|
|
1780
|
+
exports.field = field;
|
|
1781
|
+
exports.filterMiddlewares = filterMiddlewares;
|
|
1782
|
+
exports.getCacheType = getCacheType;
|
|
1783
|
+
exports.getDeepResolvingFields = require_context.getDeepResolvingFields;
|
|
1784
|
+
exports.getFieldOptions = getFieldOptions;
|
|
1785
|
+
exports.getGraphQLType = getGraphQLType;
|
|
1786
|
+
exports.getMemoizationMap = require_context.getMemoizationMap;
|
|
1787
|
+
exports.getOperationOptions = getOperationOptions;
|
|
1788
|
+
exports.getResolvingFields = require_context.getResolvingFields;
|
|
1789
|
+
exports.getStandardValue = getStandardValue;
|
|
1790
|
+
exports.getSubscriptionOptions = getSubscriptionOptions;
|
|
1791
|
+
exports.initWeaverContext = initWeaverContext;
|
|
1792
|
+
exports.inputToArgs = inputToArgs;
|
|
1793
|
+
exports.isOnlyMemoryPayload = require_context.isOnlyMemoryPayload;
|
|
1794
|
+
exports.isSchemaVendorWeaver = isSchemaVendorWeaver;
|
|
1795
|
+
exports.isSilk = isSilk;
|
|
1796
|
+
exports.listSilk = listSilk;
|
|
1797
|
+
exports.loom = loom;
|
|
1798
|
+
exports.mapValue = mapValue;
|
|
1799
|
+
exports.markErrorLocation = markErrorLocation;
|
|
1800
|
+
exports.markLocation = markLocation;
|
|
1801
|
+
exports.meta = meta;
|
|
1802
|
+
exports.mutation = mutation;
|
|
1803
|
+
exports.nonNullSilk = nonNullSilk;
|
|
1804
|
+
exports.notNullish = notNullish;
|
|
1805
|
+
exports.nullableSilk = nullableSilk;
|
|
1806
|
+
exports.onlyMemoization = require_context.onlyMemoization;
|
|
1807
|
+
exports.parseInputValue = parseInputValue;
|
|
1808
|
+
exports.parseResolvingFields = require_context.parseResolvingFields;
|
|
1809
|
+
exports.parseSilk = parseSilk;
|
|
1810
|
+
exports.pascalCase = pascalCase;
|
|
1811
|
+
exports.provideWeaverContext = provideWeaverContext;
|
|
1812
|
+
exports.query = query;
|
|
1813
|
+
exports.resolver = resolver;
|
|
1814
|
+
exports.screamingSnakeCase = screamingSnakeCase;
|
|
1815
|
+
exports.silk = silk;
|
|
1816
|
+
exports.subscription = subscription;
|
|
1817
|
+
exports.toObjMap = toObjMap;
|
|
1818
|
+
exports.tryIn = tryIn;
|
|
1819
|
+
exports.weave = weave;
|
|
1820
|
+
exports.weaverContext = weaverContext;
|