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