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