@gqloom/core 0.2.2 → 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/README.md +1 -1
- package/dist/index.cjs +370 -284
- package/dist/index.d.cts +228 -102
- package/dist/index.d.ts +228 -102
- package/dist/index.js +332 -247
- package/package.json +13 -5
package/dist/index.cjs
CHANGED
|
@@ -27,36 +27,40 @@ __export(src_exports, {
|
|
|
27
27
|
SchemaWeaver: () => SchemaWeaver,
|
|
28
28
|
applyMiddlewares: () => applyMiddlewares,
|
|
29
29
|
baseResolver: () => baseResolver,
|
|
30
|
+
collectName: () => collectName,
|
|
30
31
|
collectNames: () => collectNames,
|
|
31
32
|
compose: () => compose,
|
|
32
|
-
|
|
33
|
+
createFieldFactory: () => createFieldFactory,
|
|
33
34
|
createInputParser: () => createInputParser,
|
|
34
35
|
createLoom: () => createLoom,
|
|
35
36
|
createMemoization: () => createMemoization,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
createMutationFactory: () => createMutationFactory,
|
|
38
|
+
createQueryFactory: () => createQueryFactory,
|
|
39
|
+
createResolverFactory: () => createResolverFactory,
|
|
40
|
+
createSubscriptionFactory: () => createSubscriptionFactory,
|
|
40
41
|
deepMerge: () => deepMerge,
|
|
41
42
|
defaultSubscriptionResolve: () => defaultSubscriptionResolve,
|
|
42
43
|
ensureInputObjectType: () => ensureInputObjectType,
|
|
43
44
|
ensureInputType: () => ensureInputType,
|
|
44
45
|
ensureInterfaceType: () => ensureInterfaceType,
|
|
46
|
+
field: () => field,
|
|
45
47
|
getCacheType: () => getCacheType,
|
|
46
48
|
getFieldOptions: () => getFieldOptions,
|
|
47
49
|
getGraphQLType: () => getGraphQLType,
|
|
48
50
|
getOperationOptions: () => getOperationOptions,
|
|
51
|
+
getStandardValue: () => getStandardValue,
|
|
49
52
|
getSubscriptionOptions: () => getSubscriptionOptions,
|
|
50
53
|
initWeaverContext: () => initWeaverContext,
|
|
51
54
|
inputToArgs: () => inputToArgs,
|
|
52
55
|
isOnlyMemoryPayload: () => isOnlyMemoryPayload,
|
|
56
|
+
isSchemaVendorWeaver: () => isSchemaVendorWeaver,
|
|
53
57
|
isSilk: () => isSilk,
|
|
54
58
|
listSilk: () => listSilk,
|
|
55
59
|
loom: () => loom,
|
|
56
60
|
mapValue: () => mapValue,
|
|
57
61
|
markErrorLocation: () => markErrorLocation,
|
|
58
62
|
markLocation: () => markLocation,
|
|
59
|
-
|
|
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,28 +84,157 @@ __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
|
|
88
93
|
var symbols_exports = {};
|
|
89
94
|
__export(symbols_exports, {
|
|
90
95
|
CONTEXT_MEMORY_MAP_KEY: () => CONTEXT_MEMORY_MAP_KEY,
|
|
96
|
+
FIELD_HIDDEN: () => FIELD_HIDDEN,
|
|
91
97
|
GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
|
|
92
|
-
PARSE: () => PARSE,
|
|
93
98
|
RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
|
|
94
99
|
WEAVER_CONFIG: () => WEAVER_CONFIG
|
|
95
100
|
});
|
|
96
101
|
var GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
|
|
97
|
-
var PARSE = Symbol.for("gqloom.parse");
|
|
98
102
|
var WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
|
|
99
103
|
var RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
|
|
100
104
|
var CONTEXT_MEMORY_MAP_KEY = Symbol.for("gqloom.context-memory");
|
|
105
|
+
var FIELD_HIDDEN = Symbol.for("gqloom.field-hidden");
|
|
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
|
+
}
|
|
101
228
|
|
|
102
229
|
// src/resolver/silk.ts
|
|
103
|
-
function silk(type,
|
|
230
|
+
function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
|
|
104
231
|
return {
|
|
105
232
|
[GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
|
|
106
|
-
|
|
233
|
+
"~standard": {
|
|
234
|
+
version: 1,
|
|
235
|
+
vendor: "gqloom.silk",
|
|
236
|
+
validate
|
|
237
|
+
}
|
|
107
238
|
};
|
|
108
239
|
}
|
|
109
240
|
silk.parse = parseSilk;
|
|
@@ -113,55 +244,66 @@ silk.list = listSilk;
|
|
|
113
244
|
silk.nullable = nullableSilk;
|
|
114
245
|
function nonNullSilk(origin) {
|
|
115
246
|
return {
|
|
247
|
+
...origin,
|
|
116
248
|
[GET_GRAPHQL_TYPE]: () => {
|
|
117
249
|
const originType = getGraphQLType(origin);
|
|
118
|
-
if (originType instanceof
|
|
250
|
+
if (originType instanceof import_graphql2.GraphQLNonNull) {
|
|
119
251
|
return originType;
|
|
120
252
|
} else {
|
|
121
|
-
return new
|
|
253
|
+
return new import_graphql2.GraphQLNonNull(originType);
|
|
122
254
|
}
|
|
123
|
-
}
|
|
124
|
-
[PARSE]: (input) => origin[PARSE]?.(input)
|
|
255
|
+
}
|
|
125
256
|
};
|
|
126
257
|
}
|
|
127
258
|
function listSilk(origin) {
|
|
128
259
|
return {
|
|
260
|
+
...origin,
|
|
129
261
|
[GET_GRAPHQL_TYPE]: () => {
|
|
130
262
|
let originType = getGraphQLType(origin);
|
|
131
|
-
if (originType instanceof
|
|
263
|
+
if (originType instanceof import_graphql2.GraphQLNonNull && originType.ofType instanceof import_graphql2.GraphQLList) {
|
|
132
264
|
originType = originType.ofType;
|
|
133
265
|
}
|
|
134
|
-
if (originType instanceof
|
|
266
|
+
if (originType instanceof import_graphql2.GraphQLList) {
|
|
135
267
|
originType = originType.ofType;
|
|
136
268
|
}
|
|
137
|
-
return new
|
|
269
|
+
return new import_graphql2.GraphQLNonNull(new import_graphql2.GraphQLList(originType));
|
|
138
270
|
}
|
|
139
271
|
};
|
|
140
272
|
}
|
|
141
273
|
function nullableSilk(origin) {
|
|
142
274
|
return {
|
|
275
|
+
...origin,
|
|
143
276
|
[GET_GRAPHQL_TYPE]: () => {
|
|
144
277
|
const originType = getGraphQLType(origin);
|
|
145
|
-
if (originType instanceof
|
|
278
|
+
if (originType instanceof import_graphql2.GraphQLNonNull) {
|
|
146
279
|
return originType.ofType;
|
|
147
280
|
} else {
|
|
148
281
|
return originType;
|
|
149
282
|
}
|
|
150
|
-
}
|
|
151
|
-
[PARSE]: (input) => origin[PARSE]?.(input)
|
|
283
|
+
}
|
|
152
284
|
};
|
|
153
285
|
}
|
|
154
286
|
function getGraphQLType(silk2) {
|
|
155
|
-
|
|
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);
|
|
156
297
|
}
|
|
157
298
|
function parseSilk(silk2, input) {
|
|
158
|
-
|
|
159
|
-
return silk2[PARSE](input);
|
|
299
|
+
return silk2["~standard"].validate(input);
|
|
160
300
|
}
|
|
161
301
|
function isSilk(target) {
|
|
162
302
|
if (typeof target !== "object") return false;
|
|
163
303
|
if (target == null) return false;
|
|
164
|
-
|
|
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";
|
|
165
307
|
}
|
|
166
308
|
|
|
167
309
|
// src/utils/args.ts
|
|
@@ -378,6 +520,7 @@ function markLocation(message, ...locations) {
|
|
|
378
520
|
}
|
|
379
521
|
|
|
380
522
|
// src/resolver/input.ts
|
|
523
|
+
var import_graphql3 = require("graphql");
|
|
381
524
|
function createInputParser(schema, value) {
|
|
382
525
|
let result;
|
|
383
526
|
const parse = async () => {
|
|
@@ -394,32 +537,43 @@ function createInputParser(schema, value) {
|
|
|
394
537
|
}
|
|
395
538
|
function parseInputValue(inputSchema, input) {
|
|
396
539
|
if (inputSchema === void 0) {
|
|
397
|
-
return input;
|
|
540
|
+
return { value: input };
|
|
398
541
|
}
|
|
399
542
|
if (isSilk(inputSchema)) {
|
|
400
|
-
|
|
401
|
-
return inputSchema[symbols_exports.PARSE](input);
|
|
402
|
-
}
|
|
403
|
-
return input;
|
|
543
|
+
return inputSchema["~standard"].validate(input);
|
|
404
544
|
}
|
|
405
545
|
return parseInputEntries(inputSchema, input);
|
|
406
546
|
}
|
|
407
547
|
async function parseInputEntries(inputSchema, input = {}) {
|
|
408
548
|
const result = {};
|
|
549
|
+
const issues = [];
|
|
409
550
|
await Promise.all(
|
|
410
551
|
Object.entries(inputSchema).map(async ([key, value]) => {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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());
|
|
415
558
|
}
|
|
416
559
|
})
|
|
417
560
|
);
|
|
418
|
-
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");
|
|
419
573
|
}
|
|
420
574
|
|
|
421
575
|
// src/resolver/resolver.ts
|
|
422
|
-
var
|
|
576
|
+
var query = (output, resolveOrOptions) => {
|
|
423
577
|
const options = getOperationOptions(resolveOrOptions);
|
|
424
578
|
const type = "query";
|
|
425
579
|
return {
|
|
@@ -430,14 +584,14 @@ var silkQuery = (output, resolveOrOptions) => {
|
|
|
430
584
|
const parseInput = createInputParser(options.input, inputValue);
|
|
431
585
|
return applyMiddlewares(
|
|
432
586
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
433
|
-
async () => options.resolve(await parseInput()),
|
|
587
|
+
async () => options.resolve(getStandardValue(await parseInput())),
|
|
434
588
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
435
589
|
);
|
|
436
590
|
},
|
|
437
591
|
type
|
|
438
592
|
};
|
|
439
593
|
};
|
|
440
|
-
var
|
|
594
|
+
var mutation = (output, resolveOrOptions) => {
|
|
441
595
|
const options = getOperationOptions(resolveOrOptions);
|
|
442
596
|
const type = "mutation";
|
|
443
597
|
return {
|
|
@@ -448,14 +602,14 @@ var silkMutation = (output, resolveOrOptions) => {
|
|
|
448
602
|
const parseInput = createInputParser(options.input, inputValue);
|
|
449
603
|
return applyMiddlewares(
|
|
450
604
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
451
|
-
async () => options.resolve(await parseInput()),
|
|
605
|
+
async () => options.resolve(getStandardValue(await parseInput())),
|
|
452
606
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
453
607
|
);
|
|
454
608
|
},
|
|
455
609
|
type
|
|
456
610
|
};
|
|
457
611
|
};
|
|
458
|
-
var
|
|
612
|
+
var baseSilkField = (output, resolveOrOptions) => {
|
|
459
613
|
const options = getOperationOptions(resolveOrOptions);
|
|
460
614
|
const type = "field";
|
|
461
615
|
return {
|
|
@@ -466,15 +620,21 @@ var silkField = (output, resolveOrOptions) => {
|
|
|
466
620
|
const parseInput = createInputParser(options.input, inputValue);
|
|
467
621
|
return applyMiddlewares(
|
|
468
622
|
compose(extraOptions?.middlewares, options.middlewares),
|
|
469
|
-
async () => options.resolve(parent, await parseInput()),
|
|
623
|
+
async () => options.resolve(parent, getStandardValue(await parseInput())),
|
|
470
624
|
{ parseInput, parent, outputSilk: output, type }
|
|
471
625
|
);
|
|
472
626
|
},
|
|
473
627
|
type
|
|
474
628
|
};
|
|
475
629
|
};
|
|
630
|
+
var field = Object.assign(
|
|
631
|
+
baseSilkField,
|
|
632
|
+
{
|
|
633
|
+
hidden: FIELD_HIDDEN
|
|
634
|
+
}
|
|
635
|
+
);
|
|
476
636
|
var defaultSubscriptionResolve = (source) => source;
|
|
477
|
-
var
|
|
637
|
+
var subscription = (output, subscribeOrOptions) => {
|
|
478
638
|
const options = getSubscriptionOptions(subscribeOrOptions);
|
|
479
639
|
const type = "subscription";
|
|
480
640
|
return {
|
|
@@ -488,7 +648,7 @@ var silkSubscription = (output, subscribeOrOptions) => {
|
|
|
488
648
|
extraOptions?.middlewares,
|
|
489
649
|
options.middlewares
|
|
490
650
|
),
|
|
491
|
-
async () => options.subscribe(await parseInput()),
|
|
651
|
+
async () => options.subscribe(getStandardValue(await parseInput())),
|
|
492
652
|
{ parseInput, parent: void 0, outputSilk: output, type }
|
|
493
653
|
);
|
|
494
654
|
},
|
|
@@ -507,6 +667,7 @@ function baseResolver(operations, options) {
|
|
|
507
667
|
}
|
|
508
668
|
function extraOperationOptions(operation, options) {
|
|
509
669
|
const composeMiddlewares = (extraOptions) => compose(extraOptions?.middlewares, options?.middlewares);
|
|
670
|
+
if (typeof operation === "symbol") return operation;
|
|
510
671
|
switch (operation.type) {
|
|
511
672
|
case "field":
|
|
512
673
|
return {
|
|
@@ -534,7 +695,7 @@ function extraOperationOptions(operation, options) {
|
|
|
534
695
|
};
|
|
535
696
|
}
|
|
536
697
|
}
|
|
537
|
-
var
|
|
698
|
+
var resolver = Object.assign(
|
|
538
699
|
baseResolver,
|
|
539
700
|
{
|
|
540
701
|
of: (parent, operations, options) => baseResolver(
|
|
@@ -544,11 +705,11 @@ var silkResolver = Object.assign(
|
|
|
544
705
|
}
|
|
545
706
|
);
|
|
546
707
|
var loom = {
|
|
547
|
-
query
|
|
548
|
-
resolver
|
|
549
|
-
field
|
|
550
|
-
subscription
|
|
551
|
-
mutation
|
|
708
|
+
query,
|
|
709
|
+
resolver,
|
|
710
|
+
field,
|
|
711
|
+
subscription,
|
|
712
|
+
mutation
|
|
552
713
|
};
|
|
553
714
|
|
|
554
715
|
// src/helper/create-loom.ts
|
|
@@ -565,7 +726,7 @@ function toSilkInput(schema, toSilk, isSchema) {
|
|
|
565
726
|
}
|
|
566
727
|
return record;
|
|
567
728
|
}
|
|
568
|
-
function
|
|
729
|
+
function createResolverFactory(toSilk) {
|
|
569
730
|
return Object.assign(baseResolver, {
|
|
570
731
|
of: (parent, operations, options) => baseResolver(
|
|
571
732
|
operations,
|
|
@@ -573,39 +734,42 @@ function createResolverBobbin(toSilk) {
|
|
|
573
734
|
)
|
|
574
735
|
});
|
|
575
736
|
}
|
|
576
|
-
function
|
|
577
|
-
|
|
737
|
+
function createFieldFactory(toSilk, isSchema) {
|
|
738
|
+
const baseFieldFunc = (output, resolveOrOptions) => {
|
|
578
739
|
const options = getOperationOptions(
|
|
579
740
|
resolveOrOptions
|
|
580
741
|
);
|
|
581
|
-
return
|
|
742
|
+
return field(toSilk(output), {
|
|
582
743
|
...options,
|
|
583
744
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
584
745
|
});
|
|
585
746
|
};
|
|
747
|
+
return Object.assign(baseFieldFunc, {
|
|
748
|
+
hidden: FIELD_HIDDEN
|
|
749
|
+
});
|
|
586
750
|
}
|
|
587
|
-
function
|
|
751
|
+
function createQueryFactory(toSilk, isSchema) {
|
|
588
752
|
return (output, resolveOrOptions) => {
|
|
589
753
|
const options = getOperationOptions(resolveOrOptions);
|
|
590
|
-
return
|
|
754
|
+
return query(toSilk(output), {
|
|
591
755
|
...options,
|
|
592
756
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
593
757
|
});
|
|
594
758
|
};
|
|
595
759
|
}
|
|
596
|
-
function
|
|
760
|
+
function createMutationFactory(toSilk, isSchema) {
|
|
597
761
|
return (output, resolveOrOptions) => {
|
|
598
762
|
const options = getOperationOptions(resolveOrOptions);
|
|
599
|
-
return
|
|
763
|
+
return mutation(toSilk(output), {
|
|
600
764
|
...options,
|
|
601
765
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
602
766
|
});
|
|
603
767
|
};
|
|
604
768
|
}
|
|
605
|
-
function
|
|
769
|
+
function createSubscriptionFactory(toSilk, isSchema) {
|
|
606
770
|
return (output, resolveOrOptions) => {
|
|
607
771
|
const options = getSubscriptionOptions(resolveOrOptions);
|
|
608
|
-
return
|
|
772
|
+
return subscription(toSilk(output), {
|
|
609
773
|
...options,
|
|
610
774
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
611
775
|
});
|
|
@@ -613,131 +777,25 @@ function createSubscriptionBobbin(toSilk, isSchema) {
|
|
|
613
777
|
}
|
|
614
778
|
function createLoom(toSilk, isSchema) {
|
|
615
779
|
return {
|
|
616
|
-
query:
|
|
617
|
-
mutation:
|
|
618
|
-
field:
|
|
619
|
-
resolver:
|
|
620
|
-
subscription:
|
|
780
|
+
query: createQueryFactory(toSilk, isSchema),
|
|
781
|
+
mutation: createMutationFactory(toSilk, isSchema),
|
|
782
|
+
field: createFieldFactory(toSilk, isSchema),
|
|
783
|
+
resolver: createResolverFactory(toSilk),
|
|
784
|
+
subscription: createSubscriptionFactory(toSilk, isSchema)
|
|
621
785
|
};
|
|
622
786
|
}
|
|
623
787
|
|
|
624
788
|
// src/schema/object.ts
|
|
625
|
-
var
|
|
626
|
-
|
|
627
|
-
// src/schema/weaver-context.ts
|
|
628
|
-
var import_graphql2 = require("graphql");
|
|
629
|
-
var ref;
|
|
630
|
-
var names = /* @__PURE__ */ new WeakMap();
|
|
631
|
-
function initWeaverContext() {
|
|
632
|
-
return {
|
|
633
|
-
loomObjectMap: /* @__PURE__ */ new Map(),
|
|
634
|
-
loomUnionMap: /* @__PURE__ */ new Map(),
|
|
635
|
-
inputMap: /* @__PURE__ */ new Map(),
|
|
636
|
-
interfaceMap: /* @__PURE__ */ new Map(),
|
|
637
|
-
configs: /* @__PURE__ */ new Map(),
|
|
638
|
-
getConfig(key) {
|
|
639
|
-
return this.configs.get(key);
|
|
640
|
-
},
|
|
641
|
-
setConfig(config) {
|
|
642
|
-
const key = config[WEAVER_CONFIG];
|
|
643
|
-
this.configs.set(key, config);
|
|
644
|
-
},
|
|
645
|
-
deleteConfig(key) {
|
|
646
|
-
this.configs.delete(key);
|
|
647
|
-
},
|
|
648
|
-
names,
|
|
649
|
-
namedTypes: /* @__PURE__ */ new Map(),
|
|
650
|
-
memoNamedType(gqlTypeValue) {
|
|
651
|
-
const gqlType = gqlTypeValue;
|
|
652
|
-
if ((0, import_graphql2.isObjectType)(gqlType) || (0, import_graphql2.isUnionType)(gqlType) || (0, import_graphql2.isEnumType)(gqlType)) {
|
|
653
|
-
this.namedTypes.set(gqlType.name, gqlType);
|
|
654
|
-
}
|
|
655
|
-
return gqlTypeValue;
|
|
656
|
-
},
|
|
657
|
-
getNamedType(name) {
|
|
658
|
-
return this.namedTypes.get(name);
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
var weaverContext = {
|
|
663
|
-
get loomObjectMap() {
|
|
664
|
-
return ref?.loomObjectMap;
|
|
665
|
-
},
|
|
666
|
-
get loomUnionMap() {
|
|
667
|
-
return ref?.loomUnionMap;
|
|
668
|
-
},
|
|
669
|
-
get inputMap() {
|
|
670
|
-
return ref?.inputMap;
|
|
671
|
-
},
|
|
672
|
-
get interfaceMap() {
|
|
673
|
-
return ref?.interfaceMap;
|
|
674
|
-
},
|
|
675
|
-
get configs() {
|
|
676
|
-
return ref?.configs;
|
|
677
|
-
},
|
|
678
|
-
getConfig(key) {
|
|
679
|
-
return ref?.getConfig(key);
|
|
680
|
-
},
|
|
681
|
-
setConfig(config) {
|
|
682
|
-
ref?.setConfig(config);
|
|
683
|
-
},
|
|
684
|
-
deleteConfig(key) {
|
|
685
|
-
ref?.deleteConfig(key);
|
|
686
|
-
},
|
|
687
|
-
get value() {
|
|
688
|
-
return ref;
|
|
689
|
-
},
|
|
690
|
-
useConfig(config, callback) {
|
|
691
|
-
const context = weaverContext.value ?? initWeaverContext();
|
|
692
|
-
context.setConfig(config);
|
|
693
|
-
const result = provideWeaverContext(callback, context);
|
|
694
|
-
context.deleteConfig(config[WEAVER_CONFIG]);
|
|
695
|
-
return result;
|
|
696
|
-
},
|
|
697
|
-
names,
|
|
698
|
-
getNamedType(name) {
|
|
699
|
-
return ref?.getNamedType(name);
|
|
700
|
-
},
|
|
701
|
-
memoNamedType(gqlType) {
|
|
702
|
-
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
703
|
-
},
|
|
704
|
-
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
705
|
-
getGraphQLType(origin) {
|
|
706
|
-
return this.GraphQLTypes.get(origin);
|
|
707
|
-
},
|
|
708
|
-
memoGraphQLType(origin, gqlType) {
|
|
709
|
-
this.GraphQLTypes.set(origin, gqlType);
|
|
710
|
-
return gqlType;
|
|
711
|
-
}
|
|
712
|
-
};
|
|
713
|
-
function provideWeaverContext(func, value) {
|
|
714
|
-
const lastRef = ref;
|
|
715
|
-
ref = value;
|
|
716
|
-
try {
|
|
717
|
-
return func();
|
|
718
|
-
} finally {
|
|
719
|
-
ref = lastRef;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
function collectNames(...namesList) {
|
|
723
|
-
const namesRecord = {};
|
|
724
|
-
for (const namesItem of namesList) {
|
|
725
|
-
for (const [name, schema] of Object.entries(namesItem)) {
|
|
726
|
-
names.set(schema, name);
|
|
727
|
-
namesRecord[name] = schema;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
return namesRecord;
|
|
731
|
-
}
|
|
789
|
+
var import_graphql5 = require("graphql");
|
|
732
790
|
|
|
733
791
|
// src/schema/input.ts
|
|
734
|
-
var
|
|
792
|
+
var import_graphql4 = require("graphql");
|
|
735
793
|
function inputToArgs(input) {
|
|
736
794
|
if (input === void 0) return void 0;
|
|
737
795
|
if (isSilk(input)) {
|
|
738
796
|
let inputType = getGraphQLType(input);
|
|
739
|
-
if ((0,
|
|
740
|
-
if ((0,
|
|
797
|
+
if ((0, import_graphql4.isNonNullType)(inputType)) inputType = inputType.ofType;
|
|
798
|
+
if ((0, import_graphql4.isObjectType)(inputType)) {
|
|
741
799
|
return mapValue(
|
|
742
800
|
inputType.toConfig().fields,
|
|
743
801
|
(it) => toInputFieldConfig(it)
|
|
@@ -746,11 +804,11 @@ function inputToArgs(input) {
|
|
|
746
804
|
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
747
805
|
}
|
|
748
806
|
const args = {};
|
|
749
|
-
Object.entries(input).forEach(([name,
|
|
807
|
+
Object.entries(input).forEach(([name, field2]) => {
|
|
750
808
|
tryIn(() => {
|
|
751
809
|
args[name] = {
|
|
752
|
-
...
|
|
753
|
-
type: ensureInputType(
|
|
810
|
+
...field2,
|
|
811
|
+
type: ensureInputType(field2)
|
|
754
812
|
};
|
|
755
813
|
}, name);
|
|
756
814
|
});
|
|
@@ -763,20 +821,20 @@ function ensureInputType(silkOrType) {
|
|
|
763
821
|
}
|
|
764
822
|
return silkOrType;
|
|
765
823
|
})();
|
|
766
|
-
if ((0,
|
|
824
|
+
if ((0, import_graphql4.isUnionType)(gqlType))
|
|
767
825
|
throw new Error(`Cannot convert union type ${gqlType.name} to input type`);
|
|
768
|
-
if ((0,
|
|
769
|
-
return new
|
|
826
|
+
if ((0, import_graphql4.isNonNullType)(gqlType)) {
|
|
827
|
+
return new import_graphql4.GraphQLNonNull(ensureInputType(gqlType.ofType));
|
|
770
828
|
}
|
|
771
|
-
if ((0,
|
|
772
|
-
return new
|
|
829
|
+
if ((0, import_graphql4.isListType)(gqlType)) {
|
|
830
|
+
return new import_graphql4.GraphQLList(ensureInputType(gqlType.ofType));
|
|
773
831
|
}
|
|
774
|
-
if ((0,
|
|
832
|
+
if ((0, import_graphql4.isObjectType)(gqlType) || (0, import_graphql4.isInterfaceType)(gqlType))
|
|
775
833
|
return ensureInputObjectType(gqlType);
|
|
776
834
|
return gqlType;
|
|
777
835
|
}
|
|
778
836
|
function ensureInputObjectType(object) {
|
|
779
|
-
if ((0,
|
|
837
|
+
if ((0, import_graphql4.isInputObjectType)(object)) return object;
|
|
780
838
|
const existing = weaverContext.inputMap?.get(object);
|
|
781
839
|
if (existing != null) return existing;
|
|
782
840
|
const {
|
|
@@ -786,10 +844,12 @@ function ensureInputObjectType(object) {
|
|
|
786
844
|
...config
|
|
787
845
|
} = object.toConfig();
|
|
788
846
|
const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((name) => name);
|
|
789
|
-
const input = new
|
|
847
|
+
const input = new import_graphql4.GraphQLInputObjectType({
|
|
790
848
|
...config,
|
|
791
849
|
name: getInputObjectName(object.name),
|
|
792
|
-
fields:
|
|
850
|
+
fields: provideWeaverContext.inherit(
|
|
851
|
+
() => mapValue(fields, (it) => toInputFieldConfig(it))
|
|
852
|
+
)
|
|
793
853
|
});
|
|
794
854
|
weaverContext.inputMap?.set(object, input);
|
|
795
855
|
return input;
|
|
@@ -803,14 +863,15 @@ function toInputFieldConfig({
|
|
|
803
863
|
}
|
|
804
864
|
|
|
805
865
|
// src/schema/object.ts
|
|
806
|
-
var LoomObjectType = class extends
|
|
866
|
+
var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
|
|
807
867
|
extraFields = /* @__PURE__ */ new Map();
|
|
868
|
+
hiddenFields = /* @__PURE__ */ new Set();
|
|
808
869
|
weaverContext;
|
|
809
870
|
resolverOptions;
|
|
810
871
|
constructor(objectOrGetter, options = {}) {
|
|
811
872
|
const origin = typeof objectOrGetter === "function" ? objectOrGetter() : objectOrGetter;
|
|
812
873
|
const config = (() => {
|
|
813
|
-
if ((0,
|
|
874
|
+
if ((0, import_graphql5.isObjectType)(origin)) {
|
|
814
875
|
return origin.toConfig();
|
|
815
876
|
} else if (typeof origin === "string") {
|
|
816
877
|
return { name: origin, fields: {} };
|
|
@@ -822,77 +883,84 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
|
|
|
822
883
|
this.resolverOptions = options.resolverOptions;
|
|
823
884
|
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
824
885
|
}
|
|
825
|
-
|
|
886
|
+
hideField(name) {
|
|
887
|
+
this.hiddenFields.add(name);
|
|
888
|
+
}
|
|
889
|
+
addField(name, resolver2) {
|
|
826
890
|
const existing = this.extraFields.get(name);
|
|
827
|
-
if (existing && existing !==
|
|
891
|
+
if (existing && existing !== resolver2) {
|
|
828
892
|
throw new Error(`Field ${name} already exists in ${this.name}`);
|
|
829
893
|
}
|
|
830
|
-
this.extraFields.set(name,
|
|
894
|
+
this.extraFields.set(name, resolver2);
|
|
831
895
|
}
|
|
832
896
|
mergeExtensions(extensions) {
|
|
833
897
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
834
898
|
}
|
|
835
|
-
|
|
899
|
+
extraFieldMap;
|
|
836
900
|
getFields() {
|
|
837
|
-
const
|
|
838
|
-
Object.values(
|
|
839
|
-
(
|
|
901
|
+
const fieldsBySuper = super.getFields();
|
|
902
|
+
Object.values(fieldsBySuper).forEach(
|
|
903
|
+
(field2) => field2.type = this.getCacheType(field2.type)
|
|
840
904
|
);
|
|
841
|
-
const
|
|
905
|
+
const extraFields = provideWeaverContext(
|
|
842
906
|
() => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
|
|
843
907
|
this.weaverContext
|
|
844
908
|
);
|
|
845
|
-
if (Object.keys(this.
|
|
846
|
-
this.
|
|
909
|
+
if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) {
|
|
910
|
+
this.extraFieldMap = extraFields;
|
|
847
911
|
}
|
|
848
|
-
|
|
849
|
-
...
|
|
850
|
-
...this.
|
|
912
|
+
const answer = {
|
|
913
|
+
...fieldsBySuper,
|
|
914
|
+
...this.extraFieldMap
|
|
851
915
|
};
|
|
916
|
+
for (const fieldName of this.hiddenFields) {
|
|
917
|
+
delete answer[fieldName];
|
|
918
|
+
}
|
|
919
|
+
return answer;
|
|
852
920
|
}
|
|
853
921
|
mapToFieldConfig(map) {
|
|
854
922
|
const record = {};
|
|
855
|
-
for (const [name,
|
|
856
|
-
record[name] = this.toFieldConfig(
|
|
923
|
+
for (const [name, field2] of map.entries()) {
|
|
924
|
+
record[name] = this.toFieldConfig(field2);
|
|
857
925
|
}
|
|
858
926
|
return record;
|
|
859
927
|
}
|
|
860
|
-
toFieldConfig(
|
|
928
|
+
toFieldConfig(field2) {
|
|
861
929
|
try {
|
|
862
|
-
const outputType = this.getCacheType(getGraphQLType(
|
|
930
|
+
const outputType = this.getCacheType(getGraphQLType(field2.output));
|
|
863
931
|
return {
|
|
864
|
-
...extract(
|
|
932
|
+
...extract(field2),
|
|
865
933
|
type: outputType,
|
|
866
|
-
args: inputToArgs(
|
|
867
|
-
...this.provideForResolve(
|
|
868
|
-
...this.provideForSubscribe(
|
|
934
|
+
args: inputToArgs(field2.input),
|
|
935
|
+
...this.provideForResolve(field2),
|
|
936
|
+
...this.provideForSubscribe(field2)
|
|
869
937
|
};
|
|
870
938
|
} catch (error) {
|
|
871
939
|
throw markErrorLocation(error);
|
|
872
940
|
}
|
|
873
941
|
}
|
|
874
|
-
provideForResolve(
|
|
875
|
-
if (
|
|
876
|
-
if (
|
|
942
|
+
provideForResolve(field2) {
|
|
943
|
+
if (field2?.resolve == null) return;
|
|
944
|
+
if (field2.resolve === defaultSubscriptionResolve)
|
|
877
945
|
return { resolve: defaultSubscriptionResolve };
|
|
878
|
-
const resolve =
|
|
879
|
-
{ root, args, context, info, field },
|
|
880
|
-
() =>
|
|
881
|
-
) :
|
|
882
|
-
{ root, args, context, info, field },
|
|
883
|
-
() =>
|
|
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)
|
|
884
952
|
) : (root, args, context, info) => resolverPayloadStorage.run(
|
|
885
|
-
{ root, args, context, info, field },
|
|
886
|
-
() =>
|
|
953
|
+
{ root, args, context, info, field: field2 },
|
|
954
|
+
() => field2.resolve(args, this.resolverOptions)
|
|
887
955
|
);
|
|
888
956
|
return { resolve };
|
|
889
957
|
}
|
|
890
|
-
provideForSubscribe(
|
|
891
|
-
if (
|
|
958
|
+
provideForSubscribe(field2) {
|
|
959
|
+
if (field2?.subscribe == null) return;
|
|
892
960
|
return {
|
|
893
961
|
subscribe: (root, args, context, info) => resolverPayloadStorage.run(
|
|
894
|
-
{ root, args, context, info, field },
|
|
895
|
-
() =>
|
|
962
|
+
{ root, args, context, info, field: field2 },
|
|
963
|
+
() => field2.subscribe?.(args, this.resolverOptions)
|
|
896
964
|
)
|
|
897
965
|
};
|
|
898
966
|
}
|
|
@@ -916,11 +984,11 @@ function extract({
|
|
|
916
984
|
};
|
|
917
985
|
}
|
|
918
986
|
function defineFieldMap(fields) {
|
|
919
|
-
const fieldMap = (0,
|
|
987
|
+
const fieldMap = (0, import_graphql5.resolveObjMapThunk)(fields);
|
|
920
988
|
return mapValue(fieldMap, (fieldConfig, fieldName) => {
|
|
921
989
|
const argsConfig = fieldConfig.args ?? {};
|
|
922
990
|
return {
|
|
923
|
-
name: (0,
|
|
991
|
+
name: (0, import_graphql5.assertName)(fieldName),
|
|
924
992
|
description: fieldConfig.description,
|
|
925
993
|
type: fieldConfig.type,
|
|
926
994
|
args: defineArguments(argsConfig),
|
|
@@ -934,7 +1002,7 @@ function defineFieldMap(fields) {
|
|
|
934
1002
|
}
|
|
935
1003
|
function defineArguments(args) {
|
|
936
1004
|
return Object.entries(args).map(([argName, argConfig]) => ({
|
|
937
|
-
name: (0,
|
|
1005
|
+
name: (0, import_graphql5.assertName)(argName),
|
|
938
1006
|
description: argConfig.description,
|
|
939
1007
|
type: argConfig.type,
|
|
940
1008
|
defaultValue: argConfig.defaultValue,
|
|
@@ -946,21 +1014,21 @@ function defineArguments(args) {
|
|
|
946
1014
|
function getCacheType(gqlType, options = {}) {
|
|
947
1015
|
const context = options.weaverContext ?? weaverContext;
|
|
948
1016
|
if (gqlType instanceof LoomObjectType) return gqlType;
|
|
949
|
-
if ((0,
|
|
1017
|
+
if ((0, import_graphql5.isObjectType)(gqlType)) {
|
|
950
1018
|
const gqlObject = context.loomObjectMap?.get(gqlType);
|
|
951
1019
|
if (gqlObject != null) return gqlObject;
|
|
952
1020
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
953
1021
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
954
1022
|
return loomObject;
|
|
955
|
-
} else if ((0,
|
|
956
|
-
return new
|
|
957
|
-
} else if ((0,
|
|
958
|
-
return new
|
|
959
|
-
} 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)) {
|
|
960
1028
|
const existing = context.loomUnionMap?.get(gqlType);
|
|
961
1029
|
if (existing != null) return existing;
|
|
962
1030
|
const config = gqlType.toConfig();
|
|
963
|
-
const unionType = new
|
|
1031
|
+
const unionType = new import_graphql5.GraphQLUnionType({
|
|
964
1032
|
...config,
|
|
965
1033
|
types: config.types.map(
|
|
966
1034
|
(type) => getCacheType(type, options)
|
|
@@ -972,8 +1040,17 @@ function getCacheType(gqlType, options = {}) {
|
|
|
972
1040
|
return gqlType;
|
|
973
1041
|
}
|
|
974
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
|
+
|
|
975
1052
|
// src/schema/schema-weaver.ts
|
|
976
|
-
var
|
|
1053
|
+
var import_graphql6 = require("graphql");
|
|
977
1054
|
var SchemaWeaver = class _SchemaWeaver {
|
|
978
1055
|
query;
|
|
979
1056
|
mutation;
|
|
@@ -992,10 +1069,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
992
1069
|
[WEAVER_CONFIG]: "gqloom.core.schema"
|
|
993
1070
|
};
|
|
994
1071
|
}
|
|
995
|
-
constructor({ query, mutation, subscription, types } = {}, context) {
|
|
996
|
-
if (
|
|
997
|
-
if (
|
|
998
|
-
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;
|
|
999
1076
|
if (types != null) this.types = types.slice();
|
|
1000
1077
|
this.context = context ?? initWeaverContext();
|
|
1001
1078
|
}
|
|
@@ -1005,21 +1082,25 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1005
1082
|
this.resolverOptions.middlewares.push(...middlewares);
|
|
1006
1083
|
return this;
|
|
1007
1084
|
}
|
|
1008
|
-
add(
|
|
1009
|
-
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);
|
|
1010
1091
|
return this;
|
|
1011
1092
|
}
|
|
1012
1093
|
addType(silk2) {
|
|
1013
1094
|
const gqlType = provideWeaverContext(() => {
|
|
1014
1095
|
let gqlType2 = getGraphQLType(silk2);
|
|
1015
|
-
if ((0,
|
|
1016
|
-
if ((0,
|
|
1096
|
+
if ((0, import_graphql6.isNonNullType)(gqlType2)) gqlType2 = gqlType2.ofType;
|
|
1097
|
+
if ((0, import_graphql6.isObjectType)(gqlType2)) {
|
|
1017
1098
|
const existing = this.context.loomObjectMap.get(gqlType2);
|
|
1018
1099
|
if (existing != null) return existing;
|
|
1019
1100
|
const extraObject = new LoomObjectType(gqlType2, this.fieldOptions);
|
|
1020
1101
|
this.context.loomObjectMap.set(gqlType2, extraObject);
|
|
1021
1102
|
return extraObject;
|
|
1022
|
-
} else if ((0,
|
|
1103
|
+
} else if ((0, import_graphql6.isUnionType)(gqlType2) || (0, import_graphql6.isEnumType)(gqlType2)) {
|
|
1023
1104
|
return gqlType2;
|
|
1024
1105
|
}
|
|
1025
1106
|
throw new Error(
|
|
@@ -1035,25 +1116,25 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1035
1116
|
return this;
|
|
1036
1117
|
}
|
|
1037
1118
|
weaveGraphQLSchema() {
|
|
1038
|
-
const { query, mutation, subscription, types } = this;
|
|
1119
|
+
const { query: query2, mutation: mutation2, subscription: subscription2, types } = this;
|
|
1039
1120
|
const config = this.context.getConfig("gqloom.core.schema");
|
|
1040
|
-
const schema = new
|
|
1041
|
-
query,
|
|
1042
|
-
mutation,
|
|
1043
|
-
subscription,
|
|
1121
|
+
const schema = new import_graphql6.GraphQLSchema({
|
|
1122
|
+
query: query2,
|
|
1123
|
+
mutation: mutation2,
|
|
1124
|
+
subscription: subscription2,
|
|
1044
1125
|
types: [...types ?? [], ...config?.types ?? []],
|
|
1045
1126
|
...config
|
|
1046
1127
|
});
|
|
1047
1128
|
return schema;
|
|
1048
1129
|
}
|
|
1049
|
-
addResolver(
|
|
1050
|
-
const resolverOptions = ResolverOptionsMap.get(
|
|
1130
|
+
addResolver(resolver2) {
|
|
1131
|
+
const resolverOptions = ResolverOptionsMap.get(resolver2);
|
|
1051
1132
|
const parent = resolverOptions?.parent;
|
|
1052
1133
|
const parentObject = (() => {
|
|
1053
1134
|
if (parent == null) return void 0;
|
|
1054
1135
|
let gqlType = getGraphQLType(parent);
|
|
1055
|
-
if ((0,
|
|
1056
|
-
if ((0,
|
|
1136
|
+
if ((0, import_graphql6.isNonNullType)(gqlType)) gqlType = gqlType.ofType;
|
|
1137
|
+
if ((0, import_graphql6.isObjectType)(gqlType)) {
|
|
1057
1138
|
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1058
1139
|
if (existing != null) return existing;
|
|
1059
1140
|
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
@@ -1066,8 +1147,11 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1066
1147
|
})();
|
|
1067
1148
|
if (resolverOptions?.extensions && parentObject)
|
|
1068
1149
|
parentObject.mergeExtensions(resolverOptions.extensions);
|
|
1069
|
-
Object.entries(
|
|
1070
|
-
if (operation
|
|
1150
|
+
Object.entries(resolver2).forEach(([name, operation]) => {
|
|
1151
|
+
if (operation === FIELD_HIDDEN) {
|
|
1152
|
+
if (parentObject == null) return;
|
|
1153
|
+
parentObject.hideField(name);
|
|
1154
|
+
} else if (operation.type === "field") {
|
|
1071
1155
|
if (parentObject == null) return;
|
|
1072
1156
|
parentObject.addField(name, operation);
|
|
1073
1157
|
} else {
|
|
@@ -1111,12 +1195,16 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1111
1195
|
const middlewares = /* @__PURE__ */ new Set();
|
|
1112
1196
|
const resolvers = /* @__PURE__ */ new Set();
|
|
1113
1197
|
const silks = /* @__PURE__ */ new Set();
|
|
1198
|
+
const weavers = /* @__PURE__ */ new Set();
|
|
1114
1199
|
let context;
|
|
1115
1200
|
for (const item of inputs) {
|
|
1116
|
-
if (
|
|
1201
|
+
if (isSchemaVendorWeaver(item)) {
|
|
1202
|
+
weavers.add(item);
|
|
1203
|
+
} else if (typeof item === "function") {
|
|
1117
1204
|
middlewares.add(item);
|
|
1118
1205
|
} else if (WEAVER_CONFIG in item) {
|
|
1119
1206
|
configs.add(item);
|
|
1207
|
+
if (item.vendorWeaver) weavers.add(item.vendorWeaver);
|
|
1120
1208
|
if (item[WEAVER_CONFIG] === "gqloom.core.schema") {
|
|
1121
1209
|
context = item.weaverContext;
|
|
1122
1210
|
}
|
|
@@ -1126,7 +1214,7 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1126
1214
|
resolvers.add(item);
|
|
1127
1215
|
}
|
|
1128
1216
|
}
|
|
1129
|
-
return { context, configs, middlewares, resolvers, silks };
|
|
1217
|
+
return { context, configs, middlewares, resolvers, silks, weavers };
|
|
1130
1218
|
}
|
|
1131
1219
|
/**
|
|
1132
1220
|
* Weave a GraphQL Schema from resolvers
|
|
@@ -1134,9 +1222,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1134
1222
|
* @returns GraphQ LSchema
|
|
1135
1223
|
*/
|
|
1136
1224
|
static weave(...inputs) {
|
|
1137
|
-
const { context, configs, middlewares, resolvers, silks } = _SchemaWeaver.optionsFrom(...inputs);
|
|
1225
|
+
const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
|
|
1138
1226
|
const weaver = new _SchemaWeaver({}, context);
|
|
1139
1227
|
configs.forEach((it) => weaver.setConfig(it));
|
|
1228
|
+
weavers.forEach((it) => weaver.addVendor(it));
|
|
1140
1229
|
middlewares.forEach((it) => weaver.use(it));
|
|
1141
1230
|
resolvers.forEach((it) => weaver.add(it));
|
|
1142
1231
|
silks.forEach((it) => weaver.addType(it));
|
|
@@ -1146,10 +1235,10 @@ var SchemaWeaver = class _SchemaWeaver {
|
|
|
1146
1235
|
var weave = SchemaWeaver.weave;
|
|
1147
1236
|
|
|
1148
1237
|
// src/schema/interface.ts
|
|
1149
|
-
var
|
|
1238
|
+
var import_graphql7 = require("graphql");
|
|
1150
1239
|
function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
1151
|
-
if ((0,
|
|
1152
|
-
if (!(0,
|
|
1240
|
+
if ((0, import_graphql7.isInterfaceType)(gqlType)) return gqlType;
|
|
1241
|
+
if (!(0, import_graphql7.isObjectType)(gqlType))
|
|
1153
1242
|
throw new Error(`${gqlType.toString()} is not an object`);
|
|
1154
1243
|
const key = gqlType;
|
|
1155
1244
|
const existing = weaverContext.interfaceMap?.get(key);
|
|
@@ -1160,21 +1249,16 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1160
1249
|
fields,
|
|
1161
1250
|
...config
|
|
1162
1251
|
} = gqlType.toConfig();
|
|
1163
|
-
const interfaceType = new
|
|
1252
|
+
const interfaceType = new import_graphql7.GraphQLInterfaceType({
|
|
1164
1253
|
...config,
|
|
1165
1254
|
...interfaceConfig,
|
|
1166
|
-
fields: mapValue(fields, (
|
|
1167
|
-
return { ...
|
|
1255
|
+
fields: mapValue(fields, (field2) => {
|
|
1256
|
+
return { ...field2, type: getCacheType(field2.type) };
|
|
1168
1257
|
})
|
|
1169
1258
|
});
|
|
1170
1259
|
weaverContext.interfaceMap?.set(key, interfaceType);
|
|
1171
1260
|
return interfaceType;
|
|
1172
1261
|
}
|
|
1173
|
-
|
|
1174
|
-
// src/schema/extensions.ts
|
|
1175
|
-
function mergeExtensions(...extensionsList) {
|
|
1176
|
-
return deepMerge(...extensionsList);
|
|
1177
|
-
}
|
|
1178
1262
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1179
1263
|
0 && (module.exports = {
|
|
1180
1264
|
ContextMemoization,
|
|
@@ -1184,36 +1268,40 @@ function mergeExtensions(...extensionsList) {
|
|
|
1184
1268
|
SchemaWeaver,
|
|
1185
1269
|
applyMiddlewares,
|
|
1186
1270
|
baseResolver,
|
|
1271
|
+
collectName,
|
|
1187
1272
|
collectNames,
|
|
1188
1273
|
compose,
|
|
1189
|
-
|
|
1274
|
+
createFieldFactory,
|
|
1190
1275
|
createInputParser,
|
|
1191
1276
|
createLoom,
|
|
1192
1277
|
createMemoization,
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1278
|
+
createMutationFactory,
|
|
1279
|
+
createQueryFactory,
|
|
1280
|
+
createResolverFactory,
|
|
1281
|
+
createSubscriptionFactory,
|
|
1197
1282
|
deepMerge,
|
|
1198
1283
|
defaultSubscriptionResolve,
|
|
1199
1284
|
ensureInputObjectType,
|
|
1200
1285
|
ensureInputType,
|
|
1201
1286
|
ensureInterfaceType,
|
|
1287
|
+
field,
|
|
1202
1288
|
getCacheType,
|
|
1203
1289
|
getFieldOptions,
|
|
1204
1290
|
getGraphQLType,
|
|
1205
1291
|
getOperationOptions,
|
|
1292
|
+
getStandardValue,
|
|
1206
1293
|
getSubscriptionOptions,
|
|
1207
1294
|
initWeaverContext,
|
|
1208
1295
|
inputToArgs,
|
|
1209
1296
|
isOnlyMemoryPayload,
|
|
1297
|
+
isSchemaVendorWeaver,
|
|
1210
1298
|
isSilk,
|
|
1211
1299
|
listSilk,
|
|
1212
1300
|
loom,
|
|
1213
1301
|
mapValue,
|
|
1214
1302
|
markErrorLocation,
|
|
1215
1303
|
markLocation,
|
|
1216
|
-
|
|
1304
|
+
mutation,
|
|
1217
1305
|
nonNullSilk,
|
|
1218
1306
|
notNullish,
|
|
1219
1307
|
nullableSilk,
|
|
@@ -1221,13 +1309,11 @@ function mergeExtensions(...extensionsList) {
|
|
|
1221
1309
|
parseInputValue,
|
|
1222
1310
|
parseSilk,
|
|
1223
1311
|
provideWeaverContext,
|
|
1312
|
+
query,
|
|
1313
|
+
resolver,
|
|
1224
1314
|
resolverPayloadStorage,
|
|
1225
1315
|
silk,
|
|
1226
|
-
|
|
1227
|
-
silkMutation,
|
|
1228
|
-
silkQuery,
|
|
1229
|
-
silkResolver,
|
|
1230
|
-
silkSubscription,
|
|
1316
|
+
subscription,
|
|
1231
1317
|
toObjMap,
|
|
1232
1318
|
tryIn,
|
|
1233
1319
|
useContext,
|