@gqloom/core 0.12.0 → 0.13.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-B1bRSxSg.d.cts → index-DBqGrLn7.d.cts} +362 -316
- package/dist/{index-_VhWbhmU.d.ts → index-DWjUYc0-.d.ts} +363 -316
- package/dist/index.cjs +493 -429
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +467 -406
- package/dist/{context-BxqO4Eg9.js → parse-resolving-fields-BS_BL7I_.js} +67 -62
- package/dist/{context-DshDoxiE.cjs → parse-resolving-fields-BXQG_2Z-.cjs} +71 -60
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,125 +1,370 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_parse_resolving_fields = require('./parse-resolving-fields-BXQG_2Z-.cjs');
|
|
2
2
|
let graphql = require("graphql");
|
|
3
|
-
graphql =
|
|
3
|
+
graphql = require_parse_resolving_fields.__toESM(graphql);
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
//#region src/schema/weaver-context.ts
|
|
6
|
+
var WeaverContext = class WeaverContext {
|
|
7
|
+
static increasingID = 1;
|
|
8
|
+
static names = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
static autoAliasTypes = /* @__PURE__ */ new WeakSet();
|
|
10
|
+
static _ref;
|
|
11
|
+
static get ref() {
|
|
12
|
+
return WeaverContext._ref;
|
|
13
|
+
}
|
|
14
|
+
id;
|
|
15
|
+
loomObjectMap;
|
|
16
|
+
loomUnionMap;
|
|
17
|
+
inputMap;
|
|
18
|
+
interfaceMap;
|
|
19
|
+
configs;
|
|
20
|
+
namedTypes;
|
|
21
|
+
vendorWeavers;
|
|
22
|
+
constructor() {
|
|
23
|
+
this.id = WeaverContext.increasingID++;
|
|
24
|
+
this.loomObjectMap = /* @__PURE__ */ new Map();
|
|
25
|
+
this.loomUnionMap = /* @__PURE__ */ new Map();
|
|
26
|
+
this.inputMap = /* @__PURE__ */ new Map();
|
|
27
|
+
this.interfaceMap = /* @__PURE__ */ new Map();
|
|
28
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
29
|
+
this.namedTypes = /* @__PURE__ */ new Map();
|
|
30
|
+
this.vendorWeavers = /* @__PURE__ */ new Map();
|
|
31
|
+
}
|
|
32
|
+
getConfig(key) {
|
|
33
|
+
return this.configs.get(key);
|
|
34
|
+
}
|
|
35
|
+
setConfig(config) {
|
|
36
|
+
const key = config[require_parse_resolving_fields.WEAVER_CONFIG];
|
|
37
|
+
this.configs.set(key, config);
|
|
38
|
+
}
|
|
39
|
+
deleteConfig(key) {
|
|
40
|
+
this.configs.delete(key);
|
|
41
|
+
}
|
|
42
|
+
memoNamedType(gqlTypeValue) {
|
|
43
|
+
const gqlType = gqlTypeValue;
|
|
44
|
+
if ((0, graphql.isObjectType)(gqlType) || (0, graphql.isUnionType)(gqlType) || (0, graphql.isEnumType)(gqlType) || (0, graphql.isScalarType)(gqlType)) this.namedTypes.set(gqlType.name, gqlType);
|
|
45
|
+
return gqlTypeValue;
|
|
46
|
+
}
|
|
47
|
+
getNamedType(name) {
|
|
48
|
+
return this.namedTypes.get(name);
|
|
49
|
+
}
|
|
50
|
+
static namedTypes = {
|
|
51
|
+
Object: "Object",
|
|
52
|
+
Union: "Union",
|
|
53
|
+
Enum: "Enum",
|
|
54
|
+
Interface: "Interface",
|
|
55
|
+
Scalar: "Scalar"
|
|
56
|
+
};
|
|
57
|
+
aliasCounters = {};
|
|
58
|
+
setAlias(namedType, alias) {
|
|
59
|
+
if (namedType.name === require_parse_resolving_fields.AUTO_ALIASING) WeaverContext.autoAliasTypes.add(namedType);
|
|
60
|
+
if (!WeaverContext.autoAliasTypes.has(namedType)) return namedType.name;
|
|
61
|
+
if (WeaverContext.higherPriorityThan(alias, namedType.name) < 0) {
|
|
62
|
+
if (alias) return namedType.name = alias;
|
|
63
|
+
}
|
|
64
|
+
if (namedType.name === require_parse_resolving_fields.AUTO_ALIASING) {
|
|
65
|
+
if ((0, graphql.isObjectType)(namedType) || (0, graphql.isInputObjectType)(namedType)) {
|
|
66
|
+
this.aliasCounters["Object"] ??= 0;
|
|
67
|
+
return namedType.name = `Object${++this.aliasCounters["Object"]}`;
|
|
68
|
+
} else if ((0, graphql.isUnionType)(namedType)) {
|
|
69
|
+
this.aliasCounters["Union"] ??= 0;
|
|
70
|
+
return namedType.name = `Union${++this.aliasCounters["Union"]}`;
|
|
71
|
+
} else if ((0, graphql.isEnumType)(namedType)) {
|
|
72
|
+
this.aliasCounters["Enum"] ??= 0;
|
|
73
|
+
return namedType.name = `Enum${++this.aliasCounters["Enum"]}`;
|
|
74
|
+
} else if ((0, graphql.isInterfaceType)(namedType)) {
|
|
75
|
+
this.aliasCounters["Interface"] ??= 0;
|
|
76
|
+
return namedType.name = `Interface${++this.aliasCounters["Interface"]}`;
|
|
77
|
+
} else if ((0, graphql.isScalarType)(namedType)) {
|
|
78
|
+
this.aliasCounters["Scalar"] ??= 0;
|
|
79
|
+
return namedType.name = `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
85
|
+
*/
|
|
86
|
+
static higherPriorityThan(a, 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;
|
|
89
|
+
const compareLength = a.length - b.length;
|
|
90
|
+
if (compareLength !== 0) return compareLength;
|
|
91
|
+
const compareLocale = a.localeCompare(b);
|
|
92
|
+
if (compareLocale !== 0) return compareLocale;
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
static provide(func, value) {
|
|
96
|
+
const lastRef = WeaverContext._ref;
|
|
97
|
+
WeaverContext._ref = value;
|
|
98
|
+
try {
|
|
99
|
+
return func();
|
|
100
|
+
} finally {
|
|
101
|
+
WeaverContext._ref = lastRef;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const initWeaverContext = () => new WeaverContext();
|
|
106
|
+
const provideWeaverContext = Object.assign(WeaverContext.provide, { inherit: (func) => {
|
|
107
|
+
const weaverContextRef = WeaverContext.ref;
|
|
108
|
+
return () => WeaverContext.provide(func, weaverContextRef);
|
|
109
|
+
} });
|
|
110
|
+
var GlobalWeaverContext = class {
|
|
111
|
+
GraphQLTypes = /* @__PURE__ */ new WeakMap();
|
|
112
|
+
get id() {
|
|
113
|
+
return WeaverContext.ref?.id;
|
|
114
|
+
}
|
|
115
|
+
get loomObjectMap() {
|
|
116
|
+
return WeaverContext.ref?.loomObjectMap;
|
|
117
|
+
}
|
|
118
|
+
get loomUnionMap() {
|
|
119
|
+
return WeaverContext.ref?.loomUnionMap;
|
|
120
|
+
}
|
|
121
|
+
get inputMap() {
|
|
122
|
+
return WeaverContext.ref?.inputMap;
|
|
123
|
+
}
|
|
124
|
+
get interfaceMap() {
|
|
125
|
+
return WeaverContext.ref?.interfaceMap;
|
|
126
|
+
}
|
|
127
|
+
get configs() {
|
|
128
|
+
return WeaverContext.ref?.configs;
|
|
129
|
+
}
|
|
130
|
+
get vendorWeavers() {
|
|
131
|
+
return WeaverContext.ref?.vendorWeavers;
|
|
132
|
+
}
|
|
133
|
+
get names() {
|
|
134
|
+
return WeaverContext.names;
|
|
135
|
+
}
|
|
136
|
+
get autoAliasTypes() {
|
|
137
|
+
return WeaverContext.autoAliasTypes;
|
|
138
|
+
}
|
|
139
|
+
get value() {
|
|
140
|
+
return WeaverContext.ref;
|
|
141
|
+
}
|
|
142
|
+
getConfig(key) {
|
|
143
|
+
return WeaverContext.ref?.getConfig(key);
|
|
144
|
+
}
|
|
145
|
+
setConfig(config) {
|
|
146
|
+
WeaverContext.ref?.setConfig(config);
|
|
147
|
+
}
|
|
148
|
+
deleteConfig(key) {
|
|
149
|
+
WeaverContext.ref?.deleteConfig(key);
|
|
150
|
+
}
|
|
151
|
+
useConfig(config, callback) {
|
|
152
|
+
const context = this.value ?? initWeaverContext();
|
|
153
|
+
context.setConfig(config);
|
|
154
|
+
const result = provideWeaverContext(callback, context);
|
|
155
|
+
context.deleteConfig(config[require_parse_resolving_fields.WEAVER_CONFIG]);
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
getNamedType(name) {
|
|
159
|
+
return WeaverContext.ref?.getNamedType(name);
|
|
160
|
+
}
|
|
161
|
+
memoNamedType(gqlType) {
|
|
162
|
+
return WeaverContext.ref?.memoNamedType(gqlType) ?? gqlType;
|
|
163
|
+
}
|
|
164
|
+
getGraphQLType(origin) {
|
|
165
|
+
return this.GraphQLTypes.get(origin);
|
|
166
|
+
}
|
|
167
|
+
memoGraphQLType(origin, gqlType) {
|
|
168
|
+
this.GraphQLTypes.set(origin, gqlType);
|
|
169
|
+
return gqlType;
|
|
170
|
+
}
|
|
171
|
+
setAlias(namedType, alias) {
|
|
172
|
+
return WeaverContext.ref?.setAlias(namedType, alias);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const weaverContext = new GlobalWeaverContext();
|
|
176
|
+
/**
|
|
177
|
+
* collect names for schemas
|
|
178
|
+
* @param namesList - names to collect
|
|
179
|
+
* @returns namesRecord
|
|
180
|
+
*/
|
|
181
|
+
function collectNames(...namesList) {
|
|
182
|
+
const namesRecord = {};
|
|
183
|
+
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
184
|
+
WeaverContext.names.set(schema, name);
|
|
185
|
+
namesRecord[name] = schema;
|
|
186
|
+
}
|
|
187
|
+
return namesRecord;
|
|
9
188
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
13
198
|
}
|
|
14
|
-
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/resolver/silk.ts
|
|
202
|
+
function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
|
|
15
203
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
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
|
+
}
|
|
22
210
|
};
|
|
23
211
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
return middleware(callableOptions);
|
|
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
|
+
}
|
|
42
228
|
};
|
|
43
|
-
return next(0);
|
|
44
229
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
};
|
|
53
243
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
};
|
|
57
256
|
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/utils/object.ts
|
|
61
257
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
258
|
+
* Get GraphQL Output Type from Silk.
|
|
259
|
+
* @param silk GraphQL Silk
|
|
260
|
+
* @returns GraphQL Output Type
|
|
64
261
|
*/
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return result;
|
|
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);
|
|
73
269
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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);
|
|
82
283
|
}
|
|
83
|
-
|
|
84
|
-
|
|
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);
|
|
85
292
|
}
|
|
86
|
-
function
|
|
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 = {}) {
|
|
87
329
|
const result = {};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
+
};
|
|
97
340
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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 };
|
|
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");
|
|
111
347
|
}
|
|
112
348
|
|
|
113
349
|
//#endregion
|
|
114
|
-
//#region src/utils/
|
|
115
|
-
function
|
|
116
|
-
|
|
350
|
+
//#region src/utils/args.ts
|
|
351
|
+
function getOperationOptions(resolveOrOptions) {
|
|
352
|
+
if (typeof resolveOrOptions === "function") return { resolve: resolveOrOptions };
|
|
353
|
+
return resolveOrOptions;
|
|
117
354
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
355
|
+
function getSubscriptionOptions(subscribeOrOptions) {
|
|
356
|
+
if (typeof subscribeOrOptions === "function") return { subscribe: subscribeOrOptions };
|
|
357
|
+
return subscribeOrOptions;
|
|
120
358
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
359
|
+
function getFieldOptions({ description, deprecationReason, extensions }, extraExtensions) {
|
|
360
|
+
return {
|
|
361
|
+
description,
|
|
362
|
+
deprecationReason,
|
|
363
|
+
extensions: extraExtensions ? {
|
|
364
|
+
...extensions,
|
|
365
|
+
...extraExtensions
|
|
366
|
+
} : extensions
|
|
367
|
+
};
|
|
123
368
|
}
|
|
124
369
|
|
|
125
370
|
//#endregion
|
|
@@ -239,271 +484,102 @@ var EasyDataLoader = class extends LoomDataLoader {
|
|
|
239
484
|
};
|
|
240
485
|
|
|
241
486
|
//#endregion
|
|
242
|
-
//#region src/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this.configs.set(key, config);
|
|
260
|
-
},
|
|
261
|
-
deleteConfig(key) {
|
|
262
|
-
this.configs.delete(key);
|
|
263
|
-
},
|
|
264
|
-
names,
|
|
265
|
-
autoAliasTypes,
|
|
266
|
-
namedTypes: /* @__PURE__ */ new Map(),
|
|
267
|
-
memoNamedType(gqlTypeValue) {
|
|
268
|
-
const gqlType = gqlTypeValue;
|
|
269
|
-
if ((0, graphql.isObjectType)(gqlType) || (0, graphql.isUnionType)(gqlType) || (0, graphql.isEnumType)(gqlType) || (0, graphql.isScalarType)(gqlType)) this.namedTypes.set(gqlType.name, gqlType);
|
|
270
|
-
return gqlTypeValue;
|
|
271
|
-
},
|
|
272
|
-
getNamedType(name) {
|
|
273
|
-
return this.namedTypes.get(name);
|
|
274
|
-
},
|
|
275
|
-
vendorWeavers: /* @__PURE__ */ new Map()
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
initWeaverContext.increasingID = 1;
|
|
279
|
-
const weaverContext = {
|
|
280
|
-
get id() {
|
|
281
|
-
return ref?.id;
|
|
282
|
-
},
|
|
283
|
-
get loomObjectMap() {
|
|
284
|
-
return ref?.loomObjectMap;
|
|
285
|
-
},
|
|
286
|
-
get loomUnionMap() {
|
|
287
|
-
return ref?.loomUnionMap;
|
|
288
|
-
},
|
|
289
|
-
get inputMap() {
|
|
290
|
-
return ref?.inputMap;
|
|
291
|
-
},
|
|
292
|
-
get interfaceMap() {
|
|
293
|
-
return ref?.interfaceMap;
|
|
294
|
-
},
|
|
295
|
-
get configs() {
|
|
296
|
-
return ref?.configs;
|
|
297
|
-
},
|
|
298
|
-
get vendorWeavers() {
|
|
299
|
-
return ref?.vendorWeavers;
|
|
300
|
-
},
|
|
301
|
-
getConfig(key) {
|
|
302
|
-
return ref?.getConfig(key);
|
|
303
|
-
},
|
|
304
|
-
setConfig(config) {
|
|
305
|
-
ref?.setConfig(config);
|
|
306
|
-
},
|
|
307
|
-
deleteConfig(key) {
|
|
308
|
-
ref?.deleteConfig(key);
|
|
309
|
-
},
|
|
310
|
-
get value() {
|
|
311
|
-
return ref;
|
|
312
|
-
},
|
|
313
|
-
useConfig(config, callback) {
|
|
314
|
-
const context = weaverContext.value ?? initWeaverContext();
|
|
315
|
-
context.setConfig(config);
|
|
316
|
-
const result = provideWeaverContext(callback, context);
|
|
317
|
-
context.deleteConfig(config[require_context.WEAVER_CONFIG]);
|
|
318
|
-
return result;
|
|
319
|
-
},
|
|
320
|
-
names,
|
|
321
|
-
autoAliasTypes,
|
|
322
|
-
getNamedType(name) {
|
|
323
|
-
return ref?.getNamedType(name);
|
|
324
|
-
},
|
|
325
|
-
memoNamedType(gqlType) {
|
|
326
|
-
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
327
|
-
},
|
|
328
|
-
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
329
|
-
getGraphQLType(origin) {
|
|
330
|
-
return this.GraphQLTypes.get(origin);
|
|
331
|
-
},
|
|
332
|
-
memoGraphQLType(origin, gqlType) {
|
|
333
|
-
this.GraphQLTypes.set(origin, gqlType);
|
|
334
|
-
return gqlType;
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
function provideWeaverContext(func, value) {
|
|
338
|
-
const lastRef = ref;
|
|
339
|
-
ref = value;
|
|
340
|
-
try {
|
|
341
|
-
return func();
|
|
342
|
-
} finally {
|
|
343
|
-
ref = lastRef;
|
|
344
|
-
}
|
|
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
|
+
}));
|
|
502
|
+
};
|
|
503
|
+
return next(0);
|
|
345
504
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
*/
|
|
355
|
-
function collectNames(...namesList) {
|
|
356
|
-
const namesRecord = {};
|
|
357
|
-
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
358
|
-
names.set(schema, name);
|
|
359
|
-
namesRecord[name] = schema;
|
|
360
|
-
}
|
|
361
|
-
return namesRecord;
|
|
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
|
+
}, []);
|
|
362
513
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
* @param schema - schema to be named
|
|
367
|
-
* @returns schema
|
|
368
|
-
*/
|
|
369
|
-
function collectName(name, schema) {
|
|
370
|
-
names.set(schema, name);
|
|
371
|
-
return schema;
|
|
514
|
+
function ensureArray(value) {
|
|
515
|
+
if (value != null && typeof value === "object" && Symbol.iterator in value) return Array.from(value);
|
|
516
|
+
return [value];
|
|
372
517
|
}
|
|
373
518
|
|
|
374
519
|
//#endregion
|
|
375
|
-
//#region src/
|
|
376
|
-
function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
|
|
377
|
-
return {
|
|
378
|
-
[require_context.GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
379
|
-
"~standard": {
|
|
380
|
-
version: 1,
|
|
381
|
-
vendor: "gqloom.silk",
|
|
382
|
-
validate
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
silk.parse = parseSilk;
|
|
387
|
-
silk.getType = getGraphQLType;
|
|
388
|
-
silk.nonNull = nonNullSilk;
|
|
389
|
-
silk.list = listSilk;
|
|
390
|
-
silk.nullable = nullableSilk;
|
|
520
|
+
//#region src/utils/object.ts
|
|
391
521
|
/**
|
|
392
|
-
*
|
|
522
|
+
* Creates an object map with the same keys as `map` and values generated by
|
|
523
|
+
* running each value of `record` thru `fn`.
|
|
393
524
|
*/
|
|
394
|
-
function
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
[
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
};
|
|
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;
|
|
403
533
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
return
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (originType instanceof graphql.GraphQLNonNull && originType.ofType instanceof graphql.GraphQLList) originType = originType.ofType.ofType;
|
|
413
|
-
if (originType instanceof graphql.GraphQLList) originType = originType.ofType;
|
|
414
|
-
return new graphql.GraphQLNonNull(new graphql.GraphQLList(originType));
|
|
415
|
-
}
|
|
416
|
-
};
|
|
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;
|
|
417
542
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
*/
|
|
421
|
-
function nullableSilk(origin) {
|
|
422
|
-
return {
|
|
423
|
-
...origin,
|
|
424
|
-
[require_context.GET_GRAPHQL_TYPE]: () => {
|
|
425
|
-
const originType = getGraphQLType(origin);
|
|
426
|
-
if (originType instanceof graphql.GraphQLNonNull) return originType.ofType;
|
|
427
|
-
else return originType;
|
|
428
|
-
}
|
|
429
|
-
};
|
|
543
|
+
function notNullish(x) {
|
|
544
|
+
return x != null;
|
|
430
545
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
return weaver.getGraphQLType(silk$1);
|
|
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;
|
|
443
557
|
}
|
|
444
558
|
/**
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
* @
|
|
448
|
-
* @
|
|
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" } }
|
|
449
568
|
*/
|
|
450
|
-
function
|
|
451
|
-
return
|
|
452
|
-
}
|
|
453
|
-
function isSilk(target) {
|
|
454
|
-
if (typeof target !== "object" && typeof target !== "function") return false;
|
|
455
|
-
if (target == null) return false;
|
|
456
|
-
if (require_context.GET_GRAPHQL_TYPE in target) return true;
|
|
457
|
-
if (!("~standard" in target)) return false;
|
|
458
|
-
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
569
|
+
function meta(data) {
|
|
570
|
+
return { "~meta": data };
|
|
459
571
|
}
|
|
460
572
|
|
|
461
573
|
//#endregion
|
|
462
|
-
//#region src/
|
|
463
|
-
function
|
|
464
|
-
|
|
465
|
-
const parse = async () => {
|
|
466
|
-
if (result !== void 0) return result;
|
|
467
|
-
result = await parseInputValue(schema, value);
|
|
468
|
-
return result;
|
|
469
|
-
};
|
|
470
|
-
Object.assign(parse, {
|
|
471
|
-
schema,
|
|
472
|
-
value
|
|
473
|
-
});
|
|
474
|
-
Object.defineProperty(parse, "result", {
|
|
475
|
-
get: () => result,
|
|
476
|
-
set: (value$1) => result = value$1
|
|
477
|
-
});
|
|
478
|
-
Object.defineProperty(parse, "getResult", { value: async () => getStandardValue(await parse()) });
|
|
479
|
-
Object.defineProperty(parse, "setResult", { value: (value$1) => result = { value: value$1 } });
|
|
480
|
-
Object.defineProperty(parse, "clearResult", { value: () => result = void 0 });
|
|
481
|
-
return parse;
|
|
482
|
-
}
|
|
483
|
-
function parseInputValue(inputSchema, input) {
|
|
484
|
-
if (inputSchema === void 0) return { value: input };
|
|
485
|
-
if (isSilk(inputSchema)) return inputSchema["~standard"].validate(input);
|
|
486
|
-
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("");
|
|
487
577
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
const issues = [];
|
|
491
|
-
await Promise.all(Object.entries(inputSchema).map(async ([key, value]) => {
|
|
492
|
-
const res = await value["~standard"].validate(input[key]);
|
|
493
|
-
if ("value" in res) result[key] = res.value;
|
|
494
|
-
if (res.issues) issues.push(...res.issues.slice());
|
|
495
|
-
}));
|
|
496
|
-
return {
|
|
497
|
-
value: result,
|
|
498
|
-
...issues.length > 0 ? { issues } : null
|
|
499
|
-
};
|
|
578
|
+
function capitalize(str) {
|
|
579
|
+
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
500
580
|
}
|
|
501
|
-
function
|
|
502
|
-
|
|
503
|
-
const { issues } = result;
|
|
504
|
-
if (issues?.length) throw new graphql.GraphQLError(issues?.[0]?.message ?? "Invalid input", { extensions: { issues } });
|
|
505
|
-
if ("value" in result) return result.value;
|
|
506
|
-
else throw new graphql.GraphQLError("Invalid input");
|
|
581
|
+
function screamingSnakeCase(str) {
|
|
582
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").split(/[\s-_]+/).map((word) => word.toUpperCase()).join("_");
|
|
507
583
|
}
|
|
508
584
|
|
|
509
585
|
//#endregion
|
|
@@ -562,7 +638,7 @@ var BaseChainFactory = class BaseChainFactory {
|
|
|
562
638
|
var FieldLoader = class FieldLoader extends LoomDataLoader {
|
|
563
639
|
static getByPath(payload, resolve, getByPath = true) {
|
|
564
640
|
if (!payload) return new FieldLoader(resolve);
|
|
565
|
-
const memoMap =
|
|
641
|
+
const memoMap = require_parse_resolving_fields.getMemoizationMap(payload);
|
|
566
642
|
if (!getByPath) {
|
|
567
643
|
const loader = memoMap.get(resolve) ?? new FieldLoader(resolve);
|
|
568
644
|
memoMap.set(resolve, loader);
|
|
@@ -1043,7 +1119,7 @@ const createField = (output, resolveOrOptions) => {
|
|
|
1043
1119
|
if (resolveOrOptions == null) return new FieldChainFactory({ output });
|
|
1044
1120
|
const options = getOperationOptions(resolveOrOptions);
|
|
1045
1121
|
return meta({
|
|
1046
|
-
...getFieldOptions(options, { [
|
|
1122
|
+
...getFieldOptions(options, { [require_parse_resolving_fields.DERIVED_DEPENDENCIES]: options.dependencies }),
|
|
1047
1123
|
input: options.input,
|
|
1048
1124
|
dependencies: options.dependencies,
|
|
1049
1125
|
output,
|
|
@@ -1055,7 +1131,7 @@ const createField = (output, resolveOrOptions) => {
|
|
|
1055
1131
|
/**
|
|
1056
1132
|
* Factory function for creating GraphQL fields with chainable configuration
|
|
1057
1133
|
*/
|
|
1058
|
-
const field = Object.assign(createField, { hidden:
|
|
1134
|
+
const field = Object.assign(createField, { hidden: require_parse_resolving_fields.FIELD_HIDDEN }, FieldChainFactory.methods());
|
|
1059
1135
|
/**
|
|
1060
1136
|
* Default subscription resolver that returns the source value
|
|
1061
1137
|
* @param source - The source value to resolve
|
|
@@ -1108,7 +1184,7 @@ var ChainResolver = class {
|
|
|
1108
1184
|
*/
|
|
1109
1185
|
constructor(fields, options) {
|
|
1110
1186
|
this.meta = {
|
|
1111
|
-
[
|
|
1187
|
+
[require_parse_resolving_fields.IS_RESOLVER]: true,
|
|
1112
1188
|
fields,
|
|
1113
1189
|
options
|
|
1114
1190
|
};
|
|
@@ -1133,7 +1209,7 @@ var ChainResolver = class {
|
|
|
1133
1209
|
return mapValue(this["~meta"].fields, (field$1) => this.toExecutorOperation(field$1, middlewares) ?? mapValue.SKIP);
|
|
1134
1210
|
}
|
|
1135
1211
|
toExecutorOperation(field$1, executorMiddlewares) {
|
|
1136
|
-
if (field$1 ===
|
|
1212
|
+
if (field$1 === require_parse_resolving_fields.FIELD_HIDDEN || field$1["~meta"].operation === "subscription") return;
|
|
1137
1213
|
const operation = field$1["~meta"].operation;
|
|
1138
1214
|
const middlewares = filterMiddlewares(operation, executorMiddlewares, this.meta.options?.middlewares, field$1["~meta"].middlewares);
|
|
1139
1215
|
if (field$1["~meta"].operation === "field") {
|
|
@@ -1179,7 +1255,7 @@ var ObjectChainResolver = class extends ChainResolver {
|
|
|
1179
1255
|
constructor(parent, fields, options) {
|
|
1180
1256
|
super(fields, options);
|
|
1181
1257
|
this.meta = {
|
|
1182
|
-
[
|
|
1258
|
+
[require_parse_resolving_fields.IS_RESOLVER]: true,
|
|
1183
1259
|
fields,
|
|
1184
1260
|
parent,
|
|
1185
1261
|
options
|
|
@@ -1206,15 +1282,6 @@ var ObjectChainResolver = class extends ChainResolver {
|
|
|
1206
1282
|
}
|
|
1207
1283
|
};
|
|
1208
1284
|
|
|
1209
|
-
//#endregion
|
|
1210
|
-
//#region src/schema/alias.ts
|
|
1211
|
-
function setAlias(namedType, alias, context) {
|
|
1212
|
-
if (namedType.name === require_context.AUTO_ALIASING) context.autoAliasTypes.add(namedType);
|
|
1213
|
-
if (!context.autoAliasTypes.has(namedType) || !alias) return;
|
|
1214
|
-
if (namedType.name === require_context.AUTO_ALIASING) namedType.name = alias;
|
|
1215
|
-
namedType.name = alias.length < namedType.name.length ? alias : namedType.name;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
1285
|
//#endregion
|
|
1219
1286
|
//#region src/schema/input.ts
|
|
1220
1287
|
function inputToArgs(input, options) {
|
|
@@ -1223,8 +1290,7 @@ function inputToArgs(input, options) {
|
|
|
1223
1290
|
let inputType = getGraphQLType(input);
|
|
1224
1291
|
if ((0, graphql.isNonNullType)(inputType)) inputType = inputType.ofType;
|
|
1225
1292
|
if ((0, graphql.isObjectType)(inputType)) return mapValue(inputType.toConfig().fields, (it, key) => {
|
|
1226
|
-
|
|
1227
|
-
return toInputFieldConfig(it, { fieldName });
|
|
1293
|
+
return toInputFieldConfig(it, { fieldName: `${pascalCase(options.fieldName)}${pascalCase(key)}` });
|
|
1228
1294
|
});
|
|
1229
1295
|
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
1230
1296
|
}
|
|
@@ -1233,7 +1299,7 @@ function inputToArgs(input, options) {
|
|
|
1233
1299
|
tryIn(() => {
|
|
1234
1300
|
const fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
|
|
1235
1301
|
args[name] = {
|
|
1236
|
-
...field$1,
|
|
1302
|
+
...getGraphQLArgumentConfig(field$1),
|
|
1237
1303
|
type: ensureInputType(field$1, { fieldName })
|
|
1238
1304
|
};
|
|
1239
1305
|
}, name);
|
|
@@ -1250,9 +1316,9 @@ function ensureInputType(silkOrType, options) {
|
|
|
1250
1316
|
if ((0, graphql.isListType)(gqlType)) return new graphql.GraphQLList(ensureInputType(gqlType.ofType, options));
|
|
1251
1317
|
if ((0, graphql.isObjectType)(gqlType) || (0, graphql.isInterfaceType)(gqlType)) return ensureInputObjectType(gqlType, options);
|
|
1252
1318
|
if ((0, graphql.isEnumType)(gqlType)) {
|
|
1253
|
-
if (gqlType.name ===
|
|
1319
|
+
if (gqlType.name === require_parse_resolving_fields.AUTO_ALIASING) {
|
|
1254
1320
|
const alias = `${pascalCase(options.fieldName)}Input`;
|
|
1255
|
-
setAlias(gqlType, alias
|
|
1321
|
+
weaverContext.setAlias(gqlType, alias);
|
|
1256
1322
|
}
|
|
1257
1323
|
return gqlType;
|
|
1258
1324
|
}
|
|
@@ -1262,9 +1328,9 @@ function ensureInputObjectType(object, options) {
|
|
|
1262
1328
|
if ((0, graphql.isInputObjectType)(object)) return object;
|
|
1263
1329
|
const existing = weaverContext.inputMap?.get(object);
|
|
1264
1330
|
if (existing != null) return existing;
|
|
1265
|
-
const { astNode, extensionASTNodes, fields,...config } = object.toConfig();
|
|
1331
|
+
const { astNode: _1, extensionASTNodes: _2, fields,...config } = object.toConfig();
|
|
1266
1332
|
let name = object.name;
|
|
1267
|
-
if (name ===
|
|
1333
|
+
if (name === require_parse_resolving_fields.AUTO_ALIASING) name = `${pascalCase(options.fieldName)}Input`;
|
|
1268
1334
|
name = (weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n))(name);
|
|
1269
1335
|
const input = new graphql.GraphQLInputObjectType({
|
|
1270
1336
|
...config,
|
|
@@ -1310,10 +1376,10 @@ var LoomObjectType = class extends graphql.GraphQLObjectType {
|
|
|
1310
1376
|
this.globalOptions = options.globalOptions;
|
|
1311
1377
|
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
1312
1378
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
1313
|
-
if (this.name ===
|
|
1379
|
+
if (this.name === require_parse_resolving_fields.AUTO_ALIASING) WeaverContext.autoAliasTypes.add(this);
|
|
1314
1380
|
}
|
|
1315
1381
|
addAlias(alias) {
|
|
1316
|
-
if (!
|
|
1382
|
+
if (!WeaverContext.autoAliasTypes.has(this) || !alias) return;
|
|
1317
1383
|
this.name = alias.length < this.name.length ? alias : this.name;
|
|
1318
1384
|
}
|
|
1319
1385
|
hideField(name) {
|
|
@@ -1328,10 +1394,14 @@ var LoomObjectType = class extends graphql.GraphQLObjectType {
|
|
|
1328
1394
|
mergeExtensions(extensions) {
|
|
1329
1395
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
1330
1396
|
}
|
|
1397
|
+
collectedFieldNames() {
|
|
1398
|
+
const fieldsBySuper = super.getFields();
|
|
1399
|
+
Object.entries(fieldsBySuper).forEach(([fieldName, field$1]) => field$1.type = this.getCacheType(field$1.type, fieldName));
|
|
1400
|
+
}
|
|
1331
1401
|
extraFieldMap;
|
|
1332
1402
|
getFields() {
|
|
1333
1403
|
const fieldsBySuper = super.getFields();
|
|
1334
|
-
|
|
1404
|
+
this.collectedFieldNames();
|
|
1335
1405
|
const extraFields = provideWeaverContext(() => defineFieldMap(this.mapToFieldConfig(this.extraFields)), this.weaverContext);
|
|
1336
1406
|
if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) this.extraFieldMap = extraFields;
|
|
1337
1407
|
const answer = {
|
|
@@ -1471,8 +1541,7 @@ function extract(field$1) {
|
|
|
1471
1541
|
};
|
|
1472
1542
|
}
|
|
1473
1543
|
function defineFieldMap(fields) {
|
|
1474
|
-
|
|
1475
|
-
return mapValue(fieldMap, (fieldConfig, fieldName) => {
|
|
1544
|
+
return mapValue((0, graphql.resolveObjMapThunk)(fields), (fieldConfig, fieldName) => {
|
|
1476
1545
|
const argsConfig = fieldConfig.args ?? {};
|
|
1477
1546
|
return {
|
|
1478
1547
|
name: (0, graphql.assertName)(fieldName),
|
|
@@ -1515,7 +1584,7 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1515
1584
|
if (gqlObject != null) return gqlObject;
|
|
1516
1585
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
1517
1586
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1518
|
-
setAlias(loomObject, getAlias()
|
|
1587
|
+
context.setAlias(loomObject, getAlias());
|
|
1519
1588
|
return loomObject;
|
|
1520
1589
|
} else if ((0, graphql.isListType)(gqlType)) return new graphql.GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1521
1590
|
else if ((0, graphql.isNonNullType)(gqlType)) return new graphql.GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
@@ -1527,14 +1596,14 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1527
1596
|
...config,
|
|
1528
1597
|
types: config.types.map((type, i) => getCacheType(type, {
|
|
1529
1598
|
...options,
|
|
1530
|
-
fieldName: options.fieldName ? `${options.fieldName}${i + 1}` : void 0
|
|
1599
|
+
fieldName: options.fieldName ? `${options.fieldName}Item${i + 1}` : void 0
|
|
1531
1600
|
}))
|
|
1532
1601
|
});
|
|
1533
1602
|
context.loomUnionMap?.set(gqlType, unionType);
|
|
1534
|
-
setAlias(unionType, getAlias()
|
|
1603
|
+
context.setAlias(unionType, getAlias());
|
|
1535
1604
|
return unionType;
|
|
1536
|
-
} else if ((0, graphql.isEnumType)(gqlType)) {
|
|
1537
|
-
setAlias(gqlType, getAlias()
|
|
1605
|
+
} else if ((0, graphql.isEnumType)(gqlType) || (0, graphql.isInterfaceType)(gqlType) || (0, graphql.isScalarType)(gqlType)) {
|
|
1606
|
+
context.setAlias(gqlType, getAlias());
|
|
1538
1607
|
return gqlType;
|
|
1539
1608
|
}
|
|
1540
1609
|
return gqlType;
|
|
@@ -1544,6 +1613,29 @@ function parentName(name) {
|
|
|
1544
1613
|
return name;
|
|
1545
1614
|
}
|
|
1546
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
|
+
|
|
1547
1639
|
//#endregion
|
|
1548
1640
|
//#region src/schema/schema-weaver.ts
|
|
1549
1641
|
function isSchemaVendorWeaver(some) {
|
|
@@ -1571,7 +1663,7 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1571
1663
|
static config(config) {
|
|
1572
1664
|
return {
|
|
1573
1665
|
...config,
|
|
1574
|
-
[
|
|
1666
|
+
[require_parse_resolving_fields.WEAVER_CONFIG]: "gqloom.core.schema"
|
|
1575
1667
|
};
|
|
1576
1668
|
}
|
|
1577
1669
|
constructor({ query: query$1, mutation: mutation$1, subscription: subscription$1, types } = {}, context) {
|
|
@@ -1596,18 +1688,10 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1596
1688
|
return this;
|
|
1597
1689
|
}
|
|
1598
1690
|
addType(silk$1) {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
if ((0, graphql.isNonNullType)(gqlType$1)) gqlType$1 = gqlType$1.ofType;
|
|
1602
|
-
if ((0, graphql.isObjectType)(gqlType$1)) {
|
|
1603
|
-
const existing = this.context.loomObjectMap.get(gqlType$1);
|
|
1604
|
-
if (existing != null) return existing;
|
|
1605
|
-
const extraObject = new LoomObjectType(gqlType$1, this.fieldOptions);
|
|
1606
|
-
this.context.loomObjectMap.set(gqlType$1, extraObject);
|
|
1607
|
-
return extraObject;
|
|
1608
|
-
} else if ((0, graphql.isUnionType)(gqlType$1) || (0, graphql.isEnumType)(gqlType$1)) return gqlType$1;
|
|
1609
|
-
throw new Error(`${gqlType$1?.name ?? gqlType$1.toString()} is not a named type`);
|
|
1691
|
+
let gqlType = provideWeaverContext(() => {
|
|
1692
|
+
return getCacheType(getGraphQLType(silk$1));
|
|
1610
1693
|
}, this.context);
|
|
1694
|
+
while ((0, graphql.isNonNullType)(gqlType) || (0, graphql.isListType)(gqlType)) gqlType = gqlType.ofType;
|
|
1611
1695
|
this.types.add(gqlType);
|
|
1612
1696
|
return this;
|
|
1613
1697
|
}
|
|
@@ -1632,8 +1716,8 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1632
1716
|
let parentObject = (() => {
|
|
1633
1717
|
if (parent == null) return void 0;
|
|
1634
1718
|
let gqlType = getGraphQLType(parent);
|
|
1635
|
-
|
|
1636
|
-
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType
|
|
1719
|
+
while ((0, graphql.isNonNullType)(gqlType) || (0, graphql.isListType)(gqlType)) gqlType = gqlType.ofType;
|
|
1720
|
+
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType.name} is not an object type`);
|
|
1637
1721
|
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1638
1722
|
if (existing != null) return existing;
|
|
1639
1723
|
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
@@ -1644,7 +1728,7 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1644
1728
|
if (resolverOptions?.extensions && parentObject) parentObject.mergeExtensions(resolverOptions.extensions);
|
|
1645
1729
|
if (modifyParent != null && parentObject) parentObject = modifyParent(parentObject);
|
|
1646
1730
|
Object.entries(resolver$1["~meta"].fields).forEach(([name, field$1]) => {
|
|
1647
|
-
if (field$1 ===
|
|
1731
|
+
if (field$1 === require_parse_resolving_fields.FIELD_HIDDEN) {
|
|
1648
1732
|
if (parentObject == null) return;
|
|
1649
1733
|
parentObject.hideField(name);
|
|
1650
1734
|
} else if (field$1["~meta"].operation === "field") {
|
|
@@ -1694,12 +1778,12 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1694
1778
|
if (item == null) continue;
|
|
1695
1779
|
if (isSchemaVendorWeaver(item)) weavers.add(item);
|
|
1696
1780
|
else if (typeof item === "function") middlewares.add(item);
|
|
1697
|
-
else if (
|
|
1781
|
+
else if (require_parse_resolving_fields.WEAVER_CONFIG in item) {
|
|
1698
1782
|
configs.add(item);
|
|
1699
1783
|
if (item.vendorWeaver) weavers.add(item.vendorWeaver);
|
|
1700
|
-
if (item[
|
|
1784
|
+
if (item[require_parse_resolving_fields.WEAVER_CONFIG] === "gqloom.core.schema") context = item.weaverContext;
|
|
1701
1785
|
} else if (isSilk(item)) silks.add(item);
|
|
1702
|
-
else if (item["~meta"][
|
|
1786
|
+
else if (item["~meta"][require_parse_resolving_fields.IS_RESOLVER]) resolvers.add(item);
|
|
1703
1787
|
}
|
|
1704
1788
|
return {
|
|
1705
1789
|
context,
|
|
@@ -1734,36 +1818,14 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1734
1818
|
const weave = GraphQLSchemaLoom.weave;
|
|
1735
1819
|
|
|
1736
1820
|
//#endregion
|
|
1737
|
-
|
|
1738
|
-
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1739
|
-
if ((0, graphql.isInterfaceType)(gqlType)) return gqlType;
|
|
1740
|
-
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType.toString()} is not an object`);
|
|
1741
|
-
const key = gqlType;
|
|
1742
|
-
const existing = weaverContext.interfaceMap?.get(key);
|
|
1743
|
-
if (existing != null) return existing;
|
|
1744
|
-
const { astNode: _, extensionASTNodes: _1, fields,...config } = gqlType.toConfig();
|
|
1745
|
-
const interfaceType = new graphql.GraphQLInterfaceType({
|
|
1746
|
-
...config,
|
|
1747
|
-
...interfaceConfig,
|
|
1748
|
-
fields: mapValue(fields, (field$1) => {
|
|
1749
|
-
return {
|
|
1750
|
-
...field$1,
|
|
1751
|
-
type: getCacheType(field$1.type)
|
|
1752
|
-
};
|
|
1753
|
-
})
|
|
1754
|
-
});
|
|
1755
|
-
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
1756
|
-
return interfaceType;
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
//#endregion
|
|
1760
|
-
exports.AUTO_ALIASING = require_context.AUTO_ALIASING;
|
|
1821
|
+
exports.AUTO_ALIASING = require_parse_resolving_fields.AUTO_ALIASING;
|
|
1761
1822
|
exports.BaseChainFactory = BaseChainFactory;
|
|
1762
1823
|
exports.ChainResolver = ChainResolver;
|
|
1763
|
-
exports.DERIVED_DEPENDENCIES =
|
|
1824
|
+
exports.DERIVED_DEPENDENCIES = require_parse_resolving_fields.DERIVED_DEPENDENCIES;
|
|
1764
1825
|
exports.EasyDataLoader = EasyDataLoader;
|
|
1765
1826
|
exports.FieldChainFactory = FieldChainFactory;
|
|
1766
1827
|
exports.FieldFactoryWithResolve = FieldFactoryWithResolve;
|
|
1828
|
+
exports.GlobalWeaverContext = GlobalWeaverContext;
|
|
1767
1829
|
exports.GraphQLSchemaLoom = GraphQLSchemaLoom;
|
|
1768
1830
|
exports.LoomDataLoader = LoomDataLoader;
|
|
1769
1831
|
exports.LoomObjectType = LoomObjectType;
|
|
@@ -1776,12 +1838,13 @@ exports.QueryFactoryWithResolve = QueryFactoryWithResolve;
|
|
|
1776
1838
|
Object.defineProperty(exports, 'SYMBOLS', {
|
|
1777
1839
|
enumerable: true,
|
|
1778
1840
|
get: function () {
|
|
1779
|
-
return
|
|
1841
|
+
return require_parse_resolving_fields.symbols_exports;
|
|
1780
1842
|
}
|
|
1781
1843
|
});
|
|
1782
1844
|
exports.SubscriptionChainFactory = SubscriptionChainFactory;
|
|
1845
|
+
exports.WeaverContext = WeaverContext;
|
|
1783
1846
|
exports.applyMiddlewares = applyMiddlewares;
|
|
1784
|
-
exports.assignContextMap =
|
|
1847
|
+
exports.assignContextMap = require_parse_resolving_fields.assignContextMap;
|
|
1785
1848
|
exports.capitalize = capitalize;
|
|
1786
1849
|
exports.collectName = collectName;
|
|
1787
1850
|
exports.collectNames = collectNames;
|
|
@@ -1798,17 +1861,18 @@ exports.ensureInterfaceType = ensureInterfaceType;
|
|
|
1798
1861
|
exports.field = field;
|
|
1799
1862
|
exports.filterMiddlewares = filterMiddlewares;
|
|
1800
1863
|
exports.getCacheType = getCacheType;
|
|
1801
|
-
exports.getDeepResolvingFields =
|
|
1864
|
+
exports.getDeepResolvingFields = require_parse_resolving_fields.getDeepResolvingFields;
|
|
1802
1865
|
exports.getFieldOptions = getFieldOptions;
|
|
1866
|
+
exports.getGraphQLArgumentConfig = getGraphQLArgumentConfig;
|
|
1803
1867
|
exports.getGraphQLType = getGraphQLType;
|
|
1804
|
-
exports.getMemoizationMap =
|
|
1868
|
+
exports.getMemoizationMap = require_parse_resolving_fields.getMemoizationMap;
|
|
1805
1869
|
exports.getOperationOptions = getOperationOptions;
|
|
1806
|
-
exports.getResolvingFields =
|
|
1870
|
+
exports.getResolvingFields = require_parse_resolving_fields.getResolvingFields;
|
|
1807
1871
|
exports.getStandardValue = getStandardValue;
|
|
1808
1872
|
exports.getSubscriptionOptions = getSubscriptionOptions;
|
|
1809
1873
|
exports.initWeaverContext = initWeaverContext;
|
|
1810
1874
|
exports.inputToArgs = inputToArgs;
|
|
1811
|
-
exports.isOnlyMemoryPayload =
|
|
1875
|
+
exports.isOnlyMemoryPayload = require_parse_resolving_fields.isOnlyMemoryPayload;
|
|
1812
1876
|
exports.isSchemaVendorWeaver = isSchemaVendorWeaver;
|
|
1813
1877
|
exports.isSilk = isSilk;
|
|
1814
1878
|
exports.listSilk = listSilk;
|
|
@@ -1821,9 +1885,9 @@ exports.mutation = mutation;
|
|
|
1821
1885
|
exports.nonNullSilk = nonNullSilk;
|
|
1822
1886
|
exports.notNullish = notNullish;
|
|
1823
1887
|
exports.nullableSilk = nullableSilk;
|
|
1824
|
-
exports.onlyMemoization =
|
|
1888
|
+
exports.onlyMemoization = require_parse_resolving_fields.onlyMemoization;
|
|
1825
1889
|
exports.parseInputValue = parseInputValue;
|
|
1826
|
-
exports.parseResolvingFields =
|
|
1890
|
+
exports.parseResolvingFields = require_parse_resolving_fields.parseResolvingFields;
|
|
1827
1891
|
exports.parseSilk = parseSilk;
|
|
1828
1892
|
exports.pascalCase = pascalCase;
|
|
1829
1893
|
exports.provideWeaverContext = provideWeaverContext;
|