@gqloom/core 0.10.1 → 0.11.1

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