@gqloom/core 0.3.0 → 0.4.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/index.cjs +311 -258
- package/dist/index.d.cts +169 -74
- package/dist/index.d.ts +169 -74
- package/dist/index.js +279 -228
- 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,146 @@ __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) => ({ value: value ?? void 0 })) {
|
|
106
231
|
return {
|
|
107
232
|
[GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
108
|
-
|
|
233
|
+
"~standard": {
|
|
234
|
+
version: 1,
|
|
235
|
+
vendor: "gqloom.silk",
|
|
236
|
+
validate
|
|
237
|
+
}
|
|
109
238
|
};
|
|
110
239
|
}
|
|
111
240
|
silk.parse = parseSilk;
|
|
@@ -115,55 +244,66 @@ silk.list = listSilk;
|
|
|
115
244
|
silk.nullable = nullableSilk;
|
|
116
245
|
function nonNullSilk(origin) {
|
|
117
246
|
return {
|
|
247
|
+
...origin,
|
|
118
248
|
[GET_GRAPHQL_TYPE]: () => {
|
|
119
249
|
const originType = getGraphQLType(origin);
|
|
120
|
-
if (originType instanceof
|
|
250
|
+
if (originType instanceof import_graphql2.GraphQLNonNull) {
|
|
121
251
|
return originType;
|
|
122
252
|
} else {
|
|
123
|
-
return new
|
|
253
|
+
return new import_graphql2.GraphQLNonNull(originType);
|
|
124
254
|
}
|
|
125
|
-
}
|
|
126
|
-
[PARSE]: (input) => origin[PARSE]?.(input)
|
|
255
|
+
}
|
|
127
256
|
};
|
|
128
257
|
}
|
|
129
258
|
function listSilk(origin) {
|
|
130
259
|
return {
|
|
260
|
+
...origin,
|
|
131
261
|
[GET_GRAPHQL_TYPE]: () => {
|
|
132
262
|
let originType = getGraphQLType(origin);
|
|
133
|
-
if (originType instanceof
|
|
263
|
+
if (originType instanceof import_graphql2.GraphQLNonNull && originType.ofType instanceof import_graphql2.GraphQLList) {
|
|
134
264
|
originType = originType.ofType;
|
|
135
265
|
}
|
|
136
|
-
if (originType instanceof
|
|
266
|
+
if (originType instanceof import_graphql2.GraphQLList) {
|
|
137
267
|
originType = originType.ofType;
|
|
138
268
|
}
|
|
139
|
-
return new
|
|
269
|
+
return new import_graphql2.GraphQLNonNull(new import_graphql2.GraphQLList(originType));
|
|
140
270
|
}
|
|
141
271
|
};
|
|
142
272
|
}
|
|
143
273
|
function nullableSilk(origin) {
|
|
144
274
|
return {
|
|
275
|
+
...origin,
|
|
145
276
|
[GET_GRAPHQL_TYPE]: () => {
|
|
146
277
|
const originType = getGraphQLType(origin);
|
|
147
|
-
if (originType instanceof
|
|
278
|
+
if (originType instanceof import_graphql2.GraphQLNonNull) {
|
|
148
279
|
return originType.ofType;
|
|
149
280
|
} else {
|
|
150
281
|
return originType;
|
|
151
282
|
}
|
|
152
|
-
}
|
|
153
|
-
[PARSE]: (input) => origin[PARSE]?.(input)
|
|
283
|
+
}
|
|
154
284
|
};
|
|
155
285
|
}
|
|
156
286
|
function getGraphQLType(silk2) {
|
|
157
|
-
|
|
287
|
+
if (GET_GRAPHQL_TYPE in silk2 && silk2[GET_GRAPHQL_TYPE] != null)
|
|
288
|
+
return silk2[GET_GRAPHQL_TYPE]();
|
|
289
|
+
const vendorWeavers = weaverContext.vendorWeavers;
|
|
290
|
+
if (vendorWeavers == null) throw new Error("Schema Weaver is not initialized");
|
|
291
|
+
const weaver = vendorWeavers.get(silk2["~standard"].vendor);
|
|
292
|
+
if (weaver == null)
|
|
293
|
+
throw new Error(
|
|
294
|
+
`Schema Weaver for ${silk2["~standard"].vendor} is not found`
|
|
295
|
+
);
|
|
296
|
+
return weaver.getGraphQLType(silk2);
|
|
158
297
|
}
|
|
159
298
|
function parseSilk(silk2, input) {
|
|
160
|
-
|
|
161
|
-
return silk2[PARSE](input);
|
|
299
|
+
return silk2["~standard"].validate(input);
|
|
162
300
|
}
|
|
163
301
|
function isSilk(target) {
|
|
164
302
|
if (typeof target !== "object") return false;
|
|
165
303
|
if (target == null) return false;
|
|
166
|
-
|
|
304
|
+
if (GET_GRAPHQL_TYPE in target) return true;
|
|
305
|
+
if (!("~standard" in target)) return false;
|
|
306
|
+
return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
|
|
167
307
|
}
|
|
168
308
|
|
|
169
309
|
// src/utils/args.ts
|
|
@@ -380,6 +520,7 @@ function markLocation(message, ...locations) {
|
|
|
380
520
|
}
|
|
381
521
|
|
|
382
522
|
// src/resolver/input.ts
|
|
523
|
+
var import_graphql3 = require("graphql");
|
|
383
524
|
function createInputParser(schema, value) {
|
|
384
525
|
let result;
|
|
385
526
|
const parse = async () => {
|
|
@@ -396,32 +537,43 @@ function createInputParser(schema, value) {
|
|
|
396
537
|
}
|
|
397
538
|
function parseInputValue(inputSchema, input) {
|
|
398
539
|
if (inputSchema === void 0) {
|
|
399
|
-
return input;
|
|
540
|
+
return { value: input };
|
|
400
541
|
}
|
|
401
542
|
if (isSilk(inputSchema)) {
|
|
402
|
-
|
|
403
|
-
return inputSchema[symbols_exports.PARSE](input);
|
|
404
|
-
}
|
|
405
|
-
return input;
|
|
543
|
+
return inputSchema["~standard"].validate(input);
|
|
406
544
|
}
|
|
407
545
|
return parseInputEntries(inputSchema, input);
|
|
408
546
|
}
|
|
409
547
|
async function parseInputEntries(inputSchema, input = {}) {
|
|
410
548
|
const result = {};
|
|
549
|
+
const issues = [];
|
|
411
550
|
await Promise.all(
|
|
412
551
|
Object.entries(inputSchema).map(async ([key, value]) => {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
552
|
+
const res = await value["~standard"].validate(input[key]);
|
|
553
|
+
if ("value" in res) {
|
|
554
|
+
result[key] = res.value;
|
|
555
|
+
}
|
|
556
|
+
if (res.issues) {
|
|
557
|
+
issues.push(...res.issues.slice());
|
|
417
558
|
}
|
|
418
559
|
})
|
|
419
560
|
);
|
|
420
|
-
return result;
|
|
561
|
+
return { value: result, ...issues.length > 0 ? { issues } : null };
|
|
562
|
+
}
|
|
563
|
+
function getStandardValue(result) {
|
|
564
|
+
if (result == null) return result;
|
|
565
|
+
const { issues } = result;
|
|
566
|
+
if (issues?.length) {
|
|
567
|
+
throw new import_graphql3.GraphQLError(issues?.[0]?.message ?? "Invalid input", {
|
|
568
|
+
extensions: { issues }
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
if ("value" in result) return result.value;
|
|
572
|
+
else throw new import_graphql3.GraphQLError("Invalid input");
|
|
421
573
|
}
|
|
422
574
|
|
|
423
575
|
// src/resolver/resolver.ts
|
|
424
|
-
var
|
|
576
|
+
var query = (output, resolveOrOptions) => {
|
|
425
577
|
const options = getOperationOptions(resolveOrOptions);
|
|
426
578
|
const type = "query";
|
|
427
579
|
return {
|
|
@@ -432,14 +584,14 @@ var silkQuery = (output, resolveOrOptions) => {
|
|
|
432
584
|
const parseInput = createInputParser(options.input, inputValue);
|
|
433
585
|
return applyMiddlewares(
|
|
434
586
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
435
|
-
async () => options.resolve(await parseInput()),
|
|
587
|
+
async () => options.resolve(getStandardValue(await parseInput())),
|
|
436
588
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
437
589
|
);
|
|
438
590
|
},
|
|
439
591
|
type
|
|
440
592
|
};
|
|
441
593
|
};
|
|
442
|
-
var
|
|
594
|
+
var mutation = (output, resolveOrOptions) => {
|
|
443
595
|
const options = getOperationOptions(resolveOrOptions);
|
|
444
596
|
const type = "mutation";
|
|
445
597
|
return {
|
|
@@ -450,7 +602,7 @@ var silkMutation = (output, resolveOrOptions) => {
|
|
|
450
602
|
const parseInput = createInputParser(options.input, inputValue);
|
|
451
603
|
return applyMiddlewares(
|
|
452
604
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
453
|
-
async () => options.resolve(await parseInput()),
|
|
605
|
+
async () => options.resolve(getStandardValue(await parseInput())),
|
|
454
606
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
455
607
|
);
|
|
456
608
|
},
|
|
@@ -468,21 +620,21 @@ var baseSilkField = (output, resolveOrOptions) => {
|
|
|
468
620
|
const parseInput = createInputParser(options.input, inputValue);
|
|
469
621
|
return applyMiddlewares(
|
|
470
622
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
471
|
-
async () => options.resolve(parent, await parseInput()),
|
|
623
|
+
async () => options.resolve(parent, getStandardValue(await parseInput())),
|
|
472
624
|
{ parseInput, parent, outputSilk: output, type }
|
|
473
625
|
);
|
|
474
626
|
},
|
|
475
627
|
type
|
|
476
628
|
};
|
|
477
629
|
};
|
|
478
|
-
var
|
|
630
|
+
var field = Object.assign(
|
|
479
631
|
baseSilkField,
|
|
480
632
|
{
|
|
481
633
|
hidden: FIELD_HIDDEN
|
|
482
634
|
}
|
|
483
635
|
);
|
|
484
636
|
var defaultSubscriptionResolve = (source) => source;
|
|
485
|
-
var
|
|
637
|
+
var subscription = (output, subscribeOrOptions) => {
|
|
486
638
|
const options = getSubscriptionOptions(subscribeOrOptions);
|
|
487
639
|
const type = "subscription";
|
|
488
640
|
return {
|
|
@@ -496,7 +648,7 @@ var silkSubscription = (output, subscribeOrOptions) => {
|
|
|
496
648
|
extraOptions?.middlewares,
|
|
497
649
|
options.middlewares
|
|
498
650
|
),
|
|
499
|
-
async () => options.subscribe(await parseInput()),
|
|
651
|
+
async () => options.subscribe(getStandardValue(await parseInput())),
|
|
500
652
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
501
653
|
);
|
|
502
654
|
},
|
|
@@ -543,7 +695,7 @@ function extraOperationOptions(operation, options) {
|
|
|
543
695
|
};
|
|
544
696
|
}
|
|
545
697
|
}
|
|
546
|
-
var
|
|
698
|
+
var resolver = Object.assign(
|
|
547
699
|
baseResolver,
|
|
548
700
|
{
|
|
549
701
|
of: (parent, operations, options) => baseResolver(
|
|
@@ -553,11 +705,11 @@ var silkResolver = Object.assign(
|
|
|
553
705
|
}
|
|
554
706
|
);
|
|
555
707
|
var loom = {
|
|
556
|
-
query
|
|
557
|
-
resolver
|
|
558
|
-
field
|
|
559
|
-
subscription
|
|
560
|
-
mutation
|
|
708
|
+
query,
|
|
709
|
+
resolver,
|
|
710
|
+
field,
|
|
711
|
+
subscription,
|
|
712
|
+
mutation
|
|
561
713
|
};
|
|
562
714
|
|
|
563
715
|
// src/helper/create-loom.ts
|
|
@@ -587,7 +739,7 @@ function createFieldFactory(toSilk, isSchema) {
|
|
|
587
739
|
const options = getOperationOptions(
|
|
588
740
|
resolveOrOptions
|
|
589
741
|
);
|
|
590
|
-
return
|
|
742
|
+
return field(toSilk(output), {
|
|
591
743
|
...options,
|
|
592
744
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
593
745
|
});
|
|
@@ -599,7 +751,7 @@ function createFieldFactory(toSilk, isSchema) {
|
|
|
599
751
|
function createQueryFactory(toSilk, isSchema) {
|
|
600
752
|
return (output, resolveOrOptions) => {
|
|
601
753
|
const options = getOperationOptions(resolveOrOptions);
|
|
602
|
-
return
|
|
754
|
+
return query(toSilk(output), {
|
|
603
755
|
...options,
|
|
604
756
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
605
757
|
});
|
|
@@ -608,7 +760,7 @@ function createQueryFactory(toSilk, isSchema) {
|
|
|
608
760
|
function createMutationFactory(toSilk, isSchema) {
|
|
609
761
|
return (output, resolveOrOptions) => {
|
|
610
762
|
const options = getOperationOptions(resolveOrOptions);
|
|
611
|
-
return
|
|
763
|
+
return mutation(toSilk(output), {
|
|
612
764
|
...options,
|
|
613
765
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
614
766
|
});
|
|
@@ -617,7 +769,7 @@ function createMutationFactory(toSilk, isSchema) {
|
|
|
617
769
|
function createSubscriptionFactory(toSilk, isSchema) {
|
|
618
770
|
return (output, resolveOrOptions) => {
|
|
619
771
|
const options = getSubscriptionOptions(resolveOrOptions);
|
|
620
|
-
return
|
|
772
|
+
return subscription(toSilk(output), {
|
|
621
773
|
...options,
|
|
622
774
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
623
775
|
});
|
|
@@ -634,135 +786,16 @@ function createLoom(toSilk, isSchema) {
|
|
|
634
786
|
}
|
|
635
787
|
|
|
636
788
|
// 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
|
-
}
|
|
789
|
+
var import_graphql5 = require("graphql");
|
|
757
790
|
|
|
758
791
|
// src/schema/input.ts
|
|
759
|
-
var
|
|
792
|
+
var import_graphql4 = require("graphql");
|
|
760
793
|
function inputToArgs(input) {
|
|
761
794
|
if (input === void 0) return void 0;
|
|
762
795
|
if (isSilk(input)) {
|
|
763
796
|
let inputType = getGraphQLType(input);
|
|
764
|
-
if ((0,
|
|
765
|
-
if ((0,
|
|
797
|
+
if ((0, import_graphql4.isNonNullType)(inputType)) inputType = inputType.ofType;
|
|
798
|
+
if ((0, import_graphql4.isObjectType)(inputType)) {
|
|
766
799
|
return mapValue(
|
|
767
800
|
inputType.toConfig().fields,
|
|
768
801
|
(it) => toInputFieldConfig(it)
|
|
@@ -771,11 +804,11 @@ function inputToArgs(input) {
|
|
|
771
804
|
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
772
805
|
}
|
|
773
806
|
const args = {};
|
|
774
|
-
Object.entries(input).forEach(([name,
|
|
807
|
+
Object.entries(input).forEach(([name, field2]) => {
|
|
775
808
|
tryIn(() => {
|
|
776
809
|
args[name] = {
|
|
777
|
-
...
|
|
778
|
-
type: ensureInputType(
|
|
810
|
+
...field2,
|
|
811
|
+
type: ensureInputType(field2)
|
|
779
812
|
};
|
|
780
813
|
}, name);
|
|
781
814
|
});
|
|
@@ -788,20 +821,20 @@ function ensureInputType(silkOrType) {
|
|
|
788
821
|
}
|
|
789
822
|
return silkOrType;
|
|
790
823
|
})();
|
|
791
|
-
if ((0,
|
|
824
|
+
if ((0, import_graphql4.isUnionType)(gqlType))
|
|
792
825
|
throw new Error(`Cannot convert union type ${gqlType.name} to input type`);
|
|
793
|
-
if ((0,
|
|
794
|
-
return new
|
|
826
|
+
if ((0, import_graphql4.isNonNullType)(gqlType)) {
|
|
827
|
+
return new import_graphql4.GraphQLNonNull(ensureInputType(gqlType.ofType));
|
|
795
828
|
}
|
|
796
|
-
if ((0,
|
|
797
|
-
return new
|
|
829
|
+
if ((0, import_graphql4.isListType)(gqlType)) {
|
|
830
|
+
return new import_graphql4.GraphQLList(ensureInputType(gqlType.ofType));
|
|
798
831
|
}
|
|
799
|
-
if ((0,
|
|
832
|
+
if ((0, import_graphql4.isObjectType)(gqlType) || (0, import_graphql4.isInterfaceType)(gqlType))
|
|
800
833
|
return ensureInputObjectType(gqlType);
|
|
801
834
|
return gqlType;
|
|
802
835
|
}
|
|
803
836
|
function ensureInputObjectType(object) {
|
|
804
|
-
if ((0,
|
|
837
|
+
if ((0, import_graphql4.isInputObjectType)(object)) return object;
|
|
805
838
|
const existing = weaverContext.inputMap?.get(object);
|
|
806
839
|
if (existing != null) return existing;
|
|
807
840
|
const {
|
|
@@ -811,7 +844,7 @@ function ensureInputObjectType(object) {
|
|
|
811
844
|
...config
|
|
812
845
|
} = object.toConfig();
|
|
813
846
|
const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((name) => name);
|
|
814
|
-
const input = new
|
|
847
|
+
const input = new import_graphql4.GraphQLInputObjectType({
|
|
815
848
|
...config,
|
|
816
849
|
name: getInputObjectName(object.name),
|
|
817
850
|
fields: provideWeaverContext.inherit(
|
|
@@ -830,7 +863,7 @@ function toInputFieldConfig({
|
|
|
830
863
|
}
|
|
831
864
|
|
|
832
865
|
// src/schema/object.ts
|
|
833
|
-
var LoomObjectType = class extends
|
|
866
|
+
var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
|
|
834
867
|
extraFields = /* @__PURE__ */ new Map();
|
|
835
868
|
hiddenFields = /* @__PURE__ */ new Set();
|
|
836
869
|
weaverContext;
|
|
@@ -838,7 +871,7 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
838
871
|
constructor(objectOrGetter, options = {}) {
|
|
839
872
|
const origin = typeof objectOrGetter === "function" ? objectOrGetter() : objectOrGetter;
|
|
840
873
|
const config = (() => {
|
|
841
|
-
if ((0,
|
|
874
|
+
if ((0, import_graphql5.isObjectType)(origin)) {
|
|
842
875
|
return origin.toConfig();
|
|
843
876
|
} else if (typeof origin === "string") {
|
|
844
877
|
return { name: origin, fields: {} };
|
|
@@ -853,12 +886,12 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
853
886
|
hideField(name) {
|
|
854
887
|
this.hiddenFields.add(name);
|
|
855
888
|
}
|
|
856
|
-
addField(name,
|
|
889
|
+
addField(name, resolver2) {
|
|
857
890
|
const existing = this.extraFields.get(name);
|
|
858
|
-
if (existing && existing !==
|
|
891
|
+
if (existing && existing !== resolver2) {
|
|
859
892
|
throw new Error(`Field ${name} already exists in ${this.name}`);
|
|
860
893
|
}
|
|
861
|
-
this.extraFields.set(name,
|
|
894
|
+
this.extraFields.set(name, resolver2);
|
|
862
895
|
}
|
|
863
896
|
mergeExtensions(extensions) {
|
|
864
897
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
@@ -867,7 +900,7 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
867
900
|
getFields() {
|
|
868
901
|
const fieldsBySuper = super.getFields();
|
|
869
902
|
Object.values(fieldsBySuper).forEach(
|
|
870
|
-
(
|
|
903
|
+
(field2) => field2.type = this.getCacheType(field2.type)
|
|
871
904
|
);
|
|
872
905
|
const extraFields = provideWeaverContext(
|
|
873
906
|
() => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
|
|
@@ -887,47 +920,47 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
887
920
|
}
|
|
888
921
|
mapToFieldConfig(map) {
|
|
889
922
|
const record = {};
|
|
890
|
-
for (const [name,
|
|
891
|
-
record[name] = this.toFieldConfig(
|
|
923
|
+
for (const [name, field2] of map.entries()) {
|
|
924
|
+
record[name] = this.toFieldConfig(field2);
|
|
892
925
|
}
|
|
893
926
|
return record;
|
|
894
927
|
}
|
|
895
|
-
toFieldConfig(
|
|
928
|
+
toFieldConfig(field2) {
|
|
896
929
|
try {
|
|
897
|
-
const outputType = this.getCacheType(getGraphQLType(
|
|
930
|
+
const outputType = this.getCacheType(getGraphQLType(field2.output));
|
|
898
931
|
return {
|
|
899
|
-
...extract(
|
|
932
|
+
...extract(field2),
|
|
900
933
|
type: outputType,
|
|
901
|
-
args: inputToArgs(
|
|
902
|
-
...this.provideForResolve(
|
|
903
|
-
...this.provideForSubscribe(
|
|
934
|
+
args: inputToArgs(field2.input),
|
|
935
|
+
...this.provideForResolve(field2),
|
|
936
|
+
...this.provideForSubscribe(field2)
|
|
904
937
|
};
|
|
905
938
|
} catch (error) {
|
|
906
939
|
throw markErrorLocation(error);
|
|
907
940
|
}
|
|
908
941
|
}
|
|
909
|
-
provideForResolve(
|
|
910
|
-
if (
|
|
911
|
-
if (
|
|
942
|
+
provideForResolve(field2) {
|
|
943
|
+
if (field2?.resolve == null) return;
|
|
944
|
+
if (field2.resolve === defaultSubscriptionResolve)
|
|
912
945
|
return { resolve: defaultSubscriptionResolve };
|
|
913
|
-
const resolve =
|
|
914
|
-
{ root, args, context, info, field },
|
|
915
|
-
() =>
|
|
916
|
-
) :
|
|
917
|
-
{ root, args, context, info, field },
|
|
918
|
-
() =>
|
|
946
|
+
const resolve = field2.type === "field" ? (root, args, context, info) => resolverPayloadStorage.run(
|
|
947
|
+
{ root, args, context, info, field: field2 },
|
|
948
|
+
() => field2.resolve(root, args, this.resolverOptions)
|
|
949
|
+
) : field2.type === "subscription" ? (root, args, context, info) => resolverPayloadStorage.run(
|
|
950
|
+
{ root, args, context, info, field: field2 },
|
|
951
|
+
() => field2.resolve(root, args)
|
|
919
952
|
) : (root, args, context, info) => resolverPayloadStorage.run(
|
|
920
|
-
{ root, args, context, info, field },
|
|
921
|
-
() =>
|
|
953
|
+
{ root, args, context, info, field: field2 },
|
|
954
|
+
() => field2.resolve(args, this.resolverOptions)
|
|
922
955
|
);
|
|
923
956
|
return { resolve };
|
|
924
957
|
}
|
|
925
|
-
provideForSubscribe(
|
|
926
|
-
if (
|
|
958
|
+
provideForSubscribe(field2) {
|
|
959
|
+
if (field2?.subscribe == null) return;
|
|
927
960
|
return {
|
|
928
961
|
subscribe: (root, args, context, info) => resolverPayloadStorage.run(
|
|
929
|
-
{ root, args, context, info, field },
|
|
930
|
-
() =>
|
|
962
|
+
{ root, args, context, info, field: field2 },
|
|
963
|
+
() => field2.subscribe?.(args, this.resolverOptions)
|
|
931
964
|
)
|
|
932
965
|
};
|
|
933
966
|
}
|
|
@@ -951,11 +984,11 @@ function extract({
|
|
|
951
984
|
};
|
|
952
985
|
}
|
|
953
986
|
function defineFieldMap(fields) {
|
|
954
|
-
const fieldMap = (0,
|
|
987
|
+
const fieldMap = (0, import_graphql5.resolveObjMapThunk)(fields);
|
|
955
988
|
return mapValue(fieldMap, (fieldConfig, fieldName) => {
|
|
956
989
|
const argsConfig = fieldConfig.args ?? {};
|
|
957
990
|
return {
|
|
958
|
-
name: (0,
|
|
991
|
+
name: (0, import_graphql5.assertName)(fieldName),
|
|
959
992
|
description: fieldConfig.description,
|
|
960
993
|
type: fieldConfig.type,
|
|
961
994
|
args: defineArguments(argsConfig),
|
|
@@ -969,7 +1002,7 @@ function defineFieldMap(fields) {
|
|
|
969
1002
|
}
|
|
970
1003
|
function defineArguments(args) {
|
|
971
1004
|
return Object.entries(args).map(([argName, argConfig]) => ({
|
|
972
|
-
name: (0,
|
|
1005
|
+
name: (0, import_graphql5.assertName)(argName),
|
|
973
1006
|
description: argConfig.description,
|
|
974
1007
|
type: argConfig.type,
|
|
975
1008
|
defaultValue: argConfig.defaultValue,
|
|
@@ -981,21 +1014,21 @@ function defineArguments(args) {
|
|
|
981
1014
|
function getCacheType(gqlType, options = {}) {
|
|
982
1015
|
const context = options.weaverContext ?? weaverContext;
|
|
983
1016
|
if (gqlType instanceof LoomObjectType) return gqlType;
|
|
984
|
-
if ((0,
|
|
1017
|
+
if ((0, import_graphql5.isObjectType)(gqlType)) {
|
|
985
1018
|
const gqlObject = context.loomObjectMap?.get(gqlType);
|
|
986
1019
|
if (gqlObject != null) return gqlObject;
|
|
987
1020
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
988
1021
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
989
1022
|
return loomObject;
|
|
990
|
-
} else if ((0,
|
|
991
|
-
return new
|
|
992
|
-
} else if ((0,
|
|
993
|
-
return new
|
|
994
|
-
} else if ((0,
|
|
1023
|
+
} else if ((0, import_graphql5.isListType)(gqlType)) {
|
|
1024
|
+
return new import_graphql5.GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1025
|
+
} else if ((0, import_graphql5.isNonNullType)(gqlType)) {
|
|
1026
|
+
return new import_graphql5.GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
1027
|
+
} else if ((0, import_graphql5.isUnionType)(gqlType)) {
|
|
995
1028
|
const existing = context.loomUnionMap?.get(gqlType);
|
|
996
1029
|
if (existing != null) return existing;
|
|
997
1030
|
const config = gqlType.toConfig();
|
|
998
|
-
const unionType = new
|
|
1031
|
+
const unionType = new import_graphql5.GraphQLUnionType({
|
|
999
1032
|
...config,
|
|
1000
1033
|
types: config.types.map(
|
|
1001
1034
|
(type) => getCacheType(type, options)
|
|
@@ -1007,8 +1040,17 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1007
1040
|
return gqlType;
|
|
1008
1041
|
}
|
|
1009
1042
|
|
|
1043
|
+
// src/schema/schema-vendor-weaver.ts
|
|
1044
|
+
function isSchemaVendorWeaver(some) {
|
|
1045
|
+
if (typeof some !== "object" && typeof some !== "function") return false;
|
|
1046
|
+
if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function")
|
|
1047
|
+
return false;
|
|
1048
|
+
if (!("vendor" in some) || typeof some.vendor !== "string") return false;
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1010
1052
|
// src/schema/schema-weaver.ts
|
|
1011
|
-
var
|
|
1053
|
+
var import_graphql6 = require("graphql");
|
|
1012
1054
|
var SchemaWeaver = class _SchemaWeaver {
|
|
1013
1055
|
query;
|
|
1014
1056
|
mutation;
|
|
@@ -1027,10 +1069,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1027
1069
|
[WEAVER_CONFIG]: "gqloom.core.schema"
|
|
1028
1070
|
};
|
|
1029
1071
|
}
|
|
1030
|
-
constructor({ query, mutation, subscription, types } = {}, context) {
|
|
1031
|
-
if (
|
|
1032
|
-
if (
|
|
1033
|
-
if (
|
|
1072
|
+
constructor({ query: query2, mutation: mutation2, subscription: subscription2, types } = {}, context) {
|
|
1073
|
+
if (query2 != null) this.query = query2;
|
|
1074
|
+
if (mutation2 != null) this.mutation = mutation2;
|
|
1075
|
+
if (subscription2 != null) this.subscription = subscription2;
|
|
1034
1076
|
if (types != null) this.types = types.slice();
|
|
1035
1077
|
this.context = context ?? initWeaverContext();
|
|
1036
1078
|
}
|
|
@@ -1040,21 +1082,25 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1040
1082
|
this.resolverOptions.middlewares.push(...middlewares);
|
|
1041
1083
|
return this;
|
|
1042
1084
|
}
|
|
1043
|
-
add(
|
|
1044
|
-
provideWeaverContext(() => this.addResolver(
|
|
1085
|
+
add(resolver2) {
|
|
1086
|
+
provideWeaverContext(() => this.addResolver(resolver2), this.context);
|
|
1087
|
+
return this;
|
|
1088
|
+
}
|
|
1089
|
+
addVendor(weaver) {
|
|
1090
|
+
this.context.vendorWeavers.set(weaver.vendor, weaver);
|
|
1045
1091
|
return this;
|
|
1046
1092
|
}
|
|
1047
1093
|
addType(silk2) {
|
|
1048
1094
|
const gqlType = provideWeaverContext(() => {
|
|
1049
1095
|
let gqlType2 = getGraphQLType(silk2);
|
|
1050
|
-
if ((0,
|
|
1051
|
-
if ((0,
|
|
1096
|
+
if ((0, import_graphql6.isNonNullType)(gqlType2)) gqlType2 = gqlType2.ofType;
|
|
1097
|
+
if ((0, import_graphql6.isObjectType)(gqlType2)) {
|
|
1052
1098
|
const existing = this.context.loomObjectMap.get(gqlType2);
|
|
1053
1099
|
if (existing != null) return existing;
|
|
1054
1100
|
const extraObject = new LoomObjectType(gqlType2, this.fieldOptions);
|
|
1055
1101
|
this.context.loomObjectMap.set(gqlType2, extraObject);
|
|
1056
1102
|
return extraObject;
|
|
1057
|
-
} else if ((0,
|
|
1103
|
+
} else if ((0, import_graphql6.isUnionType)(gqlType2) || (0, import_graphql6.isEnumType)(gqlType2)) {
|
|
1058
1104
|
return gqlType2;
|
|
1059
1105
|
}
|
|
1060
1106
|
throw new Error(
|
|
@@ -1070,25 +1116,25 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1070
1116
|
return this;
|
|
1071
1117
|
}
|
|
1072
1118
|
weaveGraphQLSchema() {
|
|
1073
|
-
const { query, mutation, subscription, types } = this;
|
|
1119
|
+
const { query: query2, mutation: mutation2, subscription: subscription2, types } = this;
|
|
1074
1120
|
const config = this.context.getConfig("gqloom.core.schema");
|
|
1075
|
-
const schema = new
|
|
1076
|
-
query,
|
|
1077
|
-
mutation,
|
|
1078
|
-
subscription,
|
|
1121
|
+
const schema = new import_graphql6.GraphQLSchema({
|
|
1122
|
+
query: query2,
|
|
1123
|
+
mutation: mutation2,
|
|
1124
|
+
subscription: subscription2,
|
|
1079
1125
|
types: [...types ?? [], ...config?.types ?? []],
|
|
1080
1126
|
...config
|
|
1081
1127
|
});
|
|
1082
1128
|
return schema;
|
|
1083
1129
|
}
|
|
1084
|
-
addResolver(
|
|
1085
|
-
const resolverOptions = ResolverOptionsMap.get(
|
|
1130
|
+
addResolver(resolver2) {
|
|
1131
|
+
const resolverOptions = ResolverOptionsMap.get(resolver2);
|
|
1086
1132
|
const parent = resolverOptions?.parent;
|
|
1087
1133
|
const parentObject = (() => {
|
|
1088
1134
|
if (parent == null) return void 0;
|
|
1089
1135
|
let gqlType = getGraphQLType(parent);
|
|
1090
|
-
if ((0,
|
|
1091
|
-
if ((0,
|
|
1136
|
+
if ((0, import_graphql6.isNonNullType)(gqlType)) gqlType = gqlType.ofType;
|
|
1137
|
+
if ((0, import_graphql6.isObjectType)(gqlType)) {
|
|
1092
1138
|
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1093
1139
|
if (existing != null) return existing;
|
|
1094
1140
|
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
@@ -1101,7 +1147,7 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1101
1147
|
})();
|
|
1102
1148
|
if (resolverOptions?.extensions && parentObject)
|
|
1103
1149
|
parentObject.mergeExtensions(resolverOptions.extensions);
|
|
1104
|
-
Object.entries(
|
|
1150
|
+
Object.entries(resolver2).forEach(([name, operation]) => {
|
|
1105
1151
|
if (operation === FIELD_HIDDEN) {
|
|
1106
1152
|
if (parentObject == null) return;
|
|
1107
1153
|
parentObject.hideField(name);
|
|
@@ -1149,12 +1195,16 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1149
1195
|
const middlewares = /* @__PURE__ */ new Set();
|
|
1150
1196
|
const resolvers = /* @__PURE__ */ new Set();
|
|
1151
1197
|
const silks = /* @__PURE__ */ new Set();
|
|
1198
|
+
const weavers = /* @__PURE__ */ new Set();
|
|
1152
1199
|
let context;
|
|
1153
1200
|
for (const item of inputs) {
|
|
1154
|
-
if (
|
|
1201
|
+
if (isSchemaVendorWeaver(item)) {
|
|
1202
|
+
weavers.add(item);
|
|
1203
|
+
} else if (typeof item === "function") {
|
|
1155
1204
|
middlewares.add(item);
|
|
1156
1205
|
} else if (WEAVER_CONFIG in item) {
|
|
1157
1206
|
configs.add(item);
|
|
1207
|
+
if (item.vendorWeaver) weavers.add(item.vendorWeaver);
|
|
1158
1208
|
if (item[WEAVER_CONFIG] === "gqloom.core.schema") {
|
|
1159
1209
|
context = item.weaverContext;
|
|
1160
1210
|
}
|
|
@@ -1164,7 +1214,7 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1164
1214
|
resolvers.add(item);
|
|
1165
1215
|
}
|
|
1166
1216
|
}
|
|
1167
|
-
return { context, configs, middlewares, resolvers, silks };
|
|
1217
|
+
return { context, configs, middlewares, resolvers, silks, weavers };
|
|
1168
1218
|
}
|
|
1169
1219
|
/**
|
|
1170
1220
|
* Weave a GraphQL Schema from resolvers
|
|
@@ -1172,9 +1222,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1172
1222
|
* @returns GraphQ LSchema
|
|
1173
1223
|
*/
|
|
1174
1224
|
static weave(...inputs) {
|
|
1175
|
-
const { context, configs, middlewares, resolvers, silks } = _SchemaWeaver.optionsFrom(...inputs);
|
|
1225
|
+
const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
|
|
1176
1226
|
const weaver = new _SchemaWeaver({}, context);
|
|
1177
1227
|
configs.forEach((it) => weaver.setConfig(it));
|
|
1228
|
+
weavers.forEach((it) => weaver.addVendor(it));
|
|
1178
1229
|
middlewares.forEach((it) => weaver.use(it));
|
|
1179
1230
|
resolvers.forEach((it) => weaver.add(it));
|
|
1180
1231
|
silks.forEach((it) => weaver.addType(it));
|
|
@@ -1184,10 +1235,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1184
1235
|
var weave = SchemaWeaver.weave;
|
|
1185
1236
|
|
|
1186
1237
|
// src/schema/interface.ts
|
|
1187
|
-
var
|
|
1238
|
+
var import_graphql7 = require("graphql");
|
|
1188
1239
|
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1189
|
-
if ((0,
|
|
1190
|
-
if (!(0,
|
|
1240
|
+
if ((0, import_graphql7.isInterfaceType)(gqlType)) return gqlType;
|
|
1241
|
+
if (!(0, import_graphql7.isObjectType)(gqlType))
|
|
1191
1242
|
throw new Error(`${gqlType.toString()} is not an object`);
|
|
1192
1243
|
const key = gqlType;
|
|
1193
1244
|
const existing = weaverContext.interfaceMap?.get(key);
|
|
@@ -1198,11 +1249,11 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1198
1249
|
fields,
|
|
1199
1250
|
...config
|
|
1200
1251
|
} = gqlType.toConfig();
|
|
1201
|
-
const interfaceType = new
|
|
1252
|
+
const interfaceType = new import_graphql7.GraphQLInterfaceType({
|
|
1202
1253
|
...config,
|
|
1203
1254
|
...interfaceConfig,
|
|
1204
|
-
fields: mapValue(fields, (
|
|
1205
|
-
return { ...
|
|
1255
|
+
fields: mapValue(fields, (field2) => {
|
|
1256
|
+
return { ...field2, type: getCacheType(field2.type) };
|
|
1206
1257
|
})
|
|
1207
1258
|
});
|
|
1208
1259
|
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
@@ -1233,20 +1284,24 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1233
1284
|
ensureInputObjectType,
|
|
1234
1285
|
ensureInputType,
|
|
1235
1286
|
ensureInterfaceType,
|
|
1287
|
+
field,
|
|
1236
1288
|
getCacheType,
|
|
1237
1289
|
getFieldOptions,
|
|
1238
1290
|
getGraphQLType,
|
|
1239
1291
|
getOperationOptions,
|
|
1292
|
+
getStandardValue,
|
|
1240
1293
|
getSubscriptionOptions,
|
|
1241
1294
|
initWeaverContext,
|
|
1242
1295
|
inputToArgs,
|
|
1243
1296
|
isOnlyMemoryPayload,
|
|
1297
|
+
isSchemaVendorWeaver,
|
|
1244
1298
|
isSilk,
|
|
1245
1299
|
listSilk,
|
|
1246
1300
|
loom,
|
|
1247
1301
|
mapValue,
|
|
1248
1302
|
markErrorLocation,
|
|
1249
1303
|
markLocation,
|
|
1304
|
+
mutation,
|
|
1250
1305
|
nonNullSilk,
|
|
1251
1306
|
notNullish,
|
|
1252
1307
|
nullableSilk,
|
|
@@ -1254,13 +1309,11 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1254
1309
|
parseInputValue,
|
|
1255
1310
|
parseSilk,
|
|
1256
1311
|
provideWeaverContext,
|
|
1312
|
+
query,
|
|
1313
|
+
resolver,
|
|
1257
1314
|
resolverPayloadStorage,
|
|
1258
1315
|
silk,
|
|
1259
|
-
|
|
1260
|
-
silkMutation,
|
|
1261
|
-
silkQuery,
|
|
1262
|
-
silkResolver,
|
|
1263
|
-
silkSubscription,
|
|
1316
|
+
subscription,
|
|
1264
1317
|
toObjMap,
|
|
1265
1318
|
tryIn,
|
|
1266
1319
|
useContext,
|