@gqloom/core 0.12.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-CTAAG5j7.js → chunk-Bp6m_JJh.js} +1 -1
- package/dist/context.cjs +9 -9
- package/dist/context.d.cts +5 -6
- package/dist/context.d.ts +5 -6
- package/dist/context.js +1 -1
- package/dist/{index-sGKC4BRu.d.ts → index-BdLdDytD.d.ts} +433 -404
- package/dist/{index-BxqR3YsC.d.cts → index-C26E_cfW.d.cts} +433 -404
- package/dist/index.cjs +440 -429
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +409 -399
- package/dist/{context-BxqO4Eg9.js → parse-resolving-fields-CH8rJgks.js} +102 -79
- package/dist/{context-DshDoxiE.cjs → parse-resolving-fields-Czn0O39L.cjs} +106 -77
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,244 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_parse_resolving_fields = require('./parse-resolving-fields-Czn0O39L.cjs');
|
|
2
2
|
let graphql = require("graphql");
|
|
3
|
-
graphql =
|
|
3
|
+
graphql = require_parse_resolving_fields.__toESM(graphql);
|
|
4
4
|
|
|
5
|
-
//#region src/utils/args.ts
|
|
6
|
-
function getOperationOptions(resolveOrOptions) {
|
|
7
|
-
if (typeof resolveOrOptions === "function") return { resolve: resolveOrOptions };
|
|
8
|
-
return resolveOrOptions;
|
|
9
|
-
}
|
|
10
|
-
function getSubscriptionOptions(subscribeOrOptions) {
|
|
11
|
-
if (typeof subscribeOrOptions === "function") return { subscribe: subscribeOrOptions };
|
|
12
|
-
return subscribeOrOptions;
|
|
13
|
-
}
|
|
14
|
-
function getFieldOptions({ description, deprecationReason, extensions }, extraExtensions) {
|
|
15
|
-
return {
|
|
16
|
-
description,
|
|
17
|
-
deprecationReason,
|
|
18
|
-
extensions: extraExtensions ? {
|
|
19
|
-
...extensions,
|
|
20
|
-
...extraExtensions
|
|
21
|
-
} : extensions
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/utils/middleware.ts
|
|
27
|
-
const defaultOperations = [
|
|
28
|
-
"field",
|
|
29
|
-
"mutation",
|
|
30
|
-
"query",
|
|
31
|
-
"subscription.subscribe"
|
|
32
|
-
];
|
|
33
|
-
function applyMiddlewares(options, resolveFunction, middlewares) {
|
|
34
|
-
const next = (index) => {
|
|
35
|
-
if (index >= middlewares.length) return resolveFunction();
|
|
36
|
-
const middleware = middlewares[index];
|
|
37
|
-
const callableOptions = Object.assign(() => next(index + 1), {
|
|
38
|
-
...options,
|
|
39
|
-
next: () => next(index + 1)
|
|
40
|
-
});
|
|
41
|
-
return middleware(callableOptions);
|
|
42
|
-
};
|
|
43
|
-
return next(0);
|
|
44
|
-
}
|
|
45
|
-
function filterMiddlewares(operation, ...middlewareList) {
|
|
46
|
-
return middlewareList.reduce((acc, m) => {
|
|
47
|
-
if (!m) return acc;
|
|
48
|
-
acc.push(...ensureArray(m).filter((m$1) => {
|
|
49
|
-
return (m$1.operations ?? defaultOperations).includes(operation);
|
|
50
|
-
}));
|
|
51
|
-
return acc;
|
|
52
|
-
}, []);
|
|
53
|
-
}
|
|
54
|
-
function ensureArray(value) {
|
|
55
|
-
if (value != null && typeof value === "object" && Symbol.iterator in value) return Array.from(value);
|
|
56
|
-
return [value];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/utils/object.ts
|
|
61
|
-
/**
|
|
62
|
-
* Creates an object map with the same keys as `map` and values generated by
|
|
63
|
-
* running each value of `record` thru `fn`.
|
|
64
|
-
*/
|
|
65
|
-
function mapValue(record, fn) {
|
|
66
|
-
const result = Object.create(null);
|
|
67
|
-
for (const key of Object.keys(record)) {
|
|
68
|
-
const value = fn(record[key], key);
|
|
69
|
-
if (value === SKIP) continue;
|
|
70
|
-
result[key] = value;
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
const SKIP = Symbol.for("mapValue.skip");
|
|
75
|
-
mapValue.SKIP = SKIP;
|
|
76
|
-
function toObjMap(obj) {
|
|
77
|
-
if (obj == null) return Object.create(null);
|
|
78
|
-
if (Object.getPrototypeOf(obj) === null) return obj;
|
|
79
|
-
const map = Object.create(null);
|
|
80
|
-
for (const [key, value] of Object.entries(obj)) map[key] = value;
|
|
81
|
-
return map;
|
|
82
|
-
}
|
|
83
|
-
function notNullish(x) {
|
|
84
|
-
return x != null;
|
|
85
|
-
}
|
|
86
|
-
function deepMerge(...objects) {
|
|
87
|
-
const result = {};
|
|
88
|
-
for (const obj of objects) {
|
|
89
|
-
if (obj == null) continue;
|
|
90
|
-
for (const [key, value] of Object.entries(obj)) if (value !== null && typeof value === "object") if (Array.isArray(value)) {
|
|
91
|
-
if (!Array.isArray(result[key])) result[key] = [];
|
|
92
|
-
result[key] = [...result[key], ...value];
|
|
93
|
-
} else result[key] = deepMerge(result[key], value);
|
|
94
|
-
else result[key] = value;
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Wraps the provided data in an object with a single key `"~meta"`.
|
|
100
|
-
*
|
|
101
|
-
* @template T - The type of the data to be wrapped.
|
|
102
|
-
* @param {T} data - The data to be wrapped.
|
|
103
|
-
* @returns {{ "~meta": T }} - An object with a single key `"~meta"` containing the provided data.
|
|
104
|
-
* @example
|
|
105
|
-
* const originalData = { key: "value" };
|
|
106
|
-
* const metaData = meta(originalData);
|
|
107
|
-
* console.log(metaData); // Output: { "~meta": { key: "value" } }
|
|
108
|
-
*/
|
|
109
|
-
function meta(data) {
|
|
110
|
-
return { "~meta": data };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/utils/string.ts
|
|
115
|
-
function pascalCase(str) {
|
|
116
|
-
return str.split(/[\s-_]+/).map((word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
117
|
-
}
|
|
118
|
-
function capitalize(str) {
|
|
119
|
-
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
120
|
-
}
|
|
121
|
-
function screamingSnakeCase(str) {
|
|
122
|
-
return str.replace(/([a-z])([A-Z])/g, "$1_$2").split(/[\s-_]+/).map((word) => word.toUpperCase()).join("_");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region src/utils/error.ts
|
|
127
|
-
function markErrorLocation(error, ...locations) {
|
|
128
|
-
if (error instanceof Error) error.message = markLocation(error.message, ...locations);
|
|
129
|
-
return error;
|
|
130
|
-
}
|
|
131
|
-
function tryIn(func, ...locations) {
|
|
132
|
-
try {
|
|
133
|
-
return func();
|
|
134
|
-
} catch (error) {
|
|
135
|
-
throw markErrorLocation(error, ...locations);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* mark message with location
|
|
140
|
-
* @param message origin message
|
|
141
|
-
* @param locations where error happened
|
|
142
|
-
* @returns message with location
|
|
143
|
-
* @example markLocation("error", "banana") // "[banana] hello"
|
|
144
|
-
* @example markLocation("error", fruit, banana) // "[fruit.banana] error"
|
|
145
|
-
* @example markLocation("[banana] error", "fruit") // "[fruit.banana] error"
|
|
146
|
-
* @example markLocation("[fruit.banana] error", "favorite") // "[favorite.fruit.banana] error"
|
|
147
|
-
*/
|
|
148
|
-
function markLocation(message, ...locations) {
|
|
149
|
-
if (locations.length === 0) return message;
|
|
150
|
-
const [existingPrefix, newMessage] = (() => {
|
|
151
|
-
const match = /^\[(.*?)\]/.exec(message);
|
|
152
|
-
if (match) return [match[1], message.slice(match[0].length).trim()];
|
|
153
|
-
return [void 0, message];
|
|
154
|
-
})();
|
|
155
|
-
return `[${locations.concat(existingPrefix ? [existingPrefix] : []).join(".")}] ${newMessage}`;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/utils/loader.ts
|
|
160
|
-
/**
|
|
161
|
-
* GraphQL Loom built-in data loader.
|
|
162
|
-
*/
|
|
163
|
-
var LoomDataLoader = class LoomDataLoader {
|
|
164
|
-
results;
|
|
165
|
-
resolvers;
|
|
166
|
-
constructor() {
|
|
167
|
-
this.results = /* @__PURE__ */ new Map();
|
|
168
|
-
this.resolvers = /* @__PURE__ */ new Map();
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Load data for a given key.
|
|
172
|
-
* @param key - The key to load data for.
|
|
173
|
-
* @returns A promise that resolves to the loaded data.
|
|
174
|
-
*/
|
|
175
|
-
load(key) {
|
|
176
|
-
const existing = this.results.get(key);
|
|
177
|
-
if (existing) return existing;
|
|
178
|
-
const promise = new Promise((resolve, reject) => {
|
|
179
|
-
this.resolvers.set(key, [resolve, reject]);
|
|
180
|
-
this.nextTickBatchLoad();
|
|
181
|
-
});
|
|
182
|
-
this.results.set(key, promise);
|
|
183
|
-
return promise;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Clear the cache and reset the loader.
|
|
187
|
-
*/
|
|
188
|
-
clear() {
|
|
189
|
-
this.results = /* @__PURE__ */ new Map();
|
|
190
|
-
this.resolvers = /* @__PURE__ */ new Map();
|
|
191
|
-
}
|
|
192
|
-
async executeBatchLoad() {
|
|
193
|
-
if (this.resolvers.size === 0) return;
|
|
194
|
-
const resolvers = this.resolvers;
|
|
195
|
-
this.resolvers = /* @__PURE__ */ new Map();
|
|
196
|
-
const keys = Array.from(resolvers.keys());
|
|
197
|
-
try {
|
|
198
|
-
const list = await this.batchLoad(keys);
|
|
199
|
-
for (let i = 0; i < list.length; i++) {
|
|
200
|
-
const data = list[i];
|
|
201
|
-
const [resolve, reject] = resolvers.get(keys[i]) ?? [];
|
|
202
|
-
if (data instanceof Error) reject?.(data);
|
|
203
|
-
else resolve?.(data);
|
|
204
|
-
}
|
|
205
|
-
} catch (error) {
|
|
206
|
-
for (const key of keys) {
|
|
207
|
-
const reject = resolvers.get(key)?.[1];
|
|
208
|
-
reject?.(error);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
nextTickPromise;
|
|
213
|
-
nextTickBatchLoad() {
|
|
214
|
-
const load = async () => {
|
|
215
|
-
try {
|
|
216
|
-
while (this.resolvers.size > 0) {
|
|
217
|
-
await LoomDataLoader.nextTick();
|
|
218
|
-
await this.executeBatchLoad();
|
|
219
|
-
}
|
|
220
|
-
} finally {
|
|
221
|
-
this.nextTickPromise = void 0;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
this.nextTickPromise ??= load();
|
|
225
|
-
return this.nextTickPromise;
|
|
226
|
-
}
|
|
227
|
-
static nextTick() {
|
|
228
|
-
return new Promise((resolve) => setTimeout(resolve));
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
var EasyDataLoader = class extends LoomDataLoader {
|
|
232
|
-
batchLoad(keys) {
|
|
233
|
-
return this.batchLoadFn(keys);
|
|
234
|
-
}
|
|
235
|
-
constructor(batchLoadFn) {
|
|
236
|
-
super();
|
|
237
|
-
this.batchLoadFn = batchLoadFn;
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
//#endregion
|
|
242
5
|
//#region src/schema/weaver-context.ts
|
|
243
6
|
var WeaverContext = class WeaverContext {
|
|
244
7
|
static increasingID = 1;
|
|
@@ -270,7 +33,7 @@ var WeaverContext = class WeaverContext {
|
|
|
270
33
|
return this.configs.get(key);
|
|
271
34
|
}
|
|
272
35
|
setConfig(config) {
|
|
273
|
-
const key = config[
|
|
36
|
+
const key = config[require_parse_resolving_fields.WEAVER_CONFIG];
|
|
274
37
|
this.configs.set(key, config);
|
|
275
38
|
}
|
|
276
39
|
deleteConfig(key) {
|
|
@@ -293,12 +56,12 @@ var WeaverContext = class WeaverContext {
|
|
|
293
56
|
};
|
|
294
57
|
aliasCounters = {};
|
|
295
58
|
setAlias(namedType, alias) {
|
|
296
|
-
if (namedType.name ===
|
|
59
|
+
if (namedType.name === require_parse_resolving_fields.AUTO_ALIASING) WeaverContext.autoAliasTypes.add(namedType);
|
|
297
60
|
if (!WeaverContext.autoAliasTypes.has(namedType)) return namedType.name;
|
|
298
61
|
if (WeaverContext.higherPriorityThan(alias, namedType.name) < 0) {
|
|
299
62
|
if (alias) return namedType.name = alias;
|
|
300
63
|
}
|
|
301
|
-
if (namedType.name ===
|
|
64
|
+
if (namedType.name === require_parse_resolving_fields.AUTO_ALIASING) {
|
|
302
65
|
if ((0, graphql.isObjectType)(namedType) || (0, graphql.isInputObjectType)(namedType)) {
|
|
303
66
|
this.aliasCounters["Object"] ??= 0;
|
|
304
67
|
return namedType.name = `Object${++this.aliasCounters["Object"]}`;
|
|
@@ -321,8 +84,8 @@ var WeaverContext = class WeaverContext {
|
|
|
321
84
|
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
322
85
|
*/
|
|
323
86
|
static higherPriorityThan(a, b) {
|
|
324
|
-
if (a ===
|
|
325
|
-
else if (b ===
|
|
87
|
+
if (a === require_parse_resolving_fields.AUTO_ALIASING || a === void 0) return 1;
|
|
88
|
+
else if (b === require_parse_resolving_fields.AUTO_ALIASING || b === void 0) return -1;
|
|
326
89
|
const compareLength = a.length - b.length;
|
|
327
90
|
if (compareLength !== 0) return compareLength;
|
|
328
91
|
const compareLocale = a.localeCompare(b);
|
|
@@ -389,7 +152,7 @@ var GlobalWeaverContext = class {
|
|
|
389
152
|
const context = this.value ?? initWeaverContext();
|
|
390
153
|
context.setConfig(config);
|
|
391
154
|
const result = provideWeaverContext(callback, context);
|
|
392
|
-
context.deleteConfig(config[
|
|
155
|
+
context.deleteConfig(config[require_parse_resolving_fields.WEAVER_CONFIG]);
|
|
393
156
|
return result;
|
|
394
157
|
}
|
|
395
158
|
getNamedType(name) {
|
|
@@ -421,152 +184,402 @@ function collectNames(...namesList) {
|
|
|
421
184
|
WeaverContext.names.set(schema, name);
|
|
422
185
|
namesRecord[name] = schema;
|
|
423
186
|
}
|
|
424
|
-
return namesRecord;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* collect name for schema
|
|
428
|
-
* @param name - name for
|
|
429
|
-
* @param schema - schema to be named
|
|
430
|
-
* @returns schema
|
|
431
|
-
*/
|
|
432
|
-
function collectName(name, schema) {
|
|
433
|
-
WeaverContext.names.set(schema, name);
|
|
434
|
-
return schema;
|
|
435
|
-
}
|
|
187
|
+
return namesRecord;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* collect name for schema
|
|
191
|
+
* @param name - name for
|
|
192
|
+
* @param schema - schema to be named
|
|
193
|
+
* @returns schema
|
|
194
|
+
*/
|
|
195
|
+
function collectName(name, schema) {
|
|
196
|
+
WeaverContext.names.set(schema, name);
|
|
197
|
+
return schema;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/resolver/silk.ts
|
|
202
|
+
function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
|
|
203
|
+
return {
|
|
204
|
+
[require_parse_resolving_fields.GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
205
|
+
"~standard": {
|
|
206
|
+
version: 1,
|
|
207
|
+
vendor: "gqloom.silk",
|
|
208
|
+
validate
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
silk.parse = parseSilk;
|
|
213
|
+
silk.getType = getGraphQLType;
|
|
214
|
+
silk.nonNull = nonNullSilk;
|
|
215
|
+
silk.list = listSilk;
|
|
216
|
+
silk.nullable = nullableSilk;
|
|
217
|
+
/**
|
|
218
|
+
* Non-nullable Silk.
|
|
219
|
+
*/
|
|
220
|
+
function nonNullSilk(origin) {
|
|
221
|
+
return {
|
|
222
|
+
...origin,
|
|
223
|
+
[require_parse_resolving_fields.GET_GRAPHQL_TYPE]: () => {
|
|
224
|
+
const originType = getGraphQLType(origin);
|
|
225
|
+
if (originType instanceof graphql.GraphQLNonNull) return originType;
|
|
226
|
+
else return new graphql.GraphQLNonNull(originType);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* List Silk.
|
|
232
|
+
*/
|
|
233
|
+
function listSilk(origin) {
|
|
234
|
+
return {
|
|
235
|
+
...origin,
|
|
236
|
+
[require_parse_resolving_fields.GET_GRAPHQL_TYPE]: () => {
|
|
237
|
+
let originType = getGraphQLType(origin);
|
|
238
|
+
if (originType instanceof graphql.GraphQLNonNull && originType.ofType instanceof graphql.GraphQLList) originType = originType.ofType.ofType;
|
|
239
|
+
if (originType instanceof graphql.GraphQLList) originType = originType.ofType;
|
|
240
|
+
return new graphql.GraphQLNonNull(new graphql.GraphQLList(originType));
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Nullable Silk.
|
|
246
|
+
*/
|
|
247
|
+
function nullableSilk(origin) {
|
|
248
|
+
return {
|
|
249
|
+
...origin,
|
|
250
|
+
[require_parse_resolving_fields.GET_GRAPHQL_TYPE]: () => {
|
|
251
|
+
const originType = getGraphQLType(origin);
|
|
252
|
+
if (originType instanceof graphql.GraphQLNonNull) return originType.ofType;
|
|
253
|
+
else return originType;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get GraphQL Output Type from Silk.
|
|
259
|
+
* @param silk GraphQL Silk
|
|
260
|
+
* @returns GraphQL Output Type
|
|
261
|
+
*/
|
|
262
|
+
function getGraphQLType(silk$1) {
|
|
263
|
+
if (require_parse_resolving_fields.GET_GRAPHQL_TYPE in silk$1 && silk$1[require_parse_resolving_fields.GET_GRAPHQL_TYPE] != null) return typeof silk$1[require_parse_resolving_fields.GET_GRAPHQL_TYPE] === "function" ? silk$1[require_parse_resolving_fields.GET_GRAPHQL_TYPE]() : silk$1[require_parse_resolving_fields.GET_GRAPHQL_TYPE];
|
|
264
|
+
const vendorWeavers = weaverContext.vendorWeavers;
|
|
265
|
+
if (vendorWeavers == null) throw new Error("Schema Weaver is not initialized");
|
|
266
|
+
const weaver = vendorWeavers.get(silk$1["~standard"].vendor);
|
|
267
|
+
if (weaver == null) throw new Error(`Schema Weaver for ${silk$1["~standard"].vendor} is not found`);
|
|
268
|
+
return weaver.getGraphQLType(silk$1);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get GraphQL Argument Config from Silk.
|
|
272
|
+
* @param silk GraphQL Silk
|
|
273
|
+
* @returns GraphQL Argument Config
|
|
274
|
+
*/
|
|
275
|
+
function getGraphQLArgumentConfig(silk$1) {
|
|
276
|
+
if (require_parse_resolving_fields.GET_GRAPHQL_ARGUMENT_CONFIG in silk$1 && silk$1[require_parse_resolving_fields.GET_GRAPHQL_ARGUMENT_CONFIG] != null) return typeof silk$1[require_parse_resolving_fields.GET_GRAPHQL_ARGUMENT_CONFIG] === "function" ? silk$1[require_parse_resolving_fields.GET_GRAPHQL_ARGUMENT_CONFIG]() : silk$1[require_parse_resolving_fields.GET_GRAPHQL_ARGUMENT_CONFIG];
|
|
277
|
+
const vendorWeavers = weaverContext.vendorWeavers;
|
|
278
|
+
if (vendorWeavers == null) return void 0;
|
|
279
|
+
const weaver = vendorWeavers.get(silk$1["~standard"]?.vendor);
|
|
280
|
+
if (weaver == null) return void 0;
|
|
281
|
+
if (weaver.getGraphQLArgumentConfig == null) return void 0;
|
|
282
|
+
return weaver.getGraphQLArgumentConfig(silk$1);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Validate and transform input to output
|
|
286
|
+
* @param silk silk GraphQL Silk
|
|
287
|
+
* @param input
|
|
288
|
+
* @returns output
|
|
289
|
+
*/
|
|
290
|
+
function parseSilk(silk$1, input) {
|
|
291
|
+
return silk$1["~standard"].validate(input);
|
|
292
|
+
}
|
|
293
|
+
function isSilk(target) {
|
|
294
|
+
if (typeof target !== "object" && typeof target !== "function") return false;
|
|
295
|
+
if (target == null) return false;
|
|
296
|
+
if (require_parse_resolving_fields.GET_GRAPHQL_TYPE in target) return true;
|
|
297
|
+
if (!("~standard" in target)) return false;
|
|
298
|
+
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/resolver/input.ts
|
|
303
|
+
function createInputParser(schema, value) {
|
|
304
|
+
let result;
|
|
305
|
+
const parse = async () => {
|
|
306
|
+
if (result !== void 0) return result;
|
|
307
|
+
result = await parseInputValue(schema, value);
|
|
308
|
+
return result;
|
|
309
|
+
};
|
|
310
|
+
Object.assign(parse, {
|
|
311
|
+
schema,
|
|
312
|
+
value
|
|
313
|
+
});
|
|
314
|
+
Object.defineProperty(parse, "result", {
|
|
315
|
+
get: () => result,
|
|
316
|
+
set: (value$1) => result = value$1
|
|
317
|
+
});
|
|
318
|
+
Object.defineProperty(parse, "getResult", { value: async () => getStandardValue(await parse()) });
|
|
319
|
+
Object.defineProperty(parse, "setResult", { value: (value$1) => result = { value: value$1 } });
|
|
320
|
+
Object.defineProperty(parse, "clearResult", { value: () => result = void 0 });
|
|
321
|
+
return parse;
|
|
322
|
+
}
|
|
323
|
+
function parseInputValue(inputSchema, input) {
|
|
324
|
+
if (inputSchema === void 0) return { value: input };
|
|
325
|
+
if (isSilk(inputSchema)) return inputSchema["~standard"].validate(input);
|
|
326
|
+
return parseInputEntries(inputSchema, input);
|
|
327
|
+
}
|
|
328
|
+
async function parseInputEntries(inputSchema, input = {}) {
|
|
329
|
+
const result = {};
|
|
330
|
+
const issues = [];
|
|
331
|
+
await Promise.all(Object.entries(inputSchema).map(async ([key, value]) => {
|
|
332
|
+
const res = await value["~standard"].validate(input[key]);
|
|
333
|
+
if ("value" in res) result[key] = res.value;
|
|
334
|
+
if (res.issues) issues.push(...res.issues.slice());
|
|
335
|
+
}));
|
|
336
|
+
return {
|
|
337
|
+
value: result,
|
|
338
|
+
...issues.length > 0 ? { issues } : null
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function getStandardValue(result) {
|
|
342
|
+
if (result == null) return result;
|
|
343
|
+
const { issues } = result;
|
|
344
|
+
if (issues?.length) throw new graphql.GraphQLError(issues?.[0]?.message ?? "Invalid input", { extensions: { issues } });
|
|
345
|
+
if ("value" in result) return result.value;
|
|
346
|
+
else throw new graphql.GraphQLError("Invalid input");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/utils/args.ts
|
|
351
|
+
function getOperationOptions(resolveOrOptions) {
|
|
352
|
+
if (typeof resolveOrOptions === "function") return { resolve: resolveOrOptions };
|
|
353
|
+
return resolveOrOptions;
|
|
354
|
+
}
|
|
355
|
+
function getSubscriptionOptions(subscribeOrOptions) {
|
|
356
|
+
if (typeof subscribeOrOptions === "function") return { subscribe: subscribeOrOptions };
|
|
357
|
+
return subscribeOrOptions;
|
|
358
|
+
}
|
|
359
|
+
function getFieldOptions({ description, deprecationReason, extensions }, extraExtensions) {
|
|
360
|
+
return {
|
|
361
|
+
description,
|
|
362
|
+
deprecationReason,
|
|
363
|
+
extensions: extraExtensions ? {
|
|
364
|
+
...extensions,
|
|
365
|
+
...extraExtensions
|
|
366
|
+
} : extensions
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/utils/error.ts
|
|
372
|
+
function markErrorLocation(error, ...locations) {
|
|
373
|
+
if (error instanceof Error) error.message = markLocation(error.message, ...locations);
|
|
374
|
+
return error;
|
|
375
|
+
}
|
|
376
|
+
function tryIn(func, ...locations) {
|
|
377
|
+
try {
|
|
378
|
+
return func();
|
|
379
|
+
} catch (error) {
|
|
380
|
+
throw markErrorLocation(error, ...locations);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* mark message with location
|
|
385
|
+
* @param message origin message
|
|
386
|
+
* @param locations where error happened
|
|
387
|
+
* @returns message with location
|
|
388
|
+
* @example markLocation("error", "banana") // "[banana] hello"
|
|
389
|
+
* @example markLocation("error", fruit, banana) // "[fruit.banana] error"
|
|
390
|
+
* @example markLocation("[banana] error", "fruit") // "[fruit.banana] error"
|
|
391
|
+
* @example markLocation("[fruit.banana] error", "favorite") // "[favorite.fruit.banana] error"
|
|
392
|
+
*/
|
|
393
|
+
function markLocation(message, ...locations) {
|
|
394
|
+
if (locations.length === 0) return message;
|
|
395
|
+
const [existingPrefix, newMessage] = (() => {
|
|
396
|
+
const match = /^\[(.*?)\]/.exec(message);
|
|
397
|
+
if (match) return [match[1], message.slice(match[0].length).trim()];
|
|
398
|
+
return [void 0, message];
|
|
399
|
+
})();
|
|
400
|
+
return `[${locations.concat(existingPrefix ? [existingPrefix] : []).join(".")}] ${newMessage}`;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/utils/loader.ts
|
|
405
|
+
/**
|
|
406
|
+
* GraphQL Loom built-in data loader.
|
|
407
|
+
*/
|
|
408
|
+
var LoomDataLoader = class LoomDataLoader {
|
|
409
|
+
results;
|
|
410
|
+
resolvers;
|
|
411
|
+
constructor() {
|
|
412
|
+
this.results = /* @__PURE__ */ new Map();
|
|
413
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Load data for a given key.
|
|
417
|
+
* @param key - The key to load data for.
|
|
418
|
+
* @returns A promise that resolves to the loaded data.
|
|
419
|
+
*/
|
|
420
|
+
load(key) {
|
|
421
|
+
const existing = this.results.get(key);
|
|
422
|
+
if (existing) return existing;
|
|
423
|
+
const promise = new Promise((resolve, reject) => {
|
|
424
|
+
this.resolvers.set(key, [resolve, reject]);
|
|
425
|
+
this.nextTickBatchLoad();
|
|
426
|
+
});
|
|
427
|
+
this.results.set(key, promise);
|
|
428
|
+
return promise;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Clear the cache and reset the loader.
|
|
432
|
+
*/
|
|
433
|
+
clear() {
|
|
434
|
+
this.results = /* @__PURE__ */ new Map();
|
|
435
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
436
|
+
}
|
|
437
|
+
async executeBatchLoad() {
|
|
438
|
+
if (this.resolvers.size === 0) return;
|
|
439
|
+
const resolvers = this.resolvers;
|
|
440
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
441
|
+
const keys = Array.from(resolvers.keys());
|
|
442
|
+
try {
|
|
443
|
+
const list = await this.batchLoad(keys);
|
|
444
|
+
for (let i = 0; i < list.length; i++) {
|
|
445
|
+
const data = list[i];
|
|
446
|
+
const [resolve, reject] = resolvers.get(keys[i]) ?? [];
|
|
447
|
+
if (data instanceof Error) reject?.(data);
|
|
448
|
+
else resolve?.(data);
|
|
449
|
+
}
|
|
450
|
+
} catch (error) {
|
|
451
|
+
for (const key of keys) {
|
|
452
|
+
const reject = resolvers.get(key)?.[1];
|
|
453
|
+
reject?.(error);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
nextTickPromise;
|
|
458
|
+
nextTickBatchLoad() {
|
|
459
|
+
const load = async () => {
|
|
460
|
+
try {
|
|
461
|
+
while (this.resolvers.size > 0) {
|
|
462
|
+
await LoomDataLoader.nextTick();
|
|
463
|
+
await this.executeBatchLoad();
|
|
464
|
+
}
|
|
465
|
+
} finally {
|
|
466
|
+
this.nextTickPromise = void 0;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
this.nextTickPromise ??= load();
|
|
470
|
+
return this.nextTickPromise;
|
|
471
|
+
}
|
|
472
|
+
static nextTick() {
|
|
473
|
+
return new Promise((resolve) => setTimeout(resolve));
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
var EasyDataLoader = class extends LoomDataLoader {
|
|
477
|
+
batchLoad(keys) {
|
|
478
|
+
return this.batchLoadFn(keys);
|
|
479
|
+
}
|
|
480
|
+
constructor(batchLoadFn) {
|
|
481
|
+
super();
|
|
482
|
+
this.batchLoadFn = batchLoadFn;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
436
485
|
|
|
437
486
|
//#endregion
|
|
438
|
-
//#region src/
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
487
|
+
//#region src/utils/middleware.ts
|
|
488
|
+
const defaultOperations = [
|
|
489
|
+
"field",
|
|
490
|
+
"mutation",
|
|
491
|
+
"query",
|
|
492
|
+
"subscription.subscribe"
|
|
493
|
+
];
|
|
494
|
+
function applyMiddlewares(options, resolveFunction, middlewares) {
|
|
495
|
+
const next = (index) => {
|
|
496
|
+
if (index >= middlewares.length) return resolveFunction();
|
|
497
|
+
const middleware = middlewares[index];
|
|
498
|
+
return middleware(Object.assign(() => next(index + 1), {
|
|
499
|
+
...options,
|
|
500
|
+
next: () => next(index + 1)
|
|
501
|
+
}));
|
|
447
502
|
};
|
|
503
|
+
return next(0);
|
|
448
504
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
function nonNullSilk(origin) {
|
|
458
|
-
return {
|
|
459
|
-
...origin,
|
|
460
|
-
[require_context.GET_GRAPHQL_TYPE]: () => {
|
|
461
|
-
const originType = getGraphQLType(origin);
|
|
462
|
-
if (originType instanceof graphql.GraphQLNonNull) return originType;
|
|
463
|
-
else return new graphql.GraphQLNonNull(originType);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
505
|
+
function filterMiddlewares(operation, ...middlewareList) {
|
|
506
|
+
return middlewareList.reduce((acc, m) => {
|
|
507
|
+
if (!m) return acc;
|
|
508
|
+
acc.push(...ensureArray(m).filter((m$1) => {
|
|
509
|
+
return (m$1.operations ?? defaultOperations).includes(operation);
|
|
510
|
+
}));
|
|
511
|
+
return acc;
|
|
512
|
+
}, []);
|
|
466
513
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
function listSilk(origin) {
|
|
471
|
-
return {
|
|
472
|
-
...origin,
|
|
473
|
-
[require_context.GET_GRAPHQL_TYPE]: () => {
|
|
474
|
-
let originType = getGraphQLType(origin);
|
|
475
|
-
if (originType instanceof graphql.GraphQLNonNull && originType.ofType instanceof graphql.GraphQLList) originType = originType.ofType.ofType;
|
|
476
|
-
if (originType instanceof graphql.GraphQLList) originType = originType.ofType;
|
|
477
|
-
return new graphql.GraphQLNonNull(new graphql.GraphQLList(originType));
|
|
478
|
-
}
|
|
479
|
-
};
|
|
514
|
+
function ensureArray(value) {
|
|
515
|
+
if (value != null && typeof value === "object" && Symbol.iterator in value) return Array.from(value);
|
|
516
|
+
return [value];
|
|
480
517
|
}
|
|
518
|
+
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region src/utils/object.ts
|
|
481
521
|
/**
|
|
482
|
-
*
|
|
522
|
+
* Creates an object map with the same keys as `map` and values generated by
|
|
523
|
+
* running each value of `record` thru `fn`.
|
|
483
524
|
*/
|
|
484
|
-
function
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
[
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
};
|
|
525
|
+
function mapValue(record, fn) {
|
|
526
|
+
const result = Object.create(null);
|
|
527
|
+
for (const key of Object.keys(record)) {
|
|
528
|
+
const value = fn(record[key], key);
|
|
529
|
+
if (value === SKIP) continue;
|
|
530
|
+
result[key] = value;
|
|
531
|
+
}
|
|
532
|
+
return result;
|
|
493
533
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
534
|
+
const SKIP = Symbol.for("mapValue.skip");
|
|
535
|
+
mapValue.SKIP = SKIP;
|
|
536
|
+
function toObjMap(obj) {
|
|
537
|
+
if (obj == null) return Object.create(null);
|
|
538
|
+
if (Object.getPrototypeOf(obj) === null) return obj;
|
|
539
|
+
const map = Object.create(null);
|
|
540
|
+
for (const [key, value] of Object.entries(obj)) map[key] = value;
|
|
541
|
+
return map;
|
|
542
|
+
}
|
|
543
|
+
function notNullish(x) {
|
|
544
|
+
return x != null;
|
|
545
|
+
}
|
|
546
|
+
function deepMerge(...objects) {
|
|
547
|
+
const result = {};
|
|
548
|
+
for (const obj of objects) {
|
|
549
|
+
if (obj == null) continue;
|
|
550
|
+
for (const [key, value] of Object.entries(obj)) if (value !== null && typeof value === "object") if (Array.isArray(value)) {
|
|
551
|
+
if (!Array.isArray(result[key])) result[key] = [];
|
|
552
|
+
result[key] = [...result[key], ...value];
|
|
553
|
+
} else result[key] = deepMerge(result[key], value);
|
|
554
|
+
else result[key] = value;
|
|
555
|
+
}
|
|
556
|
+
return result;
|
|
506
557
|
}
|
|
507
558
|
/**
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
* @
|
|
511
|
-
* @
|
|
559
|
+
* Wraps the provided data in an object with a single key `"~meta"`.
|
|
560
|
+
*
|
|
561
|
+
* @template T - The type of the data to be wrapped.
|
|
562
|
+
* @param {T} data - The data to be wrapped.
|
|
563
|
+
* @returns {{ "~meta": T }} - An object with a single key `"~meta"` containing the provided data.
|
|
564
|
+
* @example
|
|
565
|
+
* const originalData = { key: "value" };
|
|
566
|
+
* const metaData = meta(originalData);
|
|
567
|
+
* console.log(metaData); // Output: { "~meta": { key: "value" } }
|
|
512
568
|
*/
|
|
513
|
-
function
|
|
514
|
-
return
|
|
515
|
-
}
|
|
516
|
-
function isSilk(target) {
|
|
517
|
-
if (typeof target !== "object" && typeof target !== "function") return false;
|
|
518
|
-
if (target == null) return false;
|
|
519
|
-
if (require_context.GET_GRAPHQL_TYPE in target) return true;
|
|
520
|
-
if (!("~standard" in target)) return false;
|
|
521
|
-
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
569
|
+
function meta(data) {
|
|
570
|
+
return { "~meta": data };
|
|
522
571
|
}
|
|
523
572
|
|
|
524
573
|
//#endregion
|
|
525
|
-
//#region src/
|
|
526
|
-
function
|
|
527
|
-
|
|
528
|
-
const parse = async () => {
|
|
529
|
-
if (result !== void 0) return result;
|
|
530
|
-
result = await parseInputValue(schema, value);
|
|
531
|
-
return result;
|
|
532
|
-
};
|
|
533
|
-
Object.assign(parse, {
|
|
534
|
-
schema,
|
|
535
|
-
value
|
|
536
|
-
});
|
|
537
|
-
Object.defineProperty(parse, "result", {
|
|
538
|
-
get: () => result,
|
|
539
|
-
set: (value$1) => result = value$1
|
|
540
|
-
});
|
|
541
|
-
Object.defineProperty(parse, "getResult", { value: async () => getStandardValue(await parse()) });
|
|
542
|
-
Object.defineProperty(parse, "setResult", { value: (value$1) => result = { value: value$1 } });
|
|
543
|
-
Object.defineProperty(parse, "clearResult", { value: () => result = void 0 });
|
|
544
|
-
return parse;
|
|
545
|
-
}
|
|
546
|
-
function parseInputValue(inputSchema, input) {
|
|
547
|
-
if (inputSchema === void 0) return { value: input };
|
|
548
|
-
if (isSilk(inputSchema)) return inputSchema["~standard"].validate(input);
|
|
549
|
-
return parseInputEntries(inputSchema, input);
|
|
574
|
+
//#region src/utils/string.ts
|
|
575
|
+
function pascalCase(str) {
|
|
576
|
+
return str.split(/[\s-_]+/).map((word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
550
577
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const issues = [];
|
|
554
|
-
await Promise.all(Object.entries(inputSchema).map(async ([key, value]) => {
|
|
555
|
-
const res = await value["~standard"].validate(input[key]);
|
|
556
|
-
if ("value" in res) result[key] = res.value;
|
|
557
|
-
if (res.issues) issues.push(...res.issues.slice());
|
|
558
|
-
}));
|
|
559
|
-
return {
|
|
560
|
-
value: result,
|
|
561
|
-
...issues.length > 0 ? { issues } : null
|
|
562
|
-
};
|
|
578
|
+
function capitalize(str) {
|
|
579
|
+
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
563
580
|
}
|
|
564
|
-
function
|
|
565
|
-
|
|
566
|
-
const { issues } = result;
|
|
567
|
-
if (issues?.length) throw new graphql.GraphQLError(issues?.[0]?.message ?? "Invalid input", { extensions: { issues } });
|
|
568
|
-
if ("value" in result) return result.value;
|
|
569
|
-
else throw new graphql.GraphQLError("Invalid input");
|
|
581
|
+
function screamingSnakeCase(str) {
|
|
582
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").split(/[\s-_]+/).map((word) => word.toUpperCase()).join("_");
|
|
570
583
|
}
|
|
571
584
|
|
|
572
585
|
//#endregion
|
|
@@ -625,7 +638,7 @@ var BaseChainFactory = class BaseChainFactory {
|
|
|
625
638
|
var FieldLoader = class FieldLoader extends LoomDataLoader {
|
|
626
639
|
static getByPath(payload, resolve, getByPath = true) {
|
|
627
640
|
if (!payload) return new FieldLoader(resolve);
|
|
628
|
-
const memoMap =
|
|
641
|
+
const memoMap = require_parse_resolving_fields.getMemoizationMap(payload);
|
|
629
642
|
if (!getByPath) {
|
|
630
643
|
const loader = memoMap.get(resolve) ?? new FieldLoader(resolve);
|
|
631
644
|
memoMap.set(resolve, loader);
|
|
@@ -1106,7 +1119,7 @@ const createField = (output, resolveOrOptions) => {
|
|
|
1106
1119
|
if (resolveOrOptions == null) return new FieldChainFactory({ output });
|
|
1107
1120
|
const options = getOperationOptions(resolveOrOptions);
|
|
1108
1121
|
return meta({
|
|
1109
|
-
...getFieldOptions(options, { [
|
|
1122
|
+
...getFieldOptions(options, { [require_parse_resolving_fields.DERIVED_DEPENDENCIES]: options.dependencies }),
|
|
1110
1123
|
input: options.input,
|
|
1111
1124
|
dependencies: options.dependencies,
|
|
1112
1125
|
output,
|
|
@@ -1118,7 +1131,7 @@ const createField = (output, resolveOrOptions) => {
|
|
|
1118
1131
|
/**
|
|
1119
1132
|
* Factory function for creating GraphQL fields with chainable configuration
|
|
1120
1133
|
*/
|
|
1121
|
-
const field = Object.assign(createField, { hidden:
|
|
1134
|
+
const field = Object.assign(createField, { hidden: require_parse_resolving_fields.FIELD_HIDDEN }, FieldChainFactory.methods());
|
|
1122
1135
|
/**
|
|
1123
1136
|
* Default subscription resolver that returns the source value
|
|
1124
1137
|
* @param source - The source value to resolve
|
|
@@ -1171,7 +1184,7 @@ var ChainResolver = class {
|
|
|
1171
1184
|
*/
|
|
1172
1185
|
constructor(fields, options) {
|
|
1173
1186
|
this.meta = {
|
|
1174
|
-
[
|
|
1187
|
+
[require_parse_resolving_fields.IS_RESOLVER]: true,
|
|
1175
1188
|
fields,
|
|
1176
1189
|
options
|
|
1177
1190
|
};
|
|
@@ -1196,7 +1209,7 @@ var ChainResolver = class {
|
|
|
1196
1209
|
return mapValue(this["~meta"].fields, (field$1) => this.toExecutorOperation(field$1, middlewares) ?? mapValue.SKIP);
|
|
1197
1210
|
}
|
|
1198
1211
|
toExecutorOperation(field$1, executorMiddlewares) {
|
|
1199
|
-
if (field$1 ===
|
|
1212
|
+
if (field$1 === require_parse_resolving_fields.FIELD_HIDDEN || field$1["~meta"].operation === "subscription") return;
|
|
1200
1213
|
const operation = field$1["~meta"].operation;
|
|
1201
1214
|
const middlewares = filterMiddlewares(operation, executorMiddlewares, this.meta.options?.middlewares, field$1["~meta"].middlewares);
|
|
1202
1215
|
if (field$1["~meta"].operation === "field") {
|
|
@@ -1242,7 +1255,7 @@ var ObjectChainResolver = class extends ChainResolver {
|
|
|
1242
1255
|
constructor(parent, fields, options) {
|
|
1243
1256
|
super(fields, options);
|
|
1244
1257
|
this.meta = {
|
|
1245
|
-
[
|
|
1258
|
+
[require_parse_resolving_fields.IS_RESOLVER]: true,
|
|
1246
1259
|
fields,
|
|
1247
1260
|
parent,
|
|
1248
1261
|
options
|
|
@@ -1277,8 +1290,7 @@ function inputToArgs(input, options) {
|
|
|
1277
1290
|
let inputType = getGraphQLType(input);
|
|
1278
1291
|
if ((0, graphql.isNonNullType)(inputType)) inputType = inputType.ofType;
|
|
1279
1292
|
if ((0, graphql.isObjectType)(inputType)) return mapValue(inputType.toConfig().fields, (it, key) => {
|
|
1280
|
-
|
|
1281
|
-
return toInputFieldConfig(it, { fieldName });
|
|
1293
|
+
return toInputFieldConfig(it, { fieldName: `${pascalCase(options.fieldName)}${pascalCase(key)}` });
|
|
1282
1294
|
});
|
|
1283
1295
|
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
1284
1296
|
}
|
|
@@ -1287,7 +1299,7 @@ function inputToArgs(input, options) {
|
|
|
1287
1299
|
tryIn(() => {
|
|
1288
1300
|
const fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
|
|
1289
1301
|
args[name] = {
|
|
1290
|
-
...field$1,
|
|
1302
|
+
...getGraphQLArgumentConfig(field$1),
|
|
1291
1303
|
type: ensureInputType(field$1, { fieldName })
|
|
1292
1304
|
};
|
|
1293
1305
|
}, name);
|
|
@@ -1304,7 +1316,7 @@ function ensureInputType(silkOrType, options) {
|
|
|
1304
1316
|
if ((0, graphql.isListType)(gqlType)) return new graphql.GraphQLList(ensureInputType(gqlType.ofType, options));
|
|
1305
1317
|
if ((0, graphql.isObjectType)(gqlType) || (0, graphql.isInterfaceType)(gqlType)) return ensureInputObjectType(gqlType, options);
|
|
1306
1318
|
if ((0, graphql.isEnumType)(gqlType)) {
|
|
1307
|
-
if (gqlType.name ===
|
|
1319
|
+
if (gqlType.name === require_parse_resolving_fields.AUTO_ALIASING) {
|
|
1308
1320
|
const alias = `${pascalCase(options.fieldName)}Input`;
|
|
1309
1321
|
weaverContext.setAlias(gqlType, alias);
|
|
1310
1322
|
}
|
|
@@ -1316,9 +1328,9 @@ function ensureInputObjectType(object, options) {
|
|
|
1316
1328
|
if ((0, graphql.isInputObjectType)(object)) return object;
|
|
1317
1329
|
const existing = weaverContext.inputMap?.get(object);
|
|
1318
1330
|
if (existing != null) return existing;
|
|
1319
|
-
const { astNode, extensionASTNodes, fields,...config } = object.toConfig();
|
|
1331
|
+
const { astNode: _1, extensionASTNodes: _2, fields,...config } = object.toConfig();
|
|
1320
1332
|
let name = object.name;
|
|
1321
|
-
if (name ===
|
|
1333
|
+
if (name === require_parse_resolving_fields.AUTO_ALIASING) name = `${pascalCase(options.fieldName)}Input`;
|
|
1322
1334
|
name = (weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n))(name);
|
|
1323
1335
|
const input = new graphql.GraphQLInputObjectType({
|
|
1324
1336
|
...config,
|
|
@@ -1364,7 +1376,7 @@ var LoomObjectType = class extends graphql.GraphQLObjectType {
|
|
|
1364
1376
|
this.globalOptions = options.globalOptions;
|
|
1365
1377
|
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
1366
1378
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
1367
|
-
if (this.name ===
|
|
1379
|
+
if (this.name === require_parse_resolving_fields.AUTO_ALIASING) WeaverContext.autoAliasTypes.add(this);
|
|
1368
1380
|
}
|
|
1369
1381
|
addAlias(alias) {
|
|
1370
1382
|
if (!WeaverContext.autoAliasTypes.has(this) || !alias) return;
|
|
@@ -1529,8 +1541,7 @@ function extract(field$1) {
|
|
|
1529
1541
|
};
|
|
1530
1542
|
}
|
|
1531
1543
|
function defineFieldMap(fields) {
|
|
1532
|
-
|
|
1533
|
-
return mapValue(fieldMap, (fieldConfig, fieldName) => {
|
|
1544
|
+
return mapValue((0, graphql.resolveObjMapThunk)(fields), (fieldConfig, fieldName) => {
|
|
1534
1545
|
const argsConfig = fieldConfig.args ?? {};
|
|
1535
1546
|
return {
|
|
1536
1547
|
name: (0, graphql.assertName)(fieldName),
|
|
@@ -1602,6 +1613,29 @@ function parentName(name) {
|
|
|
1602
1613
|
return name;
|
|
1603
1614
|
}
|
|
1604
1615
|
|
|
1616
|
+
//#endregion
|
|
1617
|
+
//#region src/schema/interface.ts
|
|
1618
|
+
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1619
|
+
if ((0, graphql.isInterfaceType)(gqlType)) return gqlType;
|
|
1620
|
+
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType.toString()} is not an object`);
|
|
1621
|
+
const key = gqlType;
|
|
1622
|
+
const existing = weaverContext.interfaceMap?.get(key);
|
|
1623
|
+
if (existing != null) return existing;
|
|
1624
|
+
const { astNode: _, extensionASTNodes: _1, fields,...config } = gqlType.toConfig();
|
|
1625
|
+
const interfaceType = new graphql.GraphQLInterfaceType({
|
|
1626
|
+
...config,
|
|
1627
|
+
...interfaceConfig,
|
|
1628
|
+
fields: mapValue(fields, (field$1) => {
|
|
1629
|
+
return {
|
|
1630
|
+
...field$1,
|
|
1631
|
+
type: getCacheType(field$1.type)
|
|
1632
|
+
};
|
|
1633
|
+
})
|
|
1634
|
+
});
|
|
1635
|
+
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
1636
|
+
return interfaceType;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1605
1639
|
//#endregion
|
|
1606
1640
|
//#region src/schema/schema-weaver.ts
|
|
1607
1641
|
function isSchemaVendorWeaver(some) {
|
|
@@ -1629,7 +1663,7 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1629
1663
|
static config(config) {
|
|
1630
1664
|
return {
|
|
1631
1665
|
...config,
|
|
1632
|
-
[
|
|
1666
|
+
[require_parse_resolving_fields.WEAVER_CONFIG]: "gqloom.core.schema"
|
|
1633
1667
|
};
|
|
1634
1668
|
}
|
|
1635
1669
|
constructor({ query: query$1, mutation: mutation$1, subscription: subscription$1, types } = {}, context) {
|
|
@@ -1655,8 +1689,7 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1655
1689
|
}
|
|
1656
1690
|
addType(silk$1) {
|
|
1657
1691
|
let gqlType = provideWeaverContext(() => {
|
|
1658
|
-
|
|
1659
|
-
return getCacheType(gqlType$1);
|
|
1692
|
+
return getCacheType(getGraphQLType(silk$1));
|
|
1660
1693
|
}, this.context);
|
|
1661
1694
|
while ((0, graphql.isNonNullType)(gqlType) || (0, graphql.isListType)(gqlType)) gqlType = gqlType.ofType;
|
|
1662
1695
|
this.types.add(gqlType);
|
|
@@ -1695,7 +1728,7 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1695
1728
|
if (resolverOptions?.extensions && parentObject) parentObject.mergeExtensions(resolverOptions.extensions);
|
|
1696
1729
|
if (modifyParent != null && parentObject) parentObject = modifyParent(parentObject);
|
|
1697
1730
|
Object.entries(resolver$1["~meta"].fields).forEach(([name, field$1]) => {
|
|
1698
|
-
if (field$1 ===
|
|
1731
|
+
if (field$1 === require_parse_resolving_fields.FIELD_HIDDEN) {
|
|
1699
1732
|
if (parentObject == null) return;
|
|
1700
1733
|
parentObject.hideField(name);
|
|
1701
1734
|
} else if (field$1["~meta"].operation === "field") {
|
|
@@ -1745,12 +1778,12 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1745
1778
|
if (item == null) continue;
|
|
1746
1779
|
if (isSchemaVendorWeaver(item)) weavers.add(item);
|
|
1747
1780
|
else if (typeof item === "function") middlewares.add(item);
|
|
1748
|
-
else if (
|
|
1781
|
+
else if (require_parse_resolving_fields.WEAVER_CONFIG in item) {
|
|
1749
1782
|
configs.add(item);
|
|
1750
1783
|
if (item.vendorWeaver) weavers.add(item.vendorWeaver);
|
|
1751
|
-
if (item[
|
|
1784
|
+
if (item[require_parse_resolving_fields.WEAVER_CONFIG] === "gqloom.core.schema") context = item.weaverContext;
|
|
1752
1785
|
} else if (isSilk(item)) silks.add(item);
|
|
1753
|
-
else if (item["~meta"][
|
|
1786
|
+
else if (item["~meta"][require_parse_resolving_fields.IS_RESOLVER]) resolvers.add(item);
|
|
1754
1787
|
}
|
|
1755
1788
|
return {
|
|
1756
1789
|
context,
|
|
@@ -1785,33 +1818,10 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1785
1818
|
const weave = GraphQLSchemaLoom.weave;
|
|
1786
1819
|
|
|
1787
1820
|
//#endregion
|
|
1788
|
-
|
|
1789
|
-
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1790
|
-
if ((0, graphql.isInterfaceType)(gqlType)) return gqlType;
|
|
1791
|
-
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType.toString()} is not an object`);
|
|
1792
|
-
const key = gqlType;
|
|
1793
|
-
const existing = weaverContext.interfaceMap?.get(key);
|
|
1794
|
-
if (existing != null) return existing;
|
|
1795
|
-
const { astNode: _, extensionASTNodes: _1, fields,...config } = gqlType.toConfig();
|
|
1796
|
-
const interfaceType = new graphql.GraphQLInterfaceType({
|
|
1797
|
-
...config,
|
|
1798
|
-
...interfaceConfig,
|
|
1799
|
-
fields: mapValue(fields, (field$1) => {
|
|
1800
|
-
return {
|
|
1801
|
-
...field$1,
|
|
1802
|
-
type: getCacheType(field$1.type)
|
|
1803
|
-
};
|
|
1804
|
-
})
|
|
1805
|
-
});
|
|
1806
|
-
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
1807
|
-
return interfaceType;
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
//#endregion
|
|
1811
|
-
exports.AUTO_ALIASING = require_context.AUTO_ALIASING;
|
|
1821
|
+
exports.AUTO_ALIASING = require_parse_resolving_fields.AUTO_ALIASING;
|
|
1812
1822
|
exports.BaseChainFactory = BaseChainFactory;
|
|
1813
1823
|
exports.ChainResolver = ChainResolver;
|
|
1814
|
-
exports.DERIVED_DEPENDENCIES =
|
|
1824
|
+
exports.DERIVED_DEPENDENCIES = require_parse_resolving_fields.DERIVED_DEPENDENCIES;
|
|
1815
1825
|
exports.EasyDataLoader = EasyDataLoader;
|
|
1816
1826
|
exports.FieldChainFactory = FieldChainFactory;
|
|
1817
1827
|
exports.FieldFactoryWithResolve = FieldFactoryWithResolve;
|
|
@@ -1828,13 +1838,13 @@ exports.QueryFactoryWithResolve = QueryFactoryWithResolve;
|
|
|
1828
1838
|
Object.defineProperty(exports, 'SYMBOLS', {
|
|
1829
1839
|
enumerable: true,
|
|
1830
1840
|
get: function () {
|
|
1831
|
-
return
|
|
1841
|
+
return require_parse_resolving_fields.symbols_exports;
|
|
1832
1842
|
}
|
|
1833
1843
|
});
|
|
1834
1844
|
exports.SubscriptionChainFactory = SubscriptionChainFactory;
|
|
1835
1845
|
exports.WeaverContext = WeaverContext;
|
|
1836
1846
|
exports.applyMiddlewares = applyMiddlewares;
|
|
1837
|
-
exports.assignContextMap =
|
|
1847
|
+
exports.assignContextMap = require_parse_resolving_fields.assignContextMap;
|
|
1838
1848
|
exports.capitalize = capitalize;
|
|
1839
1849
|
exports.collectName = collectName;
|
|
1840
1850
|
exports.collectNames = collectNames;
|
|
@@ -1851,17 +1861,18 @@ exports.ensureInterfaceType = ensureInterfaceType;
|
|
|
1851
1861
|
exports.field = field;
|
|
1852
1862
|
exports.filterMiddlewares = filterMiddlewares;
|
|
1853
1863
|
exports.getCacheType = getCacheType;
|
|
1854
|
-
exports.getDeepResolvingFields =
|
|
1864
|
+
exports.getDeepResolvingFields = require_parse_resolving_fields.getDeepResolvingFields;
|
|
1855
1865
|
exports.getFieldOptions = getFieldOptions;
|
|
1866
|
+
exports.getGraphQLArgumentConfig = getGraphQLArgumentConfig;
|
|
1856
1867
|
exports.getGraphQLType = getGraphQLType;
|
|
1857
|
-
exports.getMemoizationMap =
|
|
1868
|
+
exports.getMemoizationMap = require_parse_resolving_fields.getMemoizationMap;
|
|
1858
1869
|
exports.getOperationOptions = getOperationOptions;
|
|
1859
|
-
exports.getResolvingFields =
|
|
1870
|
+
exports.getResolvingFields = require_parse_resolving_fields.getResolvingFields;
|
|
1860
1871
|
exports.getStandardValue = getStandardValue;
|
|
1861
1872
|
exports.getSubscriptionOptions = getSubscriptionOptions;
|
|
1862
1873
|
exports.initWeaverContext = initWeaverContext;
|
|
1863
1874
|
exports.inputToArgs = inputToArgs;
|
|
1864
|
-
exports.isOnlyMemoryPayload =
|
|
1875
|
+
exports.isOnlyMemoryPayload = require_parse_resolving_fields.isOnlyMemoryPayload;
|
|
1865
1876
|
exports.isSchemaVendorWeaver = isSchemaVendorWeaver;
|
|
1866
1877
|
exports.isSilk = isSilk;
|
|
1867
1878
|
exports.listSilk = listSilk;
|
|
@@ -1874,9 +1885,9 @@ exports.mutation = mutation;
|
|
|
1874
1885
|
exports.nonNullSilk = nonNullSilk;
|
|
1875
1886
|
exports.notNullish = notNullish;
|
|
1876
1887
|
exports.nullableSilk = nullableSilk;
|
|
1877
|
-
exports.onlyMemoization =
|
|
1888
|
+
exports.onlyMemoization = require_parse_resolving_fields.onlyMemoization;
|
|
1878
1889
|
exports.parseInputValue = parseInputValue;
|
|
1879
|
-
exports.parseResolvingFields =
|
|
1890
|
+
exports.parseResolvingFields = require_parse_resolving_fields.parseResolvingFields;
|
|
1880
1891
|
exports.parseSilk = parseSilk;
|
|
1881
1892
|
exports.pascalCase = pascalCase;
|
|
1882
1893
|
exports.provideWeaverContext = provideWeaverContext;
|