@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.js
CHANGED
|
@@ -1,124 +1,369 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as getMemoizationMap, c as FIELD_HIDDEN, d as IS_RESOLVER, f as WEAVER_CONFIG, h as DERIVED_DEPENDENCIES, i as assignContextMap, l as GET_GRAPHQL_ARGUMENT_CONFIG, m as AUTO_ALIASING, n as getResolvingFields, o as isOnlyMemoryPayload, p as symbols_exports, r as parseResolvingFields, s as onlyMemoization, t as getDeepResolvingFields, u as GET_GRAPHQL_TYPE } from "./parse-resolving-fields-BS_BL7I_.js";
|
|
2
2
|
import { GraphQLError, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLUnionType, assertName, isEnumType, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, resolveObjMapThunk } from "graphql";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
//#region src/schema/weaver-context.ts
|
|
5
|
+
var WeaverContext = class WeaverContext {
|
|
6
|
+
static increasingID = 1;
|
|
7
|
+
static names = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
static autoAliasTypes = /* @__PURE__ */ new WeakSet();
|
|
9
|
+
static _ref;
|
|
10
|
+
static get ref() {
|
|
11
|
+
return WeaverContext._ref;
|
|
12
|
+
}
|
|
13
|
+
id;
|
|
14
|
+
loomObjectMap;
|
|
15
|
+
loomUnionMap;
|
|
16
|
+
inputMap;
|
|
17
|
+
interfaceMap;
|
|
18
|
+
configs;
|
|
19
|
+
namedTypes;
|
|
20
|
+
vendorWeavers;
|
|
21
|
+
constructor() {
|
|
22
|
+
this.id = WeaverContext.increasingID++;
|
|
23
|
+
this.loomObjectMap = /* @__PURE__ */ new Map();
|
|
24
|
+
this.loomUnionMap = /* @__PURE__ */ new Map();
|
|
25
|
+
this.inputMap = /* @__PURE__ */ new Map();
|
|
26
|
+
this.interfaceMap = /* @__PURE__ */ new Map();
|
|
27
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
28
|
+
this.namedTypes = /* @__PURE__ */ new Map();
|
|
29
|
+
this.vendorWeavers = /* @__PURE__ */ new Map();
|
|
30
|
+
}
|
|
31
|
+
getConfig(key) {
|
|
32
|
+
return this.configs.get(key);
|
|
33
|
+
}
|
|
34
|
+
setConfig(config) {
|
|
35
|
+
const key = config[WEAVER_CONFIG];
|
|
36
|
+
this.configs.set(key, config);
|
|
37
|
+
}
|
|
38
|
+
deleteConfig(key) {
|
|
39
|
+
this.configs.delete(key);
|
|
40
|
+
}
|
|
41
|
+
memoNamedType(gqlTypeValue) {
|
|
42
|
+
const gqlType = gqlTypeValue;
|
|
43
|
+
if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType) || isScalarType(gqlType)) this.namedTypes.set(gqlType.name, gqlType);
|
|
44
|
+
return gqlTypeValue;
|
|
45
|
+
}
|
|
46
|
+
getNamedType(name) {
|
|
47
|
+
return this.namedTypes.get(name);
|
|
48
|
+
}
|
|
49
|
+
static namedTypes = {
|
|
50
|
+
Object: "Object",
|
|
51
|
+
Union: "Union",
|
|
52
|
+
Enum: "Enum",
|
|
53
|
+
Interface: "Interface",
|
|
54
|
+
Scalar: "Scalar"
|
|
55
|
+
};
|
|
56
|
+
aliasCounters = {};
|
|
57
|
+
setAlias(namedType, alias) {
|
|
58
|
+
if (namedType.name === AUTO_ALIASING) WeaverContext.autoAliasTypes.add(namedType);
|
|
59
|
+
if (!WeaverContext.autoAliasTypes.has(namedType)) return namedType.name;
|
|
60
|
+
if (WeaverContext.higherPriorityThan(alias, namedType.name) < 0) {
|
|
61
|
+
if (alias) return namedType.name = alias;
|
|
62
|
+
}
|
|
63
|
+
if (namedType.name === AUTO_ALIASING) {
|
|
64
|
+
if (isObjectType(namedType) || isInputObjectType(namedType)) {
|
|
65
|
+
this.aliasCounters["Object"] ??= 0;
|
|
66
|
+
return namedType.name = `Object${++this.aliasCounters["Object"]}`;
|
|
67
|
+
} else if (isUnionType(namedType)) {
|
|
68
|
+
this.aliasCounters["Union"] ??= 0;
|
|
69
|
+
return namedType.name = `Union${++this.aliasCounters["Union"]}`;
|
|
70
|
+
} else if (isEnumType(namedType)) {
|
|
71
|
+
this.aliasCounters["Enum"] ??= 0;
|
|
72
|
+
return namedType.name = `Enum${++this.aliasCounters["Enum"]}`;
|
|
73
|
+
} else if (isInterfaceType(namedType)) {
|
|
74
|
+
this.aliasCounters["Interface"] ??= 0;
|
|
75
|
+
return namedType.name = `Interface${++this.aliasCounters["Interface"]}`;
|
|
76
|
+
} else if (isScalarType(namedType)) {
|
|
77
|
+
this.aliasCounters["Scalar"] ??= 0;
|
|
78
|
+
return namedType.name = `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
84
|
+
*/
|
|
85
|
+
static higherPriorityThan(a, b) {
|
|
86
|
+
if (a === AUTO_ALIASING || a === void 0) return 1;
|
|
87
|
+
else if (b === AUTO_ALIASING || b === void 0) return -1;
|
|
88
|
+
const compareLength = a.length - b.length;
|
|
89
|
+
if (compareLength !== 0) return compareLength;
|
|
90
|
+
const compareLocale = a.localeCompare(b);
|
|
91
|
+
if (compareLocale !== 0) return compareLocale;
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
static provide(func, value) {
|
|
95
|
+
const lastRef = WeaverContext._ref;
|
|
96
|
+
WeaverContext._ref = value;
|
|
97
|
+
try {
|
|
98
|
+
return func();
|
|
99
|
+
} finally {
|
|
100
|
+
WeaverContext._ref = lastRef;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const initWeaverContext = () => new WeaverContext();
|
|
105
|
+
const provideWeaverContext = Object.assign(WeaverContext.provide, { inherit: (func) => {
|
|
106
|
+
const weaverContextRef = WeaverContext.ref;
|
|
107
|
+
return () => WeaverContext.provide(func, weaverContextRef);
|
|
108
|
+
} });
|
|
109
|
+
var GlobalWeaverContext = class {
|
|
110
|
+
GraphQLTypes = /* @__PURE__ */ new WeakMap();
|
|
111
|
+
get id() {
|
|
112
|
+
return WeaverContext.ref?.id;
|
|
113
|
+
}
|
|
114
|
+
get loomObjectMap() {
|
|
115
|
+
return WeaverContext.ref?.loomObjectMap;
|
|
116
|
+
}
|
|
117
|
+
get loomUnionMap() {
|
|
118
|
+
return WeaverContext.ref?.loomUnionMap;
|
|
119
|
+
}
|
|
120
|
+
get inputMap() {
|
|
121
|
+
return WeaverContext.ref?.inputMap;
|
|
122
|
+
}
|
|
123
|
+
get interfaceMap() {
|
|
124
|
+
return WeaverContext.ref?.interfaceMap;
|
|
125
|
+
}
|
|
126
|
+
get configs() {
|
|
127
|
+
return WeaverContext.ref?.configs;
|
|
128
|
+
}
|
|
129
|
+
get vendorWeavers() {
|
|
130
|
+
return WeaverContext.ref?.vendorWeavers;
|
|
131
|
+
}
|
|
132
|
+
get names() {
|
|
133
|
+
return WeaverContext.names;
|
|
134
|
+
}
|
|
135
|
+
get autoAliasTypes() {
|
|
136
|
+
return WeaverContext.autoAliasTypes;
|
|
137
|
+
}
|
|
138
|
+
get value() {
|
|
139
|
+
return WeaverContext.ref;
|
|
140
|
+
}
|
|
141
|
+
getConfig(key) {
|
|
142
|
+
return WeaverContext.ref?.getConfig(key);
|
|
143
|
+
}
|
|
144
|
+
setConfig(config) {
|
|
145
|
+
WeaverContext.ref?.setConfig(config);
|
|
146
|
+
}
|
|
147
|
+
deleteConfig(key) {
|
|
148
|
+
WeaverContext.ref?.deleteConfig(key);
|
|
149
|
+
}
|
|
150
|
+
useConfig(config, callback) {
|
|
151
|
+
const context = this.value ?? initWeaverContext();
|
|
152
|
+
context.setConfig(config);
|
|
153
|
+
const result = provideWeaverContext(callback, context);
|
|
154
|
+
context.deleteConfig(config[WEAVER_CONFIG]);
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
getNamedType(name) {
|
|
158
|
+
return WeaverContext.ref?.getNamedType(name);
|
|
159
|
+
}
|
|
160
|
+
memoNamedType(gqlType) {
|
|
161
|
+
return WeaverContext.ref?.memoNamedType(gqlType) ?? gqlType;
|
|
162
|
+
}
|
|
163
|
+
getGraphQLType(origin) {
|
|
164
|
+
return this.GraphQLTypes.get(origin);
|
|
165
|
+
}
|
|
166
|
+
memoGraphQLType(origin, gqlType) {
|
|
167
|
+
this.GraphQLTypes.set(origin, gqlType);
|
|
168
|
+
return gqlType;
|
|
169
|
+
}
|
|
170
|
+
setAlias(namedType, alias) {
|
|
171
|
+
return WeaverContext.ref?.setAlias(namedType, alias);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const weaverContext = new GlobalWeaverContext();
|
|
175
|
+
/**
|
|
176
|
+
* collect names for schemas
|
|
177
|
+
* @param namesList - names to collect
|
|
178
|
+
* @returns namesRecord
|
|
179
|
+
*/
|
|
180
|
+
function collectNames(...namesList) {
|
|
181
|
+
const namesRecord = {};
|
|
182
|
+
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
183
|
+
WeaverContext.names.set(schema, name);
|
|
184
|
+
namesRecord[name] = schema;
|
|
185
|
+
}
|
|
186
|
+
return namesRecord;
|
|
8
187
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
188
|
+
/**
|
|
189
|
+
* collect name for schema
|
|
190
|
+
* @param name - name for
|
|
191
|
+
* @param schema - schema to be named
|
|
192
|
+
* @returns schema
|
|
193
|
+
*/
|
|
194
|
+
function collectName(name, schema) {
|
|
195
|
+
WeaverContext.names.set(schema, name);
|
|
196
|
+
return schema;
|
|
12
197
|
}
|
|
13
|
-
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/resolver/silk.ts
|
|
201
|
+
function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
|
|
14
202
|
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
203
|
+
[GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
204
|
+
"~standard": {
|
|
205
|
+
version: 1,
|
|
206
|
+
vendor: "gqloom.silk",
|
|
207
|
+
validate
|
|
208
|
+
}
|
|
21
209
|
};
|
|
22
210
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
return middleware(callableOptions);
|
|
211
|
+
silk.parse = parseSilk;
|
|
212
|
+
silk.getType = getGraphQLType;
|
|
213
|
+
silk.nonNull = nonNullSilk;
|
|
214
|
+
silk.list = listSilk;
|
|
215
|
+
silk.nullable = nullableSilk;
|
|
216
|
+
/**
|
|
217
|
+
* Non-nullable Silk.
|
|
218
|
+
*/
|
|
219
|
+
function nonNullSilk(origin) {
|
|
220
|
+
return {
|
|
221
|
+
...origin,
|
|
222
|
+
[GET_GRAPHQL_TYPE]: () => {
|
|
223
|
+
const originType = getGraphQLType(origin);
|
|
224
|
+
if (originType instanceof GraphQLNonNull) return originType;
|
|
225
|
+
else return new GraphQLNonNull(originType);
|
|
226
|
+
}
|
|
41
227
|
};
|
|
42
|
-
return next(0);
|
|
43
228
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
229
|
+
/**
|
|
230
|
+
* List Silk.
|
|
231
|
+
*/
|
|
232
|
+
function listSilk(origin) {
|
|
233
|
+
return {
|
|
234
|
+
...origin,
|
|
235
|
+
[GET_GRAPHQL_TYPE]: () => {
|
|
236
|
+
let originType = getGraphQLType(origin);
|
|
237
|
+
if (originType instanceof GraphQLNonNull && originType.ofType instanceof GraphQLList) originType = originType.ofType.ofType;
|
|
238
|
+
if (originType instanceof GraphQLList) originType = originType.ofType;
|
|
239
|
+
return new GraphQLNonNull(new GraphQLList(originType));
|
|
240
|
+
}
|
|
241
|
+
};
|
|
52
242
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Nullable Silk.
|
|
245
|
+
*/
|
|
246
|
+
function nullableSilk(origin) {
|
|
247
|
+
return {
|
|
248
|
+
...origin,
|
|
249
|
+
[GET_GRAPHQL_TYPE]: () => {
|
|
250
|
+
const originType = getGraphQLType(origin);
|
|
251
|
+
if (originType instanceof GraphQLNonNull) return originType.ofType;
|
|
252
|
+
else return originType;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
56
255
|
}
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/utils/object.ts
|
|
60
256
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
257
|
+
* Get GraphQL Output Type from Silk.
|
|
258
|
+
* @param silk GraphQL Silk
|
|
259
|
+
* @returns GraphQL Output Type
|
|
63
260
|
*/
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return result;
|
|
261
|
+
function getGraphQLType(silk$1) {
|
|
262
|
+
if (GET_GRAPHQL_TYPE in silk$1 && silk$1[GET_GRAPHQL_TYPE] != null) return typeof silk$1[GET_GRAPHQL_TYPE] === "function" ? silk$1[GET_GRAPHQL_TYPE]() : silk$1[GET_GRAPHQL_TYPE];
|
|
263
|
+
const vendorWeavers = weaverContext.vendorWeavers;
|
|
264
|
+
if (vendorWeavers == null) throw new Error("Schema Weaver is not initialized");
|
|
265
|
+
const weaver = vendorWeavers.get(silk$1["~standard"].vendor);
|
|
266
|
+
if (weaver == null) throw new Error(`Schema Weaver for ${silk$1["~standard"].vendor} is not found`);
|
|
267
|
+
return weaver.getGraphQLType(silk$1);
|
|
72
268
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Get GraphQL Argument Config from Silk.
|
|
271
|
+
* @param silk GraphQL Silk
|
|
272
|
+
* @returns GraphQL Argument Config
|
|
273
|
+
*/
|
|
274
|
+
function getGraphQLArgumentConfig(silk$1) {
|
|
275
|
+
if (GET_GRAPHQL_ARGUMENT_CONFIG in silk$1 && silk$1[GET_GRAPHQL_ARGUMENT_CONFIG] != null) return typeof silk$1[GET_GRAPHQL_ARGUMENT_CONFIG] === "function" ? silk$1[GET_GRAPHQL_ARGUMENT_CONFIG]() : silk$1[GET_GRAPHQL_ARGUMENT_CONFIG];
|
|
276
|
+
const vendorWeavers = weaverContext.vendorWeavers;
|
|
277
|
+
if (vendorWeavers == null) return void 0;
|
|
278
|
+
const weaver = vendorWeavers.get(silk$1["~standard"]?.vendor);
|
|
279
|
+
if (weaver == null) return void 0;
|
|
280
|
+
if (weaver.getGraphQLArgumentConfig == null) return void 0;
|
|
281
|
+
return weaver.getGraphQLArgumentConfig(silk$1);
|
|
81
282
|
}
|
|
82
|
-
|
|
83
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Validate and transform input to output
|
|
285
|
+
* @param silk silk GraphQL Silk
|
|
286
|
+
* @param input
|
|
287
|
+
* @returns output
|
|
288
|
+
*/
|
|
289
|
+
function parseSilk(silk$1, input) {
|
|
290
|
+
return silk$1["~standard"].validate(input);
|
|
84
291
|
}
|
|
85
|
-
function
|
|
292
|
+
function isSilk(target) {
|
|
293
|
+
if (typeof target !== "object" && typeof target !== "function") return false;
|
|
294
|
+
if (target == null) return false;
|
|
295
|
+
if (GET_GRAPHQL_TYPE in target) return true;
|
|
296
|
+
if (!("~standard" in target)) return false;
|
|
297
|
+
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/resolver/input.ts
|
|
302
|
+
function createInputParser(schema, value) {
|
|
303
|
+
let result;
|
|
304
|
+
const parse = async () => {
|
|
305
|
+
if (result !== void 0) return result;
|
|
306
|
+
result = await parseInputValue(schema, value);
|
|
307
|
+
return result;
|
|
308
|
+
};
|
|
309
|
+
Object.assign(parse, {
|
|
310
|
+
schema,
|
|
311
|
+
value
|
|
312
|
+
});
|
|
313
|
+
Object.defineProperty(parse, "result", {
|
|
314
|
+
get: () => result,
|
|
315
|
+
set: (value$1) => result = value$1
|
|
316
|
+
});
|
|
317
|
+
Object.defineProperty(parse, "getResult", { value: async () => getStandardValue(await parse()) });
|
|
318
|
+
Object.defineProperty(parse, "setResult", { value: (value$1) => result = { value: value$1 } });
|
|
319
|
+
Object.defineProperty(parse, "clearResult", { value: () => result = void 0 });
|
|
320
|
+
return parse;
|
|
321
|
+
}
|
|
322
|
+
function parseInputValue(inputSchema, input) {
|
|
323
|
+
if (inputSchema === void 0) return { value: input };
|
|
324
|
+
if (isSilk(inputSchema)) return inputSchema["~standard"].validate(input);
|
|
325
|
+
return parseInputEntries(inputSchema, input);
|
|
326
|
+
}
|
|
327
|
+
async function parseInputEntries(inputSchema, input = {}) {
|
|
86
328
|
const result = {};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
329
|
+
const issues = [];
|
|
330
|
+
await Promise.all(Object.entries(inputSchema).map(async ([key, value]) => {
|
|
331
|
+
const res = await value["~standard"].validate(input[key]);
|
|
332
|
+
if ("value" in res) result[key] = res.value;
|
|
333
|
+
if (res.issues) issues.push(...res.issues.slice());
|
|
334
|
+
}));
|
|
335
|
+
return {
|
|
336
|
+
value: result,
|
|
337
|
+
...issues.length > 0 ? { issues } : null
|
|
338
|
+
};
|
|
96
339
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* @example
|
|
104
|
-
* const originalData = { key: "value" };
|
|
105
|
-
* const metaData = meta(originalData);
|
|
106
|
-
* console.log(metaData); // Output: { "~meta": { key: "value" } }
|
|
107
|
-
*/
|
|
108
|
-
function meta(data) {
|
|
109
|
-
return { "~meta": data };
|
|
340
|
+
function getStandardValue(result) {
|
|
341
|
+
if (result == null) return result;
|
|
342
|
+
const { issues } = result;
|
|
343
|
+
if (issues?.length) throw new GraphQLError(issues?.[0]?.message ?? "Invalid input", { extensions: { issues } });
|
|
344
|
+
if ("value" in result) return result.value;
|
|
345
|
+
else throw new GraphQLError("Invalid input");
|
|
110
346
|
}
|
|
111
347
|
|
|
112
348
|
//#endregion
|
|
113
|
-
//#region src/utils/
|
|
114
|
-
function
|
|
115
|
-
|
|
349
|
+
//#region src/utils/args.ts
|
|
350
|
+
function getOperationOptions(resolveOrOptions) {
|
|
351
|
+
if (typeof resolveOrOptions === "function") return { resolve: resolveOrOptions };
|
|
352
|
+
return resolveOrOptions;
|
|
116
353
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
354
|
+
function getSubscriptionOptions(subscribeOrOptions) {
|
|
355
|
+
if (typeof subscribeOrOptions === "function") return { subscribe: subscribeOrOptions };
|
|
356
|
+
return subscribeOrOptions;
|
|
119
357
|
}
|
|
120
|
-
function
|
|
121
|
-
return
|
|
358
|
+
function getFieldOptions({ description, deprecationReason, extensions }, extraExtensions) {
|
|
359
|
+
return {
|
|
360
|
+
description,
|
|
361
|
+
deprecationReason,
|
|
362
|
+
extensions: extraExtensions ? {
|
|
363
|
+
...extensions,
|
|
364
|
+
...extraExtensions
|
|
365
|
+
} : extensions
|
|
366
|
+
};
|
|
122
367
|
}
|
|
123
368
|
|
|
124
369
|
//#endregion
|
|
@@ -238,271 +483,102 @@ var EasyDataLoader = class extends LoomDataLoader {
|
|
|
238
483
|
};
|
|
239
484
|
|
|
240
485
|
//#endregion
|
|
241
|
-
//#region src/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
this.configs.set(key, config);
|
|
259
|
-
},
|
|
260
|
-
deleteConfig(key) {
|
|
261
|
-
this.configs.delete(key);
|
|
262
|
-
},
|
|
263
|
-
names,
|
|
264
|
-
autoAliasTypes,
|
|
265
|
-
namedTypes: /* @__PURE__ */ new Map(),
|
|
266
|
-
memoNamedType(gqlTypeValue) {
|
|
267
|
-
const gqlType = gqlTypeValue;
|
|
268
|
-
if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType) || isScalarType(gqlType)) this.namedTypes.set(gqlType.name, gqlType);
|
|
269
|
-
return gqlTypeValue;
|
|
270
|
-
},
|
|
271
|
-
getNamedType(name) {
|
|
272
|
-
return this.namedTypes.get(name);
|
|
273
|
-
},
|
|
274
|
-
vendorWeavers: /* @__PURE__ */ new Map()
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
initWeaverContext.increasingID = 1;
|
|
278
|
-
const weaverContext = {
|
|
279
|
-
get id() {
|
|
280
|
-
return ref?.id;
|
|
281
|
-
},
|
|
282
|
-
get loomObjectMap() {
|
|
283
|
-
return ref?.loomObjectMap;
|
|
284
|
-
},
|
|
285
|
-
get loomUnionMap() {
|
|
286
|
-
return ref?.loomUnionMap;
|
|
287
|
-
},
|
|
288
|
-
get inputMap() {
|
|
289
|
-
return ref?.inputMap;
|
|
290
|
-
},
|
|
291
|
-
get interfaceMap() {
|
|
292
|
-
return ref?.interfaceMap;
|
|
293
|
-
},
|
|
294
|
-
get configs() {
|
|
295
|
-
return ref?.configs;
|
|
296
|
-
},
|
|
297
|
-
get vendorWeavers() {
|
|
298
|
-
return ref?.vendorWeavers;
|
|
299
|
-
},
|
|
300
|
-
getConfig(key) {
|
|
301
|
-
return ref?.getConfig(key);
|
|
302
|
-
},
|
|
303
|
-
setConfig(config) {
|
|
304
|
-
ref?.setConfig(config);
|
|
305
|
-
},
|
|
306
|
-
deleteConfig(key) {
|
|
307
|
-
ref?.deleteConfig(key);
|
|
308
|
-
},
|
|
309
|
-
get value() {
|
|
310
|
-
return ref;
|
|
311
|
-
},
|
|
312
|
-
useConfig(config, callback) {
|
|
313
|
-
const context = weaverContext.value ?? initWeaverContext();
|
|
314
|
-
context.setConfig(config);
|
|
315
|
-
const result = provideWeaverContext(callback, context);
|
|
316
|
-
context.deleteConfig(config[WEAVER_CONFIG]);
|
|
317
|
-
return result;
|
|
318
|
-
},
|
|
319
|
-
names,
|
|
320
|
-
autoAliasTypes,
|
|
321
|
-
getNamedType(name) {
|
|
322
|
-
return ref?.getNamedType(name);
|
|
323
|
-
},
|
|
324
|
-
memoNamedType(gqlType) {
|
|
325
|
-
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
326
|
-
},
|
|
327
|
-
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
328
|
-
getGraphQLType(origin) {
|
|
329
|
-
return this.GraphQLTypes.get(origin);
|
|
330
|
-
},
|
|
331
|
-
memoGraphQLType(origin, gqlType) {
|
|
332
|
-
this.GraphQLTypes.set(origin, gqlType);
|
|
333
|
-
return gqlType;
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
function provideWeaverContext(func, value) {
|
|
337
|
-
const lastRef = ref;
|
|
338
|
-
ref = value;
|
|
339
|
-
try {
|
|
340
|
-
return func();
|
|
341
|
-
} finally {
|
|
342
|
-
ref = lastRef;
|
|
343
|
-
}
|
|
486
|
+
//#region src/utils/middleware.ts
|
|
487
|
+
const defaultOperations = [
|
|
488
|
+
"field",
|
|
489
|
+
"mutation",
|
|
490
|
+
"query",
|
|
491
|
+
"subscription.subscribe"
|
|
492
|
+
];
|
|
493
|
+
function applyMiddlewares(options, resolveFunction, middlewares) {
|
|
494
|
+
const next = (index) => {
|
|
495
|
+
if (index >= middlewares.length) return resolveFunction();
|
|
496
|
+
const middleware = middlewares[index];
|
|
497
|
+
return middleware(Object.assign(() => next(index + 1), {
|
|
498
|
+
...options,
|
|
499
|
+
next: () => next(index + 1)
|
|
500
|
+
}));
|
|
501
|
+
};
|
|
502
|
+
return next(0);
|
|
344
503
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
*/
|
|
354
|
-
function collectNames(...namesList) {
|
|
355
|
-
const namesRecord = {};
|
|
356
|
-
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
357
|
-
names.set(schema, name);
|
|
358
|
-
namesRecord[name] = schema;
|
|
359
|
-
}
|
|
360
|
-
return namesRecord;
|
|
504
|
+
function filterMiddlewares(operation, ...middlewareList) {
|
|
505
|
+
return middlewareList.reduce((acc, m) => {
|
|
506
|
+
if (!m) return acc;
|
|
507
|
+
acc.push(...ensureArray(m).filter((m$1) => {
|
|
508
|
+
return (m$1.operations ?? defaultOperations).includes(operation);
|
|
509
|
+
}));
|
|
510
|
+
return acc;
|
|
511
|
+
}, []);
|
|
361
512
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
* @param schema - schema to be named
|
|
366
|
-
* @returns schema
|
|
367
|
-
*/
|
|
368
|
-
function collectName(name, schema) {
|
|
369
|
-
names.set(schema, name);
|
|
370
|
-
return schema;
|
|
513
|
+
function ensureArray(value) {
|
|
514
|
+
if (value != null && typeof value === "object" && Symbol.iterator in value) return Array.from(value);
|
|
515
|
+
return [value];
|
|
371
516
|
}
|
|
372
517
|
|
|
373
518
|
//#endregion
|
|
374
|
-
//#region src/
|
|
375
|
-
function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
|
|
376
|
-
return {
|
|
377
|
-
[GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
378
|
-
"~standard": {
|
|
379
|
-
version: 1,
|
|
380
|
-
vendor: "gqloom.silk",
|
|
381
|
-
validate
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
silk.parse = parseSilk;
|
|
386
|
-
silk.getType = getGraphQLType;
|
|
387
|
-
silk.nonNull = nonNullSilk;
|
|
388
|
-
silk.list = listSilk;
|
|
389
|
-
silk.nullable = nullableSilk;
|
|
519
|
+
//#region src/utils/object.ts
|
|
390
520
|
/**
|
|
391
|
-
*
|
|
521
|
+
* Creates an object map with the same keys as `map` and values generated by
|
|
522
|
+
* running each value of `record` thru `fn`.
|
|
392
523
|
*/
|
|
393
|
-
function
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
[
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
};
|
|
524
|
+
function mapValue(record, fn) {
|
|
525
|
+
const result = Object.create(null);
|
|
526
|
+
for (const key of Object.keys(record)) {
|
|
527
|
+
const value = fn(record[key], key);
|
|
528
|
+
if (value === SKIP) continue;
|
|
529
|
+
result[key] = value;
|
|
530
|
+
}
|
|
531
|
+
return result;
|
|
402
532
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
return
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (originType instanceof GraphQLNonNull && originType.ofType instanceof GraphQLList) originType = originType.ofType.ofType;
|
|
412
|
-
if (originType instanceof GraphQLList) originType = originType.ofType;
|
|
413
|
-
return new GraphQLNonNull(new GraphQLList(originType));
|
|
414
|
-
}
|
|
415
|
-
};
|
|
533
|
+
const SKIP = Symbol.for("mapValue.skip");
|
|
534
|
+
mapValue.SKIP = SKIP;
|
|
535
|
+
function toObjMap(obj) {
|
|
536
|
+
if (obj == null) return Object.create(null);
|
|
537
|
+
if (Object.getPrototypeOf(obj) === null) return obj;
|
|
538
|
+
const map = Object.create(null);
|
|
539
|
+
for (const [key, value] of Object.entries(obj)) map[key] = value;
|
|
540
|
+
return map;
|
|
416
541
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
*/
|
|
420
|
-
function nullableSilk(origin) {
|
|
421
|
-
return {
|
|
422
|
-
...origin,
|
|
423
|
-
[GET_GRAPHQL_TYPE]: () => {
|
|
424
|
-
const originType = getGraphQLType(origin);
|
|
425
|
-
if (originType instanceof GraphQLNonNull) return originType.ofType;
|
|
426
|
-
else return originType;
|
|
427
|
-
}
|
|
428
|
-
};
|
|
542
|
+
function notNullish(x) {
|
|
543
|
+
return x != null;
|
|
429
544
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
return weaver.getGraphQLType(silk$1);
|
|
545
|
+
function deepMerge(...objects) {
|
|
546
|
+
const result = {};
|
|
547
|
+
for (const obj of objects) {
|
|
548
|
+
if (obj == null) continue;
|
|
549
|
+
for (const [key, value] of Object.entries(obj)) if (value !== null && typeof value === "object") if (Array.isArray(value)) {
|
|
550
|
+
if (!Array.isArray(result[key])) result[key] = [];
|
|
551
|
+
result[key] = [...result[key], ...value];
|
|
552
|
+
} else result[key] = deepMerge(result[key], value);
|
|
553
|
+
else result[key] = value;
|
|
554
|
+
}
|
|
555
|
+
return result;
|
|
442
556
|
}
|
|
443
557
|
/**
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
* @
|
|
447
|
-
* @
|
|
558
|
+
* Wraps the provided data in an object with a single key `"~meta"`.
|
|
559
|
+
*
|
|
560
|
+
* @template T - The type of the data to be wrapped.
|
|
561
|
+
* @param {T} data - The data to be wrapped.
|
|
562
|
+
* @returns {{ "~meta": T }} - An object with a single key `"~meta"` containing the provided data.
|
|
563
|
+
* @example
|
|
564
|
+
* const originalData = { key: "value" };
|
|
565
|
+
* const metaData = meta(originalData);
|
|
566
|
+
* console.log(metaData); // Output: { "~meta": { key: "value" } }
|
|
448
567
|
*/
|
|
449
|
-
function
|
|
450
|
-
return
|
|
451
|
-
}
|
|
452
|
-
function isSilk(target) {
|
|
453
|
-
if (typeof target !== "object" && typeof target !== "function") return false;
|
|
454
|
-
if (target == null) return false;
|
|
455
|
-
if (GET_GRAPHQL_TYPE in target) return true;
|
|
456
|
-
if (!("~standard" in target)) return false;
|
|
457
|
-
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
568
|
+
function meta(data) {
|
|
569
|
+
return { "~meta": data };
|
|
458
570
|
}
|
|
459
571
|
|
|
460
572
|
//#endregion
|
|
461
|
-
//#region src/
|
|
462
|
-
function
|
|
463
|
-
|
|
464
|
-
const parse = async () => {
|
|
465
|
-
if (result !== void 0) return result;
|
|
466
|
-
result = await parseInputValue(schema, value);
|
|
467
|
-
return result;
|
|
468
|
-
};
|
|
469
|
-
Object.assign(parse, {
|
|
470
|
-
schema,
|
|
471
|
-
value
|
|
472
|
-
});
|
|
473
|
-
Object.defineProperty(parse, "result", {
|
|
474
|
-
get: () => result,
|
|
475
|
-
set: (value$1) => result = value$1
|
|
476
|
-
});
|
|
477
|
-
Object.defineProperty(parse, "getResult", { value: async () => getStandardValue(await parse()) });
|
|
478
|
-
Object.defineProperty(parse, "setResult", { value: (value$1) => result = { value: value$1 } });
|
|
479
|
-
Object.defineProperty(parse, "clearResult", { value: () => result = void 0 });
|
|
480
|
-
return parse;
|
|
481
|
-
}
|
|
482
|
-
function parseInputValue(inputSchema, input) {
|
|
483
|
-
if (inputSchema === void 0) return { value: input };
|
|
484
|
-
if (isSilk(inputSchema)) return inputSchema["~standard"].validate(input);
|
|
485
|
-
return parseInputEntries(inputSchema, input);
|
|
573
|
+
//#region src/utils/string.ts
|
|
574
|
+
function pascalCase(str) {
|
|
575
|
+
return str.split(/[\s-_]+/).map((word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
486
576
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const issues = [];
|
|
490
|
-
await Promise.all(Object.entries(inputSchema).map(async ([key, value]) => {
|
|
491
|
-
const res = await value["~standard"].validate(input[key]);
|
|
492
|
-
if ("value" in res) result[key] = res.value;
|
|
493
|
-
if (res.issues) issues.push(...res.issues.slice());
|
|
494
|
-
}));
|
|
495
|
-
return {
|
|
496
|
-
value: result,
|
|
497
|
-
...issues.length > 0 ? { issues } : null
|
|
498
|
-
};
|
|
577
|
+
function capitalize(str) {
|
|
578
|
+
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
499
579
|
}
|
|
500
|
-
function
|
|
501
|
-
|
|
502
|
-
const { issues } = result;
|
|
503
|
-
if (issues?.length) throw new GraphQLError(issues?.[0]?.message ?? "Invalid input", { extensions: { issues } });
|
|
504
|
-
if ("value" in result) return result.value;
|
|
505
|
-
else throw new GraphQLError("Invalid input");
|
|
580
|
+
function screamingSnakeCase(str) {
|
|
581
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").split(/[\s-_]+/).map((word) => word.toUpperCase()).join("_");
|
|
506
582
|
}
|
|
507
583
|
|
|
508
584
|
//#endregion
|
|
@@ -1205,15 +1281,6 @@ var ObjectChainResolver = class extends ChainResolver {
|
|
|
1205
1281
|
}
|
|
1206
1282
|
};
|
|
1207
1283
|
|
|
1208
|
-
//#endregion
|
|
1209
|
-
//#region src/schema/alias.ts
|
|
1210
|
-
function setAlias(namedType, alias, context) {
|
|
1211
|
-
if (namedType.name === AUTO_ALIASING) context.autoAliasTypes.add(namedType);
|
|
1212
|
-
if (!context.autoAliasTypes.has(namedType) || !alias) return;
|
|
1213
|
-
if (namedType.name === AUTO_ALIASING) namedType.name = alias;
|
|
1214
|
-
namedType.name = alias.length < namedType.name.length ? alias : namedType.name;
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
1284
|
//#endregion
|
|
1218
1285
|
//#region src/schema/input.ts
|
|
1219
1286
|
function inputToArgs(input, options) {
|
|
@@ -1222,8 +1289,7 @@ function inputToArgs(input, options) {
|
|
|
1222
1289
|
let inputType = getGraphQLType(input);
|
|
1223
1290
|
if (isNonNullType(inputType)) inputType = inputType.ofType;
|
|
1224
1291
|
if (isObjectType(inputType)) return mapValue(inputType.toConfig().fields, (it, key) => {
|
|
1225
|
-
|
|
1226
|
-
return toInputFieldConfig(it, { fieldName });
|
|
1292
|
+
return toInputFieldConfig(it, { fieldName: `${pascalCase(options.fieldName)}${pascalCase(key)}` });
|
|
1227
1293
|
});
|
|
1228
1294
|
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
1229
1295
|
}
|
|
@@ -1232,7 +1298,7 @@ function inputToArgs(input, options) {
|
|
|
1232
1298
|
tryIn(() => {
|
|
1233
1299
|
const fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
|
|
1234
1300
|
args[name] = {
|
|
1235
|
-
...field$1,
|
|
1301
|
+
...getGraphQLArgumentConfig(field$1),
|
|
1236
1302
|
type: ensureInputType(field$1, { fieldName })
|
|
1237
1303
|
};
|
|
1238
1304
|
}, name);
|
|
@@ -1251,7 +1317,7 @@ function ensureInputType(silkOrType, options) {
|
|
|
1251
1317
|
if (isEnumType(gqlType)) {
|
|
1252
1318
|
if (gqlType.name === AUTO_ALIASING) {
|
|
1253
1319
|
const alias = `${pascalCase(options.fieldName)}Input`;
|
|
1254
|
-
setAlias(gqlType, alias
|
|
1320
|
+
weaverContext.setAlias(gqlType, alias);
|
|
1255
1321
|
}
|
|
1256
1322
|
return gqlType;
|
|
1257
1323
|
}
|
|
@@ -1261,7 +1327,7 @@ function ensureInputObjectType(object, options) {
|
|
|
1261
1327
|
if (isInputObjectType(object)) return object;
|
|
1262
1328
|
const existing = weaverContext.inputMap?.get(object);
|
|
1263
1329
|
if (existing != null) return existing;
|
|
1264
|
-
const { astNode, extensionASTNodes, fields,...config } = object.toConfig();
|
|
1330
|
+
const { astNode: _1, extensionASTNodes: _2, fields,...config } = object.toConfig();
|
|
1265
1331
|
let name = object.name;
|
|
1266
1332
|
if (name === AUTO_ALIASING) name = `${pascalCase(options.fieldName)}Input`;
|
|
1267
1333
|
name = (weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n))(name);
|
|
@@ -1309,10 +1375,10 @@ var LoomObjectType = class extends GraphQLObjectType {
|
|
|
1309
1375
|
this.globalOptions = options.globalOptions;
|
|
1310
1376
|
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
1311
1377
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
1312
|
-
if (this.name === AUTO_ALIASING)
|
|
1378
|
+
if (this.name === AUTO_ALIASING) WeaverContext.autoAliasTypes.add(this);
|
|
1313
1379
|
}
|
|
1314
1380
|
addAlias(alias) {
|
|
1315
|
-
if (!
|
|
1381
|
+
if (!WeaverContext.autoAliasTypes.has(this) || !alias) return;
|
|
1316
1382
|
this.name = alias.length < this.name.length ? alias : this.name;
|
|
1317
1383
|
}
|
|
1318
1384
|
hideField(name) {
|
|
@@ -1327,10 +1393,14 @@ var LoomObjectType = class extends GraphQLObjectType {
|
|
|
1327
1393
|
mergeExtensions(extensions) {
|
|
1328
1394
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
1329
1395
|
}
|
|
1396
|
+
collectedFieldNames() {
|
|
1397
|
+
const fieldsBySuper = super.getFields();
|
|
1398
|
+
Object.entries(fieldsBySuper).forEach(([fieldName, field$1]) => field$1.type = this.getCacheType(field$1.type, fieldName));
|
|
1399
|
+
}
|
|
1330
1400
|
extraFieldMap;
|
|
1331
1401
|
getFields() {
|
|
1332
1402
|
const fieldsBySuper = super.getFields();
|
|
1333
|
-
|
|
1403
|
+
this.collectedFieldNames();
|
|
1334
1404
|
const extraFields = provideWeaverContext(() => defineFieldMap(this.mapToFieldConfig(this.extraFields)), this.weaverContext);
|
|
1335
1405
|
if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) this.extraFieldMap = extraFields;
|
|
1336
1406
|
const answer = {
|
|
@@ -1470,8 +1540,7 @@ function extract(field$1) {
|
|
|
1470
1540
|
};
|
|
1471
1541
|
}
|
|
1472
1542
|
function defineFieldMap(fields) {
|
|
1473
|
-
|
|
1474
|
-
return mapValue(fieldMap, (fieldConfig, fieldName) => {
|
|
1543
|
+
return mapValue(resolveObjMapThunk(fields), (fieldConfig, fieldName) => {
|
|
1475
1544
|
const argsConfig = fieldConfig.args ?? {};
|
|
1476
1545
|
return {
|
|
1477
1546
|
name: assertName(fieldName),
|
|
@@ -1514,7 +1583,7 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1514
1583
|
if (gqlObject != null) return gqlObject;
|
|
1515
1584
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
1516
1585
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1517
|
-
setAlias(loomObject, getAlias()
|
|
1586
|
+
context.setAlias(loomObject, getAlias());
|
|
1518
1587
|
return loomObject;
|
|
1519
1588
|
} else if (isListType(gqlType)) return new GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1520
1589
|
else if (isNonNullType(gqlType)) return new GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
@@ -1526,14 +1595,14 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1526
1595
|
...config,
|
|
1527
1596
|
types: config.types.map((type, i) => getCacheType(type, {
|
|
1528
1597
|
...options,
|
|
1529
|
-
fieldName: options.fieldName ? `${options.fieldName}${i + 1}` : void 0
|
|
1598
|
+
fieldName: options.fieldName ? `${options.fieldName}Item${i + 1}` : void 0
|
|
1530
1599
|
}))
|
|
1531
1600
|
});
|
|
1532
1601
|
context.loomUnionMap?.set(gqlType, unionType);
|
|
1533
|
-
setAlias(unionType, getAlias()
|
|
1602
|
+
context.setAlias(unionType, getAlias());
|
|
1534
1603
|
return unionType;
|
|
1535
|
-
} else if (isEnumType(gqlType)) {
|
|
1536
|
-
setAlias(gqlType, getAlias()
|
|
1604
|
+
} else if (isEnumType(gqlType) || isInterfaceType(gqlType) || isScalarType(gqlType)) {
|
|
1605
|
+
context.setAlias(gqlType, getAlias());
|
|
1537
1606
|
return gqlType;
|
|
1538
1607
|
}
|
|
1539
1608
|
return gqlType;
|
|
@@ -1543,6 +1612,29 @@ function parentName(name) {
|
|
|
1543
1612
|
return name;
|
|
1544
1613
|
}
|
|
1545
1614
|
|
|
1615
|
+
//#endregion
|
|
1616
|
+
//#region src/schema/interface.ts
|
|
1617
|
+
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1618
|
+
if (isInterfaceType(gqlType)) return gqlType;
|
|
1619
|
+
if (!isObjectType(gqlType)) throw new Error(`${gqlType.toString()} is not an object`);
|
|
1620
|
+
const key = gqlType;
|
|
1621
|
+
const existing = weaverContext.interfaceMap?.get(key);
|
|
1622
|
+
if (existing != null) return existing;
|
|
1623
|
+
const { astNode: _, extensionASTNodes: _1, fields,...config } = gqlType.toConfig();
|
|
1624
|
+
const interfaceType = new GraphQLInterfaceType({
|
|
1625
|
+
...config,
|
|
1626
|
+
...interfaceConfig,
|
|
1627
|
+
fields: mapValue(fields, (field$1) => {
|
|
1628
|
+
return {
|
|
1629
|
+
...field$1,
|
|
1630
|
+
type: getCacheType(field$1.type)
|
|
1631
|
+
};
|
|
1632
|
+
})
|
|
1633
|
+
});
|
|
1634
|
+
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
1635
|
+
return interfaceType;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1546
1638
|
//#endregion
|
|
1547
1639
|
//#region src/schema/schema-weaver.ts
|
|
1548
1640
|
function isSchemaVendorWeaver(some) {
|
|
@@ -1595,18 +1687,10 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1595
1687
|
return this;
|
|
1596
1688
|
}
|
|
1597
1689
|
addType(silk$1) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
if (isNonNullType(gqlType$1)) gqlType$1 = gqlType$1.ofType;
|
|
1601
|
-
if (isObjectType(gqlType$1)) {
|
|
1602
|
-
const existing = this.context.loomObjectMap.get(gqlType$1);
|
|
1603
|
-
if (existing != null) return existing;
|
|
1604
|
-
const extraObject = new LoomObjectType(gqlType$1, this.fieldOptions);
|
|
1605
|
-
this.context.loomObjectMap.set(gqlType$1, extraObject);
|
|
1606
|
-
return extraObject;
|
|
1607
|
-
} else if (isUnionType(gqlType$1) || isEnumType(gqlType$1)) return gqlType$1;
|
|
1608
|
-
throw new Error(`${gqlType$1?.name ?? gqlType$1.toString()} is not a named type`);
|
|
1690
|
+
let gqlType = provideWeaverContext(() => {
|
|
1691
|
+
return getCacheType(getGraphQLType(silk$1));
|
|
1609
1692
|
}, this.context);
|
|
1693
|
+
while (isNonNullType(gqlType) || isListType(gqlType)) gqlType = gqlType.ofType;
|
|
1610
1694
|
this.types.add(gqlType);
|
|
1611
1695
|
return this;
|
|
1612
1696
|
}
|
|
@@ -1631,8 +1715,8 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1631
1715
|
let parentObject = (() => {
|
|
1632
1716
|
if (parent == null) return void 0;
|
|
1633
1717
|
let gqlType = getGraphQLType(parent);
|
|
1634
|
-
|
|
1635
|
-
if (!isObjectType(gqlType)) throw new Error(`${gqlType
|
|
1718
|
+
while (isNonNullType(gqlType) || isListType(gqlType)) gqlType = gqlType.ofType;
|
|
1719
|
+
if (!isObjectType(gqlType)) throw new Error(`${gqlType.name} is not an object type`);
|
|
1636
1720
|
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1637
1721
|
if (existing != null) return existing;
|
|
1638
1722
|
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
@@ -1733,27 +1817,4 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1733
1817
|
const weave = GraphQLSchemaLoom.weave;
|
|
1734
1818
|
|
|
1735
1819
|
//#endregion
|
|
1736
|
-
|
|
1737
|
-
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1738
|
-
if (isInterfaceType(gqlType)) return gqlType;
|
|
1739
|
-
if (!isObjectType(gqlType)) throw new Error(`${gqlType.toString()} is not an object`);
|
|
1740
|
-
const key = gqlType;
|
|
1741
|
-
const existing = weaverContext.interfaceMap?.get(key);
|
|
1742
|
-
if (existing != null) return existing;
|
|
1743
|
-
const { astNode: _, extensionASTNodes: _1, fields,...config } = gqlType.toConfig();
|
|
1744
|
-
const interfaceType = new GraphQLInterfaceType({
|
|
1745
|
-
...config,
|
|
1746
|
-
...interfaceConfig,
|
|
1747
|
-
fields: mapValue(fields, (field$1) => {
|
|
1748
|
-
return {
|
|
1749
|
-
...field$1,
|
|
1750
|
-
type: getCacheType(field$1.type)
|
|
1751
|
-
};
|
|
1752
|
-
})
|
|
1753
|
-
});
|
|
1754
|
-
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
1755
|
-
return interfaceType;
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
//#endregion
|
|
1759
|
-
export { AUTO_ALIASING, BaseChainFactory, ChainResolver, DERIVED_DEPENDENCIES, EasyDataLoader, FieldChainFactory, FieldFactoryWithResolve, GraphQLSchemaLoom, LoomDataLoader, LoomObjectType, MutationChainFactory, MutationFactoryWithResolve, OPERATION_OBJECT_NAMES, ObjectChainResolver, QueryChainFactory, QueryFactoryWithResolve, symbols_exports as SYMBOLS, SubscriptionChainFactory, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
|
1820
|
+
export { AUTO_ALIASING, BaseChainFactory, ChainResolver, DERIVED_DEPENDENCIES, EasyDataLoader, FieldChainFactory, FieldFactoryWithResolve, GlobalWeaverContext, GraphQLSchemaLoom, LoomDataLoader, LoomObjectType, MutationChainFactory, MutationFactoryWithResolve, OPERATION_OBJECT_NAMES, ObjectChainResolver, QueryChainFactory, QueryFactoryWithResolve, symbols_exports as SYMBOLS, SubscriptionChainFactory, WeaverContext, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLArgumentConfig, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|