@gqloom/core 0.3.0 → 0.5.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/README.md +4 -3
- package/dist/index.cjs +330 -271
- package/dist/index.d.cts +178 -76
- package/dist/index.d.ts +178 -76
- package/dist/index.js +299 -242
- package/package.json +7 -6
package/dist/index.cjs
CHANGED
|
@@ -43,20 +43,24 @@ __export(src_exports, {
|
|
|
43
43
|
ensureInputObjectType: () => ensureInputObjectType,
|
|
44
44
|
ensureInputType: () => ensureInputType,
|
|
45
45
|
ensureInterfaceType: () => ensureInterfaceType,
|
|
46
|
+
field: () => field,
|
|
46
47
|
getCacheType: () => getCacheType,
|
|
47
48
|
getFieldOptions: () => getFieldOptions,
|
|
48
49
|
getGraphQLType: () => getGraphQLType,
|
|
49
50
|
getOperationOptions: () => getOperationOptions,
|
|
51
|
+
getStandardValue: () => getStandardValue,
|
|
50
52
|
getSubscriptionOptions: () => getSubscriptionOptions,
|
|
51
53
|
initWeaverContext: () => initWeaverContext,
|
|
52
54
|
inputToArgs: () => inputToArgs,
|
|
53
55
|
isOnlyMemoryPayload: () => isOnlyMemoryPayload,
|
|
56
|
+
isSchemaVendorWeaver: () => isSchemaVendorWeaver,
|
|
54
57
|
isSilk: () => isSilk,
|
|
55
58
|
listSilk: () => listSilk,
|
|
56
59
|
loom: () => loom,
|
|
57
60
|
mapValue: () => mapValue,
|
|
58
61
|
markErrorLocation: () => markErrorLocation,
|
|
59
62
|
markLocation: () => markLocation,
|
|
63
|
+
mutation: () => mutation,
|
|
60
64
|
nonNullSilk: () => nonNullSilk,
|
|
61
65
|
notNullish: () => notNullish,
|
|
62
66
|
nullableSilk: () => nullableSilk,
|
|
@@ -64,13 +68,11 @@ __export(src_exports, {
|
|
|
64
68
|
parseInputValue: () => parseInputValue,
|
|
65
69
|
parseSilk: () => parseSilk,
|
|
66
70
|
provideWeaverContext: () => provideWeaverContext,
|
|
71
|
+
query: () => query,
|
|
72
|
+
resolver: () => resolver,
|
|
67
73
|
resolverPayloadStorage: () => resolverPayloadStorage,
|
|
68
74
|
silk: () => silk,
|
|
69
|
-
|
|
70
|
-
silkMutation: () => silkMutation,
|
|
71
|
-
silkQuery: () => silkQuery,
|
|
72
|
-
silkResolver: () => silkResolver,
|
|
73
|
-
silkSubscription: () => silkSubscription,
|
|
75
|
+
subscription: () => subscription,
|
|
74
76
|
toObjMap: () => toObjMap,
|
|
75
77
|
tryIn: () => tryIn,
|
|
76
78
|
useContext: () => useContext,
|
|
@@ -82,6 +84,9 @@ __export(src_exports, {
|
|
|
82
84
|
module.exports = __toCommonJS(src_exports);
|
|
83
85
|
|
|
84
86
|
// src/resolver/silk.ts
|
|
87
|
+
var import_graphql2 = require("graphql");
|
|
88
|
+
|
|
89
|
+
// src/schema/weaver-context.ts
|
|
85
90
|
var import_graphql = require("graphql");
|
|
86
91
|
|
|
87
92
|
// src/utils/symbols.ts
|
|
@@ -90,22 +95,148 @@ __export(symbols_exports, {
|
|
|
90
95
|
CONTEXT_MEMORY_MAP_KEY: () => CONTEXT_MEMORY_MAP_KEY,
|
|
91
96
|
FIELD_HIDDEN: () => FIELD_HIDDEN,
|
|
92
97
|
GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
|
|
93
|
-
PARSE: () => PARSE,
|
|
94
98
|
RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
|
|
95
99
|
WEAVER_CONFIG: () => WEAVER_CONFIG
|
|
96
100
|
});
|
|
97
101
|
var GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
|
|
98
|
-
var PARSE = Symbol.for("gqloom.parse");
|
|
99
102
|
var WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
|
|
100
103
|
var RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
|
|
101
104
|
var CONTEXT_MEMORY_MAP_KEY = Symbol.for("gqloom.context-memory");
|
|
102
105
|
var FIELD_HIDDEN = Symbol.for("gqloom.field-hidden");
|
|
103
106
|
|
|
107
|
+
// src/schema/weaver-context.ts
|
|
108
|
+
var ref;
|
|
109
|
+
var names = /* @__PURE__ */ new WeakMap();
|
|
110
|
+
function initWeaverContext() {
|
|
111
|
+
return {
|
|
112
|
+
id: initWeaverContext.increasingID++,
|
|
113
|
+
loomObjectMap: /* @__PURE__ */ new Map(),
|
|
114
|
+
loomUnionMap: /* @__PURE__ */ new Map(),
|
|
115
|
+
inputMap: /* @__PURE__ */ new Map(),
|
|
116
|
+
interfaceMap: /* @__PURE__ */ new Map(),
|
|
117
|
+
configs: /* @__PURE__ */ new Map(),
|
|
118
|
+
getConfig(key) {
|
|
119
|
+
return this.configs.get(key);
|
|
120
|
+
},
|
|
121
|
+
setConfig(config) {
|
|
122
|
+
const key = config[WEAVER_CONFIG];
|
|
123
|
+
this.configs.set(key, config);
|
|
124
|
+
},
|
|
125
|
+
deleteConfig(key) {
|
|
126
|
+
this.configs.delete(key);
|
|
127
|
+
},
|
|
128
|
+
names,
|
|
129
|
+
namedTypes: /* @__PURE__ */ new Map(),
|
|
130
|
+
memoNamedType(gqlTypeValue) {
|
|
131
|
+
const gqlType = gqlTypeValue;
|
|
132
|
+
if ((0, import_graphql.isObjectType)(gqlType) || (0, import_graphql.isUnionType)(gqlType) || (0, import_graphql.isEnumType)(gqlType) || (0, import_graphql.isScalarType)(gqlType)) {
|
|
133
|
+
this.namedTypes.set(gqlType.name, gqlType);
|
|
134
|
+
}
|
|
135
|
+
return gqlTypeValue;
|
|
136
|
+
},
|
|
137
|
+
getNamedType(name) {
|
|
138
|
+
return this.namedTypes.get(name);
|
|
139
|
+
},
|
|
140
|
+
vendorWeavers: /* @__PURE__ */ new Map()
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
initWeaverContext.increasingID = 1;
|
|
144
|
+
var weaverContext = {
|
|
145
|
+
get id() {
|
|
146
|
+
return ref?.id;
|
|
147
|
+
},
|
|
148
|
+
get loomObjectMap() {
|
|
149
|
+
return ref?.loomObjectMap;
|
|
150
|
+
},
|
|
151
|
+
get loomUnionMap() {
|
|
152
|
+
return ref?.loomUnionMap;
|
|
153
|
+
},
|
|
154
|
+
get inputMap() {
|
|
155
|
+
return ref?.inputMap;
|
|
156
|
+
},
|
|
157
|
+
get interfaceMap() {
|
|
158
|
+
return ref?.interfaceMap;
|
|
159
|
+
},
|
|
160
|
+
get configs() {
|
|
161
|
+
return ref?.configs;
|
|
162
|
+
},
|
|
163
|
+
get vendorWeavers() {
|
|
164
|
+
return ref?.vendorWeavers;
|
|
165
|
+
},
|
|
166
|
+
getConfig(key) {
|
|
167
|
+
return ref?.getConfig(key);
|
|
168
|
+
},
|
|
169
|
+
setConfig(config) {
|
|
170
|
+
ref?.setConfig(config);
|
|
171
|
+
},
|
|
172
|
+
deleteConfig(key) {
|
|
173
|
+
ref?.deleteConfig(key);
|
|
174
|
+
},
|
|
175
|
+
get value() {
|
|
176
|
+
return ref;
|
|
177
|
+
},
|
|
178
|
+
useConfig(config, callback) {
|
|
179
|
+
const context = weaverContext.value ?? initWeaverContext();
|
|
180
|
+
context.setConfig(config);
|
|
181
|
+
const result = provideWeaverContext(callback, context);
|
|
182
|
+
context.deleteConfig(config[WEAVER_CONFIG]);
|
|
183
|
+
return result;
|
|
184
|
+
},
|
|
185
|
+
names,
|
|
186
|
+
getNamedType(name) {
|
|
187
|
+
return ref?.getNamedType(name);
|
|
188
|
+
},
|
|
189
|
+
memoNamedType(gqlType) {
|
|
190
|
+
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
191
|
+
},
|
|
192
|
+
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
193
|
+
getGraphQLType(origin) {
|
|
194
|
+
return this.GraphQLTypes.get(origin);
|
|
195
|
+
},
|
|
196
|
+
memoGraphQLType(origin, gqlType) {
|
|
197
|
+
this.GraphQLTypes.set(origin, gqlType);
|
|
198
|
+
return gqlType;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
function provideWeaverContext(func, value) {
|
|
202
|
+
const lastRef = ref;
|
|
203
|
+
ref = value;
|
|
204
|
+
try {
|
|
205
|
+
return func();
|
|
206
|
+
} finally {
|
|
207
|
+
ref = lastRef;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
provideWeaverContext.inherit = (func) => {
|
|
211
|
+
const weaverContextRef = weaverContext.value;
|
|
212
|
+
return () => provideWeaverContext(func, weaverContextRef);
|
|
213
|
+
};
|
|
214
|
+
function collectNames(...namesList) {
|
|
215
|
+
const namesRecord = {};
|
|
216
|
+
for (const namesItem of namesList) {
|
|
217
|
+
for (const [name, schema] of Object.entries(namesItem)) {
|
|
218
|
+
names.set(schema, name);
|
|
219
|
+
namesRecord[name] = schema;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return namesRecord;
|
|
223
|
+
}
|
|
224
|
+
function collectName(name, schema) {
|
|
225
|
+
names.set(schema, name);
|
|
226
|
+
return schema;
|
|
227
|
+
}
|
|
228
|
+
|
|
104
229
|
// src/resolver/silk.ts
|
|
105
|
-
function silk(type,
|
|
230
|
+
function silk(type, validate = (value) => ({
|
|
231
|
+
value: value ?? void 0
|
|
232
|
+
})) {
|
|
106
233
|
return {
|
|
107
234
|
[GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
108
|
-
|
|
235
|
+
"~standard": {
|
|
236
|
+
version: 1,
|
|
237
|
+
vendor: "gqloom.silk",
|
|
238
|
+
validate
|
|
239
|
+
}
|
|
109
240
|
};
|
|
110
241
|
}
|
|
111
242
|
silk.parse = parseSilk;
|
|
@@ -115,55 +246,66 @@ silk.list = listSilk;
|
|
|
115
246
|
silk.nullable = nullableSilk;
|
|
116
247
|
function nonNullSilk(origin) {
|
|
117
248
|
return {
|
|
249
|
+
...origin,
|
|
118
250
|
[GET_GRAPHQL_TYPE]: () => {
|
|
119
251
|
const originType = getGraphQLType(origin);
|
|
120
|
-
if (originType instanceof
|
|
252
|
+
if (originType instanceof import_graphql2.GraphQLNonNull) {
|
|
121
253
|
return originType;
|
|
122
254
|
} else {
|
|
123
|
-
return new
|
|
255
|
+
return new import_graphql2.GraphQLNonNull(originType);
|
|
124
256
|
}
|
|
125
|
-
}
|
|
126
|
-
[PARSE]: (input) => origin[PARSE]?.(input)
|
|
257
|
+
}
|
|
127
258
|
};
|
|
128
259
|
}
|
|
129
260
|
function listSilk(origin) {
|
|
130
261
|
return {
|
|
262
|
+
...origin,
|
|
131
263
|
[GET_GRAPHQL_TYPE]: () => {
|
|
132
264
|
let originType = getGraphQLType(origin);
|
|
133
|
-
if (originType instanceof
|
|
265
|
+
if (originType instanceof import_graphql2.GraphQLNonNull && originType.ofType instanceof import_graphql2.GraphQLList) {
|
|
134
266
|
originType = originType.ofType;
|
|
135
267
|
}
|
|
136
|
-
if (originType instanceof
|
|
268
|
+
if (originType instanceof import_graphql2.GraphQLList) {
|
|
137
269
|
originType = originType.ofType;
|
|
138
270
|
}
|
|
139
|
-
return new
|
|
271
|
+
return new import_graphql2.GraphQLNonNull(new import_graphql2.GraphQLList(originType));
|
|
140
272
|
}
|
|
141
273
|
};
|
|
142
274
|
}
|
|
143
275
|
function nullableSilk(origin) {
|
|
144
276
|
return {
|
|
277
|
+
...origin,
|
|
145
278
|
[GET_GRAPHQL_TYPE]: () => {
|
|
146
279
|
const originType = getGraphQLType(origin);
|
|
147
|
-
if (originType instanceof
|
|
280
|
+
if (originType instanceof import_graphql2.GraphQLNonNull) {
|
|
148
281
|
return originType.ofType;
|
|
149
282
|
} else {
|
|
150
283
|
return originType;
|
|
151
284
|
}
|
|
152
|
-
}
|
|
153
|
-
[PARSE]: (input) => origin[PARSE]?.(input)
|
|
285
|
+
}
|
|
154
286
|
};
|
|
155
287
|
}
|
|
156
288
|
function getGraphQLType(silk2) {
|
|
157
|
-
|
|
289
|
+
if (GET_GRAPHQL_TYPE in silk2 && silk2[GET_GRAPHQL_TYPE] != null)
|
|
290
|
+
return silk2[GET_GRAPHQL_TYPE]();
|
|
291
|
+
const vendorWeavers = weaverContext.vendorWeavers;
|
|
292
|
+
if (vendorWeavers == null) throw new Error("Schema Weaver is not initialized");
|
|
293
|
+
const weaver = vendorWeavers.get(silk2["~standard"].vendor);
|
|
294
|
+
if (weaver == null)
|
|
295
|
+
throw new Error(
|
|
296
|
+
`Schema Weaver for ${silk2["~standard"].vendor} is not found`
|
|
297
|
+
);
|
|
298
|
+
return weaver.getGraphQLType(silk2);
|
|
158
299
|
}
|
|
159
300
|
function parseSilk(silk2, input) {
|
|
160
|
-
|
|
161
|
-
return silk2[PARSE](input);
|
|
301
|
+
return silk2["~standard"].validate(input);
|
|
162
302
|
}
|
|
163
303
|
function isSilk(target) {
|
|
164
304
|
if (typeof target !== "object") return false;
|
|
165
305
|
if (target == null) return false;
|
|
166
|
-
|
|
306
|
+
if (GET_GRAPHQL_TYPE in target) return true;
|
|
307
|
+
if (!("~standard" in target)) return false;
|
|
308
|
+
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
167
309
|
}
|
|
168
310
|
|
|
169
311
|
// src/utils/args.ts
|
|
@@ -192,13 +334,17 @@ function getFieldOptions({
|
|
|
192
334
|
}
|
|
193
335
|
|
|
194
336
|
// src/utils/middleware.ts
|
|
195
|
-
function applyMiddlewares(middlewares, resolveFunction,
|
|
337
|
+
function applyMiddlewares(middlewares, resolveFunction, options) {
|
|
196
338
|
const next = (index) => {
|
|
197
339
|
if (index >= middlewares.length) {
|
|
198
340
|
return resolveFunction();
|
|
199
341
|
}
|
|
200
342
|
const middleware = middlewares[index];
|
|
201
|
-
|
|
343
|
+
const callableOptions = Object.assign(() => next(index + 1), {
|
|
344
|
+
...options,
|
|
345
|
+
next: () => next(index + 1)
|
|
346
|
+
});
|
|
347
|
+
return middleware(callableOptions);
|
|
202
348
|
};
|
|
203
349
|
return next(0);
|
|
204
350
|
}
|
|
@@ -380,6 +526,7 @@ function markLocation(message, ...locations) {
|
|
|
380
526
|
}
|
|
381
527
|
|
|
382
528
|
// src/resolver/input.ts
|
|
529
|
+
var import_graphql3 = require("graphql");
|
|
383
530
|
function createInputParser(schema, value) {
|
|
384
531
|
let result;
|
|
385
532
|
const parse = async () => {
|
|
@@ -396,32 +543,43 @@ function createInputParser(schema, value) {
|
|
|
396
543
|
}
|
|
397
544
|
function parseInputValue(inputSchema, input) {
|
|
398
545
|
if (inputSchema === void 0) {
|
|
399
|
-
return input;
|
|
546
|
+
return { value: input };
|
|
400
547
|
}
|
|
401
548
|
if (isSilk(inputSchema)) {
|
|
402
|
-
|
|
403
|
-
return inputSchema[symbols_exports.PARSE](input);
|
|
404
|
-
}
|
|
405
|
-
return input;
|
|
549
|
+
return inputSchema["~standard"].validate(input);
|
|
406
550
|
}
|
|
407
551
|
return parseInputEntries(inputSchema, input);
|
|
408
552
|
}
|
|
409
553
|
async function parseInputEntries(inputSchema, input = {}) {
|
|
410
554
|
const result = {};
|
|
555
|
+
const issues = [];
|
|
411
556
|
await Promise.all(
|
|
412
557
|
Object.entries(inputSchema).map(async ([key, value]) => {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
558
|
+
const res = await value["~standard"].validate(input[key]);
|
|
559
|
+
if ("value" in res) {
|
|
560
|
+
result[key] = res.value;
|
|
561
|
+
}
|
|
562
|
+
if (res.issues) {
|
|
563
|
+
issues.push(...res.issues.slice());
|
|
417
564
|
}
|
|
418
565
|
})
|
|
419
566
|
);
|
|
420
|
-
return result;
|
|
567
|
+
return { value: result, ...issues.length > 0 ? { issues } : null };
|
|
568
|
+
}
|
|
569
|
+
function getStandardValue(result) {
|
|
570
|
+
if (result == null) return result;
|
|
571
|
+
const { issues } = result;
|
|
572
|
+
if (issues?.length) {
|
|
573
|
+
throw new import_graphql3.GraphQLError(issues?.[0]?.message ?? "Invalid input", {
|
|
574
|
+
extensions: { issues }
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
if ("value" in result) return result.value;
|
|
578
|
+
else throw new import_graphql3.GraphQLError("Invalid input");
|
|
421
579
|
}
|
|
422
580
|
|
|
423
581
|
// src/resolver/resolver.ts
|
|
424
|
-
var
|
|
582
|
+
var query = (output, resolveOrOptions) => {
|
|
425
583
|
const options = getOperationOptions(resolveOrOptions);
|
|
426
584
|
const type = "query";
|
|
427
585
|
return {
|
|
@@ -432,14 +590,14 @@ var silkQuery = (output, resolveOrOptions) => {
|
|
|
432
590
|
const parseInput = createInputParser(options.input, inputValue);
|
|
433
591
|
return applyMiddlewares(
|
|
434
592
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
435
|
-
async () => options.resolve(await parseInput()),
|
|
593
|
+
async () => options.resolve(getStandardValue(await parseInput())),
|
|
436
594
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
437
595
|
);
|
|
438
596
|
},
|
|
439
597
|
type
|
|
440
598
|
};
|
|
441
599
|
};
|
|
442
|
-
var
|
|
600
|
+
var mutation = (output, resolveOrOptions) => {
|
|
443
601
|
const options = getOperationOptions(resolveOrOptions);
|
|
444
602
|
const type = "mutation";
|
|
445
603
|
return {
|
|
@@ -450,7 +608,7 @@ var silkMutation = (output, resolveOrOptions) => {
|
|
|
450
608
|
const parseInput = createInputParser(options.input, inputValue);
|
|
451
609
|
return applyMiddlewares(
|
|
452
610
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
453
|
-
async () => options.resolve(await parseInput()),
|
|
611
|
+
async () => options.resolve(getStandardValue(await parseInput())),
|
|
454
612
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
455
613
|
);
|
|
456
614
|
},
|
|
@@ -468,21 +626,21 @@ var baseSilkField = (output, resolveOrOptions) => {
|
|
|
468
626
|
const parseInput = createInputParser(options.input, inputValue);
|
|
469
627
|
return applyMiddlewares(
|
|
470
628
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
471
|
-
async () => options.resolve(parent, await parseInput()),
|
|
629
|
+
async () => options.resolve(parent, getStandardValue(await parseInput())),
|
|
472
630
|
{ parseInput, parent, outputSilk: output, type }
|
|
473
631
|
);
|
|
474
632
|
},
|
|
475
633
|
type
|
|
476
634
|
};
|
|
477
635
|
};
|
|
478
|
-
var
|
|
636
|
+
var field = Object.assign(
|
|
479
637
|
baseSilkField,
|
|
480
638
|
{
|
|
481
639
|
hidden: FIELD_HIDDEN
|
|
482
640
|
}
|
|
483
641
|
);
|
|
484
642
|
var defaultSubscriptionResolve = (source) => source;
|
|
485
|
-
var
|
|
643
|
+
var subscription = (output, subscribeOrOptions) => {
|
|
486
644
|
const options = getSubscriptionOptions(subscribeOrOptions);
|
|
487
645
|
const type = "subscription";
|
|
488
646
|
return {
|
|
@@ -496,7 +654,7 @@ var silkSubscription = (output, subscribeOrOptions) => {
|
|
|
496
654
|
extraOptions?.middlewares,
|
|
497
655
|
options.middlewares
|
|
498
656
|
),
|
|
499
|
-
async () => options.subscribe(await parseInput()),
|
|
657
|
+
async () => options.subscribe(getStandardValue(await parseInput())),
|
|
500
658
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
501
659
|
);
|
|
502
660
|
},
|
|
@@ -543,7 +701,7 @@ function extraOperationOptions(operation, options) {
|
|
|
543
701
|
};
|
|
544
702
|
}
|
|
545
703
|
}
|
|
546
|
-
var
|
|
704
|
+
var resolver = Object.assign(
|
|
547
705
|
baseResolver,
|
|
548
706
|
{
|
|
549
707
|
of: (parent, operations, options) => baseResolver(
|
|
@@ -553,11 +711,11 @@ var silkResolver = Object.assign(
|
|
|
553
711
|
}
|
|
554
712
|
);
|
|
555
713
|
var loom = {
|
|
556
|
-
query
|
|
557
|
-
resolver
|
|
558
|
-
field
|
|
559
|
-
subscription
|
|
560
|
-
mutation
|
|
714
|
+
query,
|
|
715
|
+
resolver,
|
|
716
|
+
field,
|
|
717
|
+
subscription,
|
|
718
|
+
mutation
|
|
561
719
|
};
|
|
562
720
|
|
|
563
721
|
// src/helper/create-loom.ts
|
|
@@ -587,7 +745,7 @@ function createFieldFactory(toSilk, isSchema) {
|
|
|
587
745
|
const options = getOperationOptions(
|
|
588
746
|
resolveOrOptions
|
|
589
747
|
);
|
|
590
|
-
return
|
|
748
|
+
return field(toSilk(output), {
|
|
591
749
|
...options,
|
|
592
750
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
593
751
|
});
|
|
@@ -599,7 +757,7 @@ function createFieldFactory(toSilk, isSchema) {
|
|
|
599
757
|
function createQueryFactory(toSilk, isSchema) {
|
|
600
758
|
return (output, resolveOrOptions) => {
|
|
601
759
|
const options = getOperationOptions(resolveOrOptions);
|
|
602
|
-
return
|
|
760
|
+
return query(toSilk(output), {
|
|
603
761
|
...options,
|
|
604
762
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
605
763
|
});
|
|
@@ -608,7 +766,7 @@ function createQueryFactory(toSilk, isSchema) {
|
|
|
608
766
|
function createMutationFactory(toSilk, isSchema) {
|
|
609
767
|
return (output, resolveOrOptions) => {
|
|
610
768
|
const options = getOperationOptions(resolveOrOptions);
|
|
611
|
-
return
|
|
769
|
+
return mutation(toSilk(output), {
|
|
612
770
|
...options,
|
|
613
771
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
614
772
|
});
|
|
@@ -617,7 +775,7 @@ function createMutationFactory(toSilk, isSchema) {
|
|
|
617
775
|
function createSubscriptionFactory(toSilk, isSchema) {
|
|
618
776
|
return (output, resolveOrOptions) => {
|
|
619
777
|
const options = getSubscriptionOptions(resolveOrOptions);
|
|
620
|
-
return
|
|
778
|
+
return subscription(toSilk(output), {
|
|
621
779
|
...options,
|
|
622
780
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
623
781
|
});
|
|
@@ -634,135 +792,16 @@ function createLoom(toSilk, isSchema) {
|
|
|
634
792
|
}
|
|
635
793
|
|
|
636
794
|
// src/schema/object.ts
|
|
637
|
-
var
|
|
638
|
-
|
|
639
|
-
// src/schema/weaver-context.ts
|
|
640
|
-
var import_graphql2 = require("graphql");
|
|
641
|
-
var ref;
|
|
642
|
-
var names = /* @__PURE__ */ new WeakMap();
|
|
643
|
-
function initWeaverContext() {
|
|
644
|
-
return {
|
|
645
|
-
id: initWeaverContext.increasingID++,
|
|
646
|
-
loomObjectMap: /* @__PURE__ */ new Map(),
|
|
647
|
-
loomUnionMap: /* @__PURE__ */ new Map(),
|
|
648
|
-
inputMap: /* @__PURE__ */ new Map(),
|
|
649
|
-
interfaceMap: /* @__PURE__ */ new Map(),
|
|
650
|
-
configs: /* @__PURE__ */ new Map(),
|
|
651
|
-
getConfig(key) {
|
|
652
|
-
return this.configs.get(key);
|
|
653
|
-
},
|
|
654
|
-
setConfig(config) {
|
|
655
|
-
const key = config[WEAVER_CONFIG];
|
|
656
|
-
this.configs.set(key, config);
|
|
657
|
-
},
|
|
658
|
-
deleteConfig(key) {
|
|
659
|
-
this.configs.delete(key);
|
|
660
|
-
},
|
|
661
|
-
names,
|
|
662
|
-
namedTypes: /* @__PURE__ */ new Map(),
|
|
663
|
-
memoNamedType(gqlTypeValue) {
|
|
664
|
-
const gqlType = gqlTypeValue;
|
|
665
|
-
if ((0, import_graphql2.isObjectType)(gqlType) || (0, import_graphql2.isUnionType)(gqlType) || (0, import_graphql2.isEnumType)(gqlType) || (0, import_graphql2.isScalarType)(gqlType)) {
|
|
666
|
-
this.namedTypes.set(gqlType.name, gqlType);
|
|
667
|
-
}
|
|
668
|
-
return gqlTypeValue;
|
|
669
|
-
},
|
|
670
|
-
getNamedType(name) {
|
|
671
|
-
return this.namedTypes.get(name);
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
initWeaverContext.increasingID = 1;
|
|
676
|
-
var weaverContext = {
|
|
677
|
-
get id() {
|
|
678
|
-
return ref?.id;
|
|
679
|
-
},
|
|
680
|
-
get loomObjectMap() {
|
|
681
|
-
return ref?.loomObjectMap;
|
|
682
|
-
},
|
|
683
|
-
get loomUnionMap() {
|
|
684
|
-
return ref?.loomUnionMap;
|
|
685
|
-
},
|
|
686
|
-
get inputMap() {
|
|
687
|
-
return ref?.inputMap;
|
|
688
|
-
},
|
|
689
|
-
get interfaceMap() {
|
|
690
|
-
return ref?.interfaceMap;
|
|
691
|
-
},
|
|
692
|
-
get configs() {
|
|
693
|
-
return ref?.configs;
|
|
694
|
-
},
|
|
695
|
-
getConfig(key) {
|
|
696
|
-
return ref?.getConfig(key);
|
|
697
|
-
},
|
|
698
|
-
setConfig(config) {
|
|
699
|
-
ref?.setConfig(config);
|
|
700
|
-
},
|
|
701
|
-
deleteConfig(key) {
|
|
702
|
-
ref?.deleteConfig(key);
|
|
703
|
-
},
|
|
704
|
-
get value() {
|
|
705
|
-
return ref;
|
|
706
|
-
},
|
|
707
|
-
useConfig(config, callback) {
|
|
708
|
-
const context = weaverContext.value ?? initWeaverContext();
|
|
709
|
-
context.setConfig(config);
|
|
710
|
-
const result = provideWeaverContext(callback, context);
|
|
711
|
-
context.deleteConfig(config[WEAVER_CONFIG]);
|
|
712
|
-
return result;
|
|
713
|
-
},
|
|
714
|
-
names,
|
|
715
|
-
getNamedType(name) {
|
|
716
|
-
return ref?.getNamedType(name);
|
|
717
|
-
},
|
|
718
|
-
memoNamedType(gqlType) {
|
|
719
|
-
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
720
|
-
},
|
|
721
|
-
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
722
|
-
getGraphQLType(origin) {
|
|
723
|
-
return this.GraphQLTypes.get(origin);
|
|
724
|
-
},
|
|
725
|
-
memoGraphQLType(origin, gqlType) {
|
|
726
|
-
this.GraphQLTypes.set(origin, gqlType);
|
|
727
|
-
return gqlType;
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
function provideWeaverContext(func, value) {
|
|
731
|
-
const lastRef = ref;
|
|
732
|
-
ref = value;
|
|
733
|
-
try {
|
|
734
|
-
return func();
|
|
735
|
-
} finally {
|
|
736
|
-
ref = lastRef;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
provideWeaverContext.inherit = (func) => {
|
|
740
|
-
const weaverContextRef = weaverContext.value;
|
|
741
|
-
return () => provideWeaverContext(func, weaverContextRef);
|
|
742
|
-
};
|
|
743
|
-
function collectNames(...namesList) {
|
|
744
|
-
const namesRecord = {};
|
|
745
|
-
for (const namesItem of namesList) {
|
|
746
|
-
for (const [name, schema] of Object.entries(namesItem)) {
|
|
747
|
-
names.set(schema, name);
|
|
748
|
-
namesRecord[name] = schema;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
return namesRecord;
|
|
752
|
-
}
|
|
753
|
-
function collectName(name, schema) {
|
|
754
|
-
names.set(schema, name);
|
|
755
|
-
return schema;
|
|
756
|
-
}
|
|
795
|
+
var import_graphql5 = require("graphql");
|
|
757
796
|
|
|
758
797
|
// src/schema/input.ts
|
|
759
|
-
var
|
|
798
|
+
var import_graphql4 = require("graphql");
|
|
760
799
|
function inputToArgs(input) {
|
|
761
800
|
if (input === void 0) return void 0;
|
|
762
801
|
if (isSilk(input)) {
|
|
763
802
|
let inputType = getGraphQLType(input);
|
|
764
|
-
if ((0,
|
|
765
|
-
if ((0,
|
|
803
|
+
if ((0, import_graphql4.isNonNullType)(inputType)) inputType = inputType.ofType;
|
|
804
|
+
if ((0, import_graphql4.isObjectType)(inputType)) {
|
|
766
805
|
return mapValue(
|
|
767
806
|
inputType.toConfig().fields,
|
|
768
807
|
(it) => toInputFieldConfig(it)
|
|
@@ -771,11 +810,11 @@ function inputToArgs(input) {
|
|
|
771
810
|
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
772
811
|
}
|
|
773
812
|
const args = {};
|
|
774
|
-
Object.entries(input).forEach(([name,
|
|
813
|
+
Object.entries(input).forEach(([name, field2]) => {
|
|
775
814
|
tryIn(() => {
|
|
776
815
|
args[name] = {
|
|
777
|
-
...
|
|
778
|
-
type: ensureInputType(
|
|
816
|
+
...field2,
|
|
817
|
+
type: ensureInputType(field2)
|
|
779
818
|
};
|
|
780
819
|
}, name);
|
|
781
820
|
});
|
|
@@ -788,20 +827,20 @@ function ensureInputType(silkOrType) {
|
|
|
788
827
|
}
|
|
789
828
|
return silkOrType;
|
|
790
829
|
})();
|
|
791
|
-
if ((0,
|
|
830
|
+
if ((0, import_graphql4.isUnionType)(gqlType))
|
|
792
831
|
throw new Error(`Cannot convert union type ${gqlType.name} to input type`);
|
|
793
|
-
if ((0,
|
|
794
|
-
return new
|
|
832
|
+
if ((0, import_graphql4.isNonNullType)(gqlType)) {
|
|
833
|
+
return new import_graphql4.GraphQLNonNull(ensureInputType(gqlType.ofType));
|
|
795
834
|
}
|
|
796
|
-
if ((0,
|
|
797
|
-
return new
|
|
835
|
+
if ((0, import_graphql4.isListType)(gqlType)) {
|
|
836
|
+
return new import_graphql4.GraphQLList(ensureInputType(gqlType.ofType));
|
|
798
837
|
}
|
|
799
|
-
if ((0,
|
|
838
|
+
if ((0, import_graphql4.isObjectType)(gqlType) || (0, import_graphql4.isInterfaceType)(gqlType))
|
|
800
839
|
return ensureInputObjectType(gqlType);
|
|
801
840
|
return gqlType;
|
|
802
841
|
}
|
|
803
842
|
function ensureInputObjectType(object) {
|
|
804
|
-
if ((0,
|
|
843
|
+
if ((0, import_graphql4.isInputObjectType)(object)) return object;
|
|
805
844
|
const existing = weaverContext.inputMap?.get(object);
|
|
806
845
|
if (existing != null) return existing;
|
|
807
846
|
const {
|
|
@@ -811,7 +850,7 @@ function ensureInputObjectType(object) {
|
|
|
811
850
|
...config
|
|
812
851
|
} = object.toConfig();
|
|
813
852
|
const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((name) => name);
|
|
814
|
-
const input = new
|
|
853
|
+
const input = new import_graphql4.GraphQLInputObjectType({
|
|
815
854
|
...config,
|
|
816
855
|
name: getInputObjectName(object.name),
|
|
817
856
|
fields: provideWeaverContext.inherit(
|
|
@@ -830,7 +869,7 @@ function toInputFieldConfig({
|
|
|
830
869
|
}
|
|
831
870
|
|
|
832
871
|
// src/schema/object.ts
|
|
833
|
-
var LoomObjectType = class extends
|
|
872
|
+
var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
|
|
834
873
|
extraFields = /* @__PURE__ */ new Map();
|
|
835
874
|
hiddenFields = /* @__PURE__ */ new Set();
|
|
836
875
|
weaverContext;
|
|
@@ -838,7 +877,7 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
838
877
|
constructor(objectOrGetter, options = {}) {
|
|
839
878
|
const origin = typeof objectOrGetter === "function" ? objectOrGetter() : objectOrGetter;
|
|
840
879
|
const config = (() => {
|
|
841
|
-
if ((0,
|
|
880
|
+
if ((0, import_graphql5.isObjectType)(origin)) {
|
|
842
881
|
return origin.toConfig();
|
|
843
882
|
} else if (typeof origin === "string") {
|
|
844
883
|
return { name: origin, fields: {} };
|
|
@@ -853,12 +892,12 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
853
892
|
hideField(name) {
|
|
854
893
|
this.hiddenFields.add(name);
|
|
855
894
|
}
|
|
856
|
-
addField(name,
|
|
895
|
+
addField(name, resolver2) {
|
|
857
896
|
const existing = this.extraFields.get(name);
|
|
858
|
-
if (existing && existing !==
|
|
897
|
+
if (existing && existing !== resolver2) {
|
|
859
898
|
throw new Error(`Field ${name} already exists in ${this.name}`);
|
|
860
899
|
}
|
|
861
|
-
this.extraFields.set(name,
|
|
900
|
+
this.extraFields.set(name, resolver2);
|
|
862
901
|
}
|
|
863
902
|
mergeExtensions(extensions) {
|
|
864
903
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
@@ -867,7 +906,7 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
867
906
|
getFields() {
|
|
868
907
|
const fieldsBySuper = super.getFields();
|
|
869
908
|
Object.values(fieldsBySuper).forEach(
|
|
870
|
-
(
|
|
909
|
+
(field2) => field2.type = this.getCacheType(field2.type)
|
|
871
910
|
);
|
|
872
911
|
const extraFields = provideWeaverContext(
|
|
873
912
|
() => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
|
|
@@ -887,47 +926,47 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
887
926
|
}
|
|
888
927
|
mapToFieldConfig(map) {
|
|
889
928
|
const record = {};
|
|
890
|
-
for (const [name,
|
|
891
|
-
record[name] = this.toFieldConfig(
|
|
929
|
+
for (const [name, field2] of map.entries()) {
|
|
930
|
+
record[name] = this.toFieldConfig(field2);
|
|
892
931
|
}
|
|
893
932
|
return record;
|
|
894
933
|
}
|
|
895
|
-
toFieldConfig(
|
|
934
|
+
toFieldConfig(field2) {
|
|
896
935
|
try {
|
|
897
|
-
const outputType = this.getCacheType(getGraphQLType(
|
|
936
|
+
const outputType = this.getCacheType(getGraphQLType(field2.output));
|
|
898
937
|
return {
|
|
899
|
-
...extract(
|
|
938
|
+
...extract(field2),
|
|
900
939
|
type: outputType,
|
|
901
|
-
args: inputToArgs(
|
|
902
|
-
...this.provideForResolve(
|
|
903
|
-
...this.provideForSubscribe(
|
|
940
|
+
args: inputToArgs(field2.input),
|
|
941
|
+
...this.provideForResolve(field2),
|
|
942
|
+
...this.provideForSubscribe(field2)
|
|
904
943
|
};
|
|
905
944
|
} catch (error) {
|
|
906
945
|
throw markErrorLocation(error);
|
|
907
946
|
}
|
|
908
947
|
}
|
|
909
|
-
provideForResolve(
|
|
910
|
-
if (
|
|
911
|
-
if (
|
|
948
|
+
provideForResolve(field2) {
|
|
949
|
+
if (field2?.resolve == null) return;
|
|
950
|
+
if (field2.resolve === defaultSubscriptionResolve)
|
|
912
951
|
return { resolve: defaultSubscriptionResolve };
|
|
913
|
-
const resolve =
|
|
914
|
-
{ root, args, context, info, field },
|
|
915
|
-
() =>
|
|
916
|
-
) :
|
|
917
|
-
{ root, args, context, info, field },
|
|
918
|
-
() =>
|
|
952
|
+
const resolve = field2.type === "field" ? (root, args, context, info) => resolverPayloadStorage.run(
|
|
953
|
+
{ root, args, context, info, field: field2 },
|
|
954
|
+
() => field2.resolve(root, args, this.resolverOptions)
|
|
955
|
+
) : field2.type === "subscription" ? (root, args, context, info) => resolverPayloadStorage.run(
|
|
956
|
+
{ root, args, context, info, field: field2 },
|
|
957
|
+
() => field2.resolve(root, args)
|
|
919
958
|
) : (root, args, context, info) => resolverPayloadStorage.run(
|
|
920
|
-
{ root, args, context, info, field },
|
|
921
|
-
() =>
|
|
959
|
+
{ root, args, context, info, field: field2 },
|
|
960
|
+
() => field2.resolve(args, this.resolverOptions)
|
|
922
961
|
);
|
|
923
962
|
return { resolve };
|
|
924
963
|
}
|
|
925
|
-
provideForSubscribe(
|
|
926
|
-
if (
|
|
964
|
+
provideForSubscribe(field2) {
|
|
965
|
+
if (field2?.subscribe == null) return;
|
|
927
966
|
return {
|
|
928
967
|
subscribe: (root, args, context, info) => resolverPayloadStorage.run(
|
|
929
|
-
{ root, args, context, info, field },
|
|
930
|
-
() =>
|
|
968
|
+
{ root, args, context, info, field: field2 },
|
|
969
|
+
() => field2.subscribe?.(args, this.resolverOptions)
|
|
931
970
|
)
|
|
932
971
|
};
|
|
933
972
|
}
|
|
@@ -951,11 +990,11 @@ function extract({
|
|
|
951
990
|
};
|
|
952
991
|
}
|
|
953
992
|
function defineFieldMap(fields) {
|
|
954
|
-
const fieldMap = (0,
|
|
993
|
+
const fieldMap = (0, import_graphql5.resolveObjMapThunk)(fields);
|
|
955
994
|
return mapValue(fieldMap, (fieldConfig, fieldName) => {
|
|
956
995
|
const argsConfig = fieldConfig.args ?? {};
|
|
957
996
|
return {
|
|
958
|
-
name: (0,
|
|
997
|
+
name: (0, import_graphql5.assertName)(fieldName),
|
|
959
998
|
description: fieldConfig.description,
|
|
960
999
|
type: fieldConfig.type,
|
|
961
1000
|
args: defineArguments(argsConfig),
|
|
@@ -969,7 +1008,7 @@ function defineFieldMap(fields) {
|
|
|
969
1008
|
}
|
|
970
1009
|
function defineArguments(args) {
|
|
971
1010
|
return Object.entries(args).map(([argName, argConfig]) => ({
|
|
972
|
-
name: (0,
|
|
1011
|
+
name: (0, import_graphql5.assertName)(argName),
|
|
973
1012
|
description: argConfig.description,
|
|
974
1013
|
type: argConfig.type,
|
|
975
1014
|
defaultValue: argConfig.defaultValue,
|
|
@@ -981,21 +1020,21 @@ function defineArguments(args) {
|
|
|
981
1020
|
function getCacheType(gqlType, options = {}) {
|
|
982
1021
|
const context = options.weaverContext ?? weaverContext;
|
|
983
1022
|
if (gqlType instanceof LoomObjectType) return gqlType;
|
|
984
|
-
if ((0,
|
|
1023
|
+
if ((0, import_graphql5.isObjectType)(gqlType)) {
|
|
985
1024
|
const gqlObject = context.loomObjectMap?.get(gqlType);
|
|
986
1025
|
if (gqlObject != null) return gqlObject;
|
|
987
1026
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
988
1027
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
989
1028
|
return loomObject;
|
|
990
|
-
} else if ((0,
|
|
991
|
-
return new
|
|
992
|
-
} else if ((0,
|
|
993
|
-
return new
|
|
994
|
-
} else if ((0,
|
|
1029
|
+
} else if ((0, import_graphql5.isListType)(gqlType)) {
|
|
1030
|
+
return new import_graphql5.GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1031
|
+
} else if ((0, import_graphql5.isNonNullType)(gqlType)) {
|
|
1032
|
+
return new import_graphql5.GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
1033
|
+
} else if ((0, import_graphql5.isUnionType)(gqlType)) {
|
|
995
1034
|
const existing = context.loomUnionMap?.get(gqlType);
|
|
996
1035
|
if (existing != null) return existing;
|
|
997
1036
|
const config = gqlType.toConfig();
|
|
998
|
-
const unionType = new
|
|
1037
|
+
const unionType = new import_graphql5.GraphQLUnionType({
|
|
999
1038
|
...config,
|
|
1000
1039
|
types: config.types.map(
|
|
1001
1040
|
(type) => getCacheType(type, options)
|
|
@@ -1007,8 +1046,17 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1007
1046
|
return gqlType;
|
|
1008
1047
|
}
|
|
1009
1048
|
|
|
1049
|
+
// src/schema/schema-vendor-weaver.ts
|
|
1050
|
+
function isSchemaVendorWeaver(some) {
|
|
1051
|
+
if (typeof some !== "object" && typeof some !== "function") return false;
|
|
1052
|
+
if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function")
|
|
1053
|
+
return false;
|
|
1054
|
+
if (!("vendor" in some) || typeof some.vendor !== "string") return false;
|
|
1055
|
+
return true;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1010
1058
|
// src/schema/schema-weaver.ts
|
|
1011
|
-
var
|
|
1059
|
+
var import_graphql6 = require("graphql");
|
|
1012
1060
|
var SchemaWeaver = class _SchemaWeaver {
|
|
1013
1061
|
query;
|
|
1014
1062
|
mutation;
|
|
@@ -1027,11 +1075,11 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1027
1075
|
[WEAVER_CONFIG]: "gqloom.core.schema"
|
|
1028
1076
|
};
|
|
1029
1077
|
}
|
|
1030
|
-
constructor({ query, mutation, subscription, types } = {}, context) {
|
|
1031
|
-
if (
|
|
1032
|
-
if (
|
|
1033
|
-
if (
|
|
1034
|
-
|
|
1078
|
+
constructor({ query: query2, mutation: mutation2, subscription: subscription2, types } = {}, context) {
|
|
1079
|
+
if (query2 != null) this.query = query2;
|
|
1080
|
+
if (mutation2 != null) this.mutation = mutation2;
|
|
1081
|
+
if (subscription2 != null) this.subscription = subscription2;
|
|
1082
|
+
this.types = new Set(types ?? []);
|
|
1035
1083
|
this.context = context ?? initWeaverContext();
|
|
1036
1084
|
}
|
|
1037
1085
|
use(...middlewares) {
|
|
@@ -1040,29 +1088,32 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1040
1088
|
this.resolverOptions.middlewares.push(...middlewares);
|
|
1041
1089
|
return this;
|
|
1042
1090
|
}
|
|
1043
|
-
add(
|
|
1044
|
-
provideWeaverContext(() => this.addResolver(
|
|
1091
|
+
add(resolver2) {
|
|
1092
|
+
provideWeaverContext(() => this.addResolver(resolver2), this.context);
|
|
1093
|
+
return this;
|
|
1094
|
+
}
|
|
1095
|
+
addVendor(weaver) {
|
|
1096
|
+
this.context.vendorWeavers.set(weaver.vendor, weaver);
|
|
1045
1097
|
return this;
|
|
1046
1098
|
}
|
|
1047
1099
|
addType(silk2) {
|
|
1048
1100
|
const gqlType = provideWeaverContext(() => {
|
|
1049
1101
|
let gqlType2 = getGraphQLType(silk2);
|
|
1050
|
-
if ((0,
|
|
1051
|
-
if ((0,
|
|
1102
|
+
if ((0, import_graphql6.isNonNullType)(gqlType2)) gqlType2 = gqlType2.ofType;
|
|
1103
|
+
if ((0, import_graphql6.isObjectType)(gqlType2)) {
|
|
1052
1104
|
const existing = this.context.loomObjectMap.get(gqlType2);
|
|
1053
1105
|
if (existing != null) return existing;
|
|
1054
1106
|
const extraObject = new LoomObjectType(gqlType2, this.fieldOptions);
|
|
1055
1107
|
this.context.loomObjectMap.set(gqlType2, extraObject);
|
|
1056
1108
|
return extraObject;
|
|
1057
|
-
} else if ((0,
|
|
1109
|
+
} else if ((0, import_graphql6.isUnionType)(gqlType2) || (0, import_graphql6.isEnumType)(gqlType2)) {
|
|
1058
1110
|
return gqlType2;
|
|
1059
1111
|
}
|
|
1060
1112
|
throw new Error(
|
|
1061
1113
|
`${gqlType2?.name ?? gqlType2.toString()} is not a named type`
|
|
1062
1114
|
);
|
|
1063
1115
|
}, this.context);
|
|
1064
|
-
this.types
|
|
1065
|
-
this.types.push(gqlType);
|
|
1116
|
+
this.types.add(gqlType);
|
|
1066
1117
|
return this;
|
|
1067
1118
|
}
|
|
1068
1119
|
setConfig(config) {
|
|
@@ -1070,38 +1121,39 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1070
1121
|
return this;
|
|
1071
1122
|
}
|
|
1072
1123
|
weaveGraphQLSchema() {
|
|
1073
|
-
const { query, mutation, subscription, types } = this;
|
|
1124
|
+
const { query: query2, mutation: mutation2, subscription: subscription2, types } = this;
|
|
1074
1125
|
const config = this.context.getConfig("gqloom.core.schema");
|
|
1075
|
-
const schema = new
|
|
1076
|
-
query,
|
|
1077
|
-
mutation,
|
|
1078
|
-
subscription,
|
|
1126
|
+
const schema = new import_graphql6.GraphQLSchema({
|
|
1127
|
+
query: query2,
|
|
1128
|
+
mutation: mutation2,
|
|
1129
|
+
subscription: subscription2,
|
|
1079
1130
|
types: [...types ?? [], ...config?.types ?? []],
|
|
1080
1131
|
...config
|
|
1081
1132
|
});
|
|
1082
1133
|
return schema;
|
|
1083
1134
|
}
|
|
1084
|
-
addResolver(
|
|
1085
|
-
const resolverOptions = ResolverOptionsMap.get(
|
|
1135
|
+
addResolver(resolver2) {
|
|
1136
|
+
const resolverOptions = ResolverOptionsMap.get(resolver2);
|
|
1086
1137
|
const parent = resolverOptions?.parent;
|
|
1087
1138
|
const parentObject = (() => {
|
|
1088
1139
|
if (parent == null) return void 0;
|
|
1089
1140
|
let gqlType = getGraphQLType(parent);
|
|
1090
|
-
if ((0,
|
|
1091
|
-
if ((0,
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
this.context.loomObjectMap.set(gqlType, extraObject);
|
|
1096
|
-
return extraObject;
|
|
1141
|
+
if ((0, import_graphql6.isNonNullType)(gqlType)) gqlType = gqlType.ofType;
|
|
1142
|
+
if (!(0, import_graphql6.isObjectType)(gqlType)) {
|
|
1143
|
+
throw new Error(
|
|
1144
|
+
`${gqlType?.name ?? gqlType.toString()} is not an object type`
|
|
1145
|
+
);
|
|
1097
1146
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
);
|
|
1147
|
+
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1148
|
+
if (existing != null) return existing;
|
|
1149
|
+
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
1150
|
+
this.context.loomObjectMap.set(gqlType, extraObject);
|
|
1151
|
+
this.types.add(extraObject);
|
|
1152
|
+
return extraObject;
|
|
1101
1153
|
})();
|
|
1102
1154
|
if (resolverOptions?.extensions && parentObject)
|
|
1103
1155
|
parentObject.mergeExtensions(resolverOptions.extensions);
|
|
1104
|
-
Object.entries(
|
|
1156
|
+
Object.entries(resolver2).forEach(([name, operation]) => {
|
|
1105
1157
|
if (operation === FIELD_HIDDEN) {
|
|
1106
1158
|
if (parentObject == null) return;
|
|
1107
1159
|
parentObject.hideField(name);
|
|
@@ -1149,12 +1201,16 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1149
1201
|
const middlewares = /* @__PURE__ */ new Set();
|
|
1150
1202
|
const resolvers = /* @__PURE__ */ new Set();
|
|
1151
1203
|
const silks = /* @__PURE__ */ new Set();
|
|
1204
|
+
const weavers = /* @__PURE__ */ new Set();
|
|
1152
1205
|
let context;
|
|
1153
1206
|
for (const item of inputs) {
|
|
1154
|
-
if (
|
|
1207
|
+
if (isSchemaVendorWeaver(item)) {
|
|
1208
|
+
weavers.add(item);
|
|
1209
|
+
} else if (typeof item === "function") {
|
|
1155
1210
|
middlewares.add(item);
|
|
1156
1211
|
} else if (WEAVER_CONFIG in item) {
|
|
1157
1212
|
configs.add(item);
|
|
1213
|
+
if (item.vendorWeaver) weavers.add(item.vendorWeaver);
|
|
1158
1214
|
if (item[WEAVER_CONFIG] === "gqloom.core.schema") {
|
|
1159
1215
|
context = item.weaverContext;
|
|
1160
1216
|
}
|
|
@@ -1164,7 +1220,7 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1164
1220
|
resolvers.add(item);
|
|
1165
1221
|
}
|
|
1166
1222
|
}
|
|
1167
|
-
return { context, configs, middlewares, resolvers, silks };
|
|
1223
|
+
return { context, configs, middlewares, resolvers, silks, weavers };
|
|
1168
1224
|
}
|
|
1169
1225
|
/**
|
|
1170
1226
|
* Weave a GraphQL Schema from resolvers
|
|
@@ -1172,9 +1228,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1172
1228
|
* @returns GraphQ LSchema
|
|
1173
1229
|
*/
|
|
1174
1230
|
static weave(...inputs) {
|
|
1175
|
-
const { context, configs, middlewares, resolvers, silks } = _SchemaWeaver.optionsFrom(...inputs);
|
|
1231
|
+
const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
|
|
1176
1232
|
const weaver = new _SchemaWeaver({}, context);
|
|
1177
1233
|
configs.forEach((it) => weaver.setConfig(it));
|
|
1234
|
+
weavers.forEach((it) => weaver.addVendor(it));
|
|
1178
1235
|
middlewares.forEach((it) => weaver.use(it));
|
|
1179
1236
|
resolvers.forEach((it) => weaver.add(it));
|
|
1180
1237
|
silks.forEach((it) => weaver.addType(it));
|
|
@@ -1184,10 +1241,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1184
1241
|
var weave = SchemaWeaver.weave;
|
|
1185
1242
|
|
|
1186
1243
|
// src/schema/interface.ts
|
|
1187
|
-
var
|
|
1244
|
+
var import_graphql7 = require("graphql");
|
|
1188
1245
|
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1189
|
-
if ((0,
|
|
1190
|
-
if (!(0,
|
|
1246
|
+
if ((0, import_graphql7.isInterfaceType)(gqlType)) return gqlType;
|
|
1247
|
+
if (!(0, import_graphql7.isObjectType)(gqlType))
|
|
1191
1248
|
throw new Error(`${gqlType.toString()} is not an object`);
|
|
1192
1249
|
const key = gqlType;
|
|
1193
1250
|
const existing = weaverContext.interfaceMap?.get(key);
|
|
@@ -1198,11 +1255,11 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1198
1255
|
fields,
|
|
1199
1256
|
...config
|
|
1200
1257
|
} = gqlType.toConfig();
|
|
1201
|
-
const interfaceType = new
|
|
1258
|
+
const interfaceType = new import_graphql7.GraphQLInterfaceType({
|
|
1202
1259
|
...config,
|
|
1203
1260
|
...interfaceConfig,
|
|
1204
|
-
fields: mapValue(fields, (
|
|
1205
|
-
return { ...
|
|
1261
|
+
fields: mapValue(fields, (field2) => {
|
|
1262
|
+
return { ...field2, type: getCacheType(field2.type) };
|
|
1206
1263
|
})
|
|
1207
1264
|
});
|
|
1208
1265
|
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
@@ -1233,20 +1290,24 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1233
1290
|
ensureInputObjectType,
|
|
1234
1291
|
ensureInputType,
|
|
1235
1292
|
ensureInterfaceType,
|
|
1293
|
+
field,
|
|
1236
1294
|
getCacheType,
|
|
1237
1295
|
getFieldOptions,
|
|
1238
1296
|
getGraphQLType,
|
|
1239
1297
|
getOperationOptions,
|
|
1298
|
+
getStandardValue,
|
|
1240
1299
|
getSubscriptionOptions,
|
|
1241
1300
|
initWeaverContext,
|
|
1242
1301
|
inputToArgs,
|
|
1243
1302
|
isOnlyMemoryPayload,
|
|
1303
|
+
isSchemaVendorWeaver,
|
|
1244
1304
|
isSilk,
|
|
1245
1305
|
listSilk,
|
|
1246
1306
|
loom,
|
|
1247
1307
|
mapValue,
|
|
1248
1308
|
markErrorLocation,
|
|
1249
1309
|
markLocation,
|
|
1310
|
+
mutation,
|
|
1250
1311
|
nonNullSilk,
|
|
1251
1312
|
notNullish,
|
|
1252
1313
|
nullableSilk,
|
|
@@ -1254,13 +1315,11 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1254
1315
|
parseInputValue,
|
|
1255
1316
|
parseSilk,
|
|
1256
1317
|
provideWeaverContext,
|
|
1318
|
+
query,
|
|
1319
|
+
resolver,
|
|
1257
1320
|
resolverPayloadStorage,
|
|
1258
1321
|
silk,
|
|
1259
|
-
|
|
1260
|
-
silkMutation,
|
|
1261
|
-
silkQuery,
|
|
1262
|
-
silkResolver,
|
|
1263
|
-
silkSubscription,
|
|
1322
|
+
subscription,
|
|
1264
1323
|
toObjMap,
|
|
1265
1324
|
tryIn,
|
|
1266
1325
|
useContext,
|