@gqloom/core 0.11.1 → 0.12.1
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/{context-BtR7FTYT.js → context-BxqO4Eg9.js} +2 -1
- package/dist/{context-CnY_BFnk.cjs → context-DshDoxiE.cjs} +7 -0
- package/dist/context.cjs +1 -1
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -1
- package/dist/{index-t3pO8DK2.d.ts → index-BxqR3YsC.d.cts} +62 -30
- package/dist/{index-DXUAbzqx.d.cts → index-sGKC4BRu.d.ts} +60 -32
- package/dist/index.cjs +191 -120
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +188 -121
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DERIVED_DEPENDENCIES, FIELD_HIDDEN, GET_GRAPHQL_TYPE, IS_RESOLVER, WEAVER_CONFIG, assignContextMap, getDeepResolvingFields, getMemoizationMap, getResolvingFields, isOnlyMemoryPayload, onlyMemoization, parseResolvingFields, symbols_exports } from "./context-
|
|
1
|
+
import { AUTO_ALIASING, DERIVED_DEPENDENCIES, FIELD_HIDDEN, GET_GRAPHQL_TYPE, IS_RESOLVER, WEAVER_CONFIG, assignContextMap, getDeepResolvingFields, getMemoizationMap, getResolvingFields, isOnlyMemoryPayload, onlyMemoization, parseResolvingFields, symbols_exports } from "./context-BxqO4Eg9.js";
|
|
2
2
|
import { GraphQLError, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLUnionType, assertName, isEnumType, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, resolveObjMapThunk } from "graphql";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/args.ts
|
|
@@ -239,110 +239,176 @@ var EasyDataLoader = class extends LoomDataLoader {
|
|
|
239
239
|
|
|
240
240
|
//#endregion
|
|
241
241
|
//#region src/schema/weaver-context.ts
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
242
|
+
var WeaverContext = class WeaverContext {
|
|
243
|
+
static increasingID = 1;
|
|
244
|
+
static names = /* @__PURE__ */ new WeakMap();
|
|
245
|
+
static autoAliasTypes = /* @__PURE__ */ new WeakSet();
|
|
246
|
+
static _ref;
|
|
247
|
+
static get ref() {
|
|
248
|
+
return WeaverContext._ref;
|
|
249
|
+
}
|
|
250
|
+
id;
|
|
251
|
+
loomObjectMap;
|
|
252
|
+
loomUnionMap;
|
|
253
|
+
inputMap;
|
|
254
|
+
interfaceMap;
|
|
255
|
+
configs;
|
|
256
|
+
namedTypes;
|
|
257
|
+
vendorWeavers;
|
|
258
|
+
constructor() {
|
|
259
|
+
this.id = WeaverContext.increasingID++;
|
|
260
|
+
this.loomObjectMap = /* @__PURE__ */ new Map();
|
|
261
|
+
this.loomUnionMap = /* @__PURE__ */ new Map();
|
|
262
|
+
this.inputMap = /* @__PURE__ */ new Map();
|
|
263
|
+
this.interfaceMap = /* @__PURE__ */ new Map();
|
|
264
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
265
|
+
this.namedTypes = /* @__PURE__ */ new Map();
|
|
266
|
+
this.vendorWeavers = /* @__PURE__ */ new Map();
|
|
267
|
+
}
|
|
268
|
+
getConfig(key) {
|
|
269
|
+
return this.configs.get(key);
|
|
270
|
+
}
|
|
271
|
+
setConfig(config) {
|
|
272
|
+
const key = config[WEAVER_CONFIG];
|
|
273
|
+
this.configs.set(key, config);
|
|
274
|
+
}
|
|
275
|
+
deleteConfig(key) {
|
|
276
|
+
this.configs.delete(key);
|
|
277
|
+
}
|
|
278
|
+
memoNamedType(gqlTypeValue) {
|
|
279
|
+
const gqlType = gqlTypeValue;
|
|
280
|
+
if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType) || isScalarType(gqlType)) this.namedTypes.set(gqlType.name, gqlType);
|
|
281
|
+
return gqlTypeValue;
|
|
282
|
+
}
|
|
283
|
+
getNamedType(name) {
|
|
284
|
+
return this.namedTypes.get(name);
|
|
285
|
+
}
|
|
286
|
+
static namedTypes = {
|
|
287
|
+
Object: "Object",
|
|
288
|
+
Union: "Union",
|
|
289
|
+
Enum: "Enum",
|
|
290
|
+
Interface: "Interface",
|
|
291
|
+
Scalar: "Scalar"
|
|
273
292
|
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
293
|
+
aliasCounters = {};
|
|
294
|
+
setAlias(namedType, alias) {
|
|
295
|
+
if (namedType.name === AUTO_ALIASING) WeaverContext.autoAliasTypes.add(namedType);
|
|
296
|
+
if (!WeaverContext.autoAliasTypes.has(namedType)) return namedType.name;
|
|
297
|
+
if (WeaverContext.higherPriorityThan(alias, namedType.name) < 0) {
|
|
298
|
+
if (alias) return namedType.name = alias;
|
|
299
|
+
}
|
|
300
|
+
if (namedType.name === AUTO_ALIASING) {
|
|
301
|
+
if (isObjectType(namedType) || isInputObjectType(namedType)) {
|
|
302
|
+
this.aliasCounters["Object"] ??= 0;
|
|
303
|
+
return namedType.name = `Object${++this.aliasCounters["Object"]}`;
|
|
304
|
+
} else if (isUnionType(namedType)) {
|
|
305
|
+
this.aliasCounters["Union"] ??= 0;
|
|
306
|
+
return namedType.name = `Union${++this.aliasCounters["Union"]}`;
|
|
307
|
+
} else if (isEnumType(namedType)) {
|
|
308
|
+
this.aliasCounters["Enum"] ??= 0;
|
|
309
|
+
return namedType.name = `Enum${++this.aliasCounters["Enum"]}`;
|
|
310
|
+
} else if (isInterfaceType(namedType)) {
|
|
311
|
+
this.aliasCounters["Interface"] ??= 0;
|
|
312
|
+
return namedType.name = `Interface${++this.aliasCounters["Interface"]}`;
|
|
313
|
+
} else if (isScalarType(namedType)) {
|
|
314
|
+
this.aliasCounters["Scalar"] ??= 0;
|
|
315
|
+
return namedType.name = `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
321
|
+
*/
|
|
322
|
+
static higherPriorityThan(a, b) {
|
|
323
|
+
if (a === AUTO_ALIASING || a === void 0) return 1;
|
|
324
|
+
else if (b === AUTO_ALIASING || b === void 0) return -1;
|
|
325
|
+
const compareLength = a.length - b.length;
|
|
326
|
+
if (compareLength !== 0) return compareLength;
|
|
327
|
+
const compareLocale = a.localeCompare(b);
|
|
328
|
+
if (compareLocale !== 0) return compareLocale;
|
|
329
|
+
return 0;
|
|
330
|
+
}
|
|
331
|
+
static provide(func, value) {
|
|
332
|
+
const lastRef = WeaverContext._ref;
|
|
333
|
+
WeaverContext._ref = value;
|
|
334
|
+
try {
|
|
335
|
+
return func();
|
|
336
|
+
} finally {
|
|
337
|
+
WeaverContext._ref = lastRef;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const initWeaverContext = () => new WeaverContext();
|
|
342
|
+
const provideWeaverContext = Object.assign(WeaverContext.provide, { inherit: (func) => {
|
|
343
|
+
const weaverContextRef = WeaverContext.ref;
|
|
344
|
+
return () => WeaverContext.provide(func, weaverContextRef);
|
|
345
|
+
} });
|
|
346
|
+
var GlobalWeaverContext = class {
|
|
347
|
+
GraphQLTypes = /* @__PURE__ */ new WeakMap();
|
|
277
348
|
get id() {
|
|
278
|
-
return ref?.id;
|
|
279
|
-
}
|
|
349
|
+
return WeaverContext.ref?.id;
|
|
350
|
+
}
|
|
280
351
|
get loomObjectMap() {
|
|
281
|
-
return ref?.loomObjectMap;
|
|
282
|
-
}
|
|
352
|
+
return WeaverContext.ref?.loomObjectMap;
|
|
353
|
+
}
|
|
283
354
|
get loomUnionMap() {
|
|
284
|
-
return ref?.loomUnionMap;
|
|
285
|
-
}
|
|
355
|
+
return WeaverContext.ref?.loomUnionMap;
|
|
356
|
+
}
|
|
286
357
|
get inputMap() {
|
|
287
|
-
return ref?.inputMap;
|
|
288
|
-
}
|
|
358
|
+
return WeaverContext.ref?.inputMap;
|
|
359
|
+
}
|
|
289
360
|
get interfaceMap() {
|
|
290
|
-
return ref?.interfaceMap;
|
|
291
|
-
}
|
|
361
|
+
return WeaverContext.ref?.interfaceMap;
|
|
362
|
+
}
|
|
292
363
|
get configs() {
|
|
293
|
-
return ref?.configs;
|
|
294
|
-
}
|
|
364
|
+
return WeaverContext.ref?.configs;
|
|
365
|
+
}
|
|
295
366
|
get vendorWeavers() {
|
|
296
|
-
return ref?.vendorWeavers;
|
|
297
|
-
}
|
|
367
|
+
return WeaverContext.ref?.vendorWeavers;
|
|
368
|
+
}
|
|
369
|
+
get names() {
|
|
370
|
+
return WeaverContext.names;
|
|
371
|
+
}
|
|
372
|
+
get autoAliasTypes() {
|
|
373
|
+
return WeaverContext.autoAliasTypes;
|
|
374
|
+
}
|
|
375
|
+
get value() {
|
|
376
|
+
return WeaverContext.ref;
|
|
377
|
+
}
|
|
298
378
|
getConfig(key) {
|
|
299
|
-
return ref?.getConfig(key);
|
|
300
|
-
}
|
|
379
|
+
return WeaverContext.ref?.getConfig(key);
|
|
380
|
+
}
|
|
301
381
|
setConfig(config) {
|
|
302
|
-
ref?.setConfig(config);
|
|
303
|
-
}
|
|
382
|
+
WeaverContext.ref?.setConfig(config);
|
|
383
|
+
}
|
|
304
384
|
deleteConfig(key) {
|
|
305
|
-
ref?.deleteConfig(key);
|
|
306
|
-
}
|
|
307
|
-
get value() {
|
|
308
|
-
return ref;
|
|
309
|
-
},
|
|
385
|
+
WeaverContext.ref?.deleteConfig(key);
|
|
386
|
+
}
|
|
310
387
|
useConfig(config, callback) {
|
|
311
|
-
const context =
|
|
388
|
+
const context = this.value ?? initWeaverContext();
|
|
312
389
|
context.setConfig(config);
|
|
313
390
|
const result = provideWeaverContext(callback, context);
|
|
314
391
|
context.deleteConfig(config[WEAVER_CONFIG]);
|
|
315
392
|
return result;
|
|
316
|
-
}
|
|
317
|
-
names,
|
|
393
|
+
}
|
|
318
394
|
getNamedType(name) {
|
|
319
|
-
return ref?.getNamedType(name);
|
|
320
|
-
}
|
|
395
|
+
return WeaverContext.ref?.getNamedType(name);
|
|
396
|
+
}
|
|
321
397
|
memoNamedType(gqlType) {
|
|
322
|
-
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
323
|
-
}
|
|
324
|
-
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
398
|
+
return WeaverContext.ref?.memoNamedType(gqlType) ?? gqlType;
|
|
399
|
+
}
|
|
325
400
|
getGraphQLType(origin) {
|
|
326
401
|
return this.GraphQLTypes.get(origin);
|
|
327
|
-
}
|
|
402
|
+
}
|
|
328
403
|
memoGraphQLType(origin, gqlType) {
|
|
329
404
|
this.GraphQLTypes.set(origin, gqlType);
|
|
330
405
|
return gqlType;
|
|
331
406
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const lastRef = ref;
|
|
335
|
-
ref = value;
|
|
336
|
-
try {
|
|
337
|
-
return func();
|
|
338
|
-
} finally {
|
|
339
|
-
ref = lastRef;
|
|
407
|
+
setAlias(namedType, alias) {
|
|
408
|
+
return WeaverContext.ref?.setAlias(namedType, alias);
|
|
340
409
|
}
|
|
341
|
-
}
|
|
342
|
-
provideWeaverContext.inherit = (func) => {
|
|
343
|
-
const weaverContextRef = weaverContext.value;
|
|
344
|
-
return () => provideWeaverContext(func, weaverContextRef);
|
|
345
410
|
};
|
|
411
|
+
const weaverContext = new GlobalWeaverContext();
|
|
346
412
|
/**
|
|
347
413
|
* collect names for schemas
|
|
348
414
|
* @param namesList - names to collect
|
|
@@ -351,7 +417,7 @@ provideWeaverContext.inherit = (func) => {
|
|
|
351
417
|
function collectNames(...namesList) {
|
|
352
418
|
const namesRecord = {};
|
|
353
419
|
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
354
|
-
names.set(schema, name);
|
|
420
|
+
WeaverContext.names.set(schema, name);
|
|
355
421
|
namesRecord[name] = schema;
|
|
356
422
|
}
|
|
357
423
|
return namesRecord;
|
|
@@ -363,7 +429,7 @@ function collectNames(...namesList) {
|
|
|
363
429
|
* @returns schema
|
|
364
430
|
*/
|
|
365
431
|
function collectName(name, schema) {
|
|
366
|
-
names.set(schema, name);
|
|
432
|
+
WeaverContext.names.set(schema, name);
|
|
367
433
|
return schema;
|
|
368
434
|
}
|
|
369
435
|
|
|
@@ -1210,8 +1276,7 @@ function inputToArgs(input, options) {
|
|
|
1210
1276
|
let inputType = getGraphQLType(input);
|
|
1211
1277
|
if (isNonNullType(inputType)) inputType = inputType.ofType;
|
|
1212
1278
|
if (isObjectType(inputType)) return mapValue(inputType.toConfig().fields, (it, key) => {
|
|
1213
|
-
|
|
1214
|
-
if (options?.fieldName) fieldName = `${pascalCase(options.fieldName)}${pascalCase(key)}`;
|
|
1279
|
+
const fieldName = `${pascalCase(options.fieldName)}${pascalCase(key)}`;
|
|
1215
1280
|
return toInputFieldConfig(it, { fieldName });
|
|
1216
1281
|
});
|
|
1217
1282
|
throw new Error(`Cannot convert ${inputType.toString()} to input type`);
|
|
@@ -1219,8 +1284,7 @@ function inputToArgs(input, options) {
|
|
|
1219
1284
|
const args = {};
|
|
1220
1285
|
Object.entries(input).forEach(([name, field$1]) => {
|
|
1221
1286
|
tryIn(() => {
|
|
1222
|
-
|
|
1223
|
-
if (options?.fieldName) fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
|
|
1287
|
+
const fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
|
|
1224
1288
|
args[name] = {
|
|
1225
1289
|
...field$1,
|
|
1226
1290
|
type: ensureInputType(field$1, { fieldName })
|
|
@@ -1238,6 +1302,13 @@ function ensureInputType(silkOrType, options) {
|
|
|
1238
1302
|
if (isNonNullType(gqlType)) return new GraphQLNonNull(ensureInputType(gqlType.ofType, options));
|
|
1239
1303
|
if (isListType(gqlType)) return new GraphQLList(ensureInputType(gqlType.ofType, options));
|
|
1240
1304
|
if (isObjectType(gqlType) || isInterfaceType(gqlType)) return ensureInputObjectType(gqlType, options);
|
|
1305
|
+
if (isEnumType(gqlType)) {
|
|
1306
|
+
if (gqlType.name === AUTO_ALIASING) {
|
|
1307
|
+
const alias = `${pascalCase(options.fieldName)}Input`;
|
|
1308
|
+
weaverContext.setAlias(gqlType, alias);
|
|
1309
|
+
}
|
|
1310
|
+
return gqlType;
|
|
1311
|
+
}
|
|
1241
1312
|
return gqlType;
|
|
1242
1313
|
}
|
|
1243
1314
|
function ensureInputObjectType(object, options) {
|
|
@@ -1246,7 +1317,7 @@ function ensureInputObjectType(object, options) {
|
|
|
1246
1317
|
if (existing != null) return existing;
|
|
1247
1318
|
const { astNode, extensionASTNodes, fields,...config } = object.toConfig();
|
|
1248
1319
|
let name = object.name;
|
|
1249
|
-
if (name ===
|
|
1320
|
+
if (name === AUTO_ALIASING) name = `${pascalCase(options.fieldName)}Input`;
|
|
1250
1321
|
name = (weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n))(name);
|
|
1251
1322
|
const input = new GraphQLInputObjectType({
|
|
1252
1323
|
...config,
|
|
@@ -1269,10 +1340,9 @@ function inputFieldName(name) {
|
|
|
1269
1340
|
|
|
1270
1341
|
//#endregion
|
|
1271
1342
|
//#region src/schema/object.ts
|
|
1272
|
-
var LoomObjectType = class
|
|
1343
|
+
var LoomObjectType = class extends GraphQLObjectType {
|
|
1273
1344
|
extraFields = /* @__PURE__ */ new Map();
|
|
1274
1345
|
hiddenFields = /* @__PURE__ */ new Set();
|
|
1275
|
-
static AUTO_ALIASING = "__gqloom_auto_aliasing";
|
|
1276
1346
|
weaverContext;
|
|
1277
1347
|
globalOptions;
|
|
1278
1348
|
/**
|
|
@@ -1293,22 +1363,11 @@ var LoomObjectType = class LoomObjectType extends GraphQLObjectType {
|
|
|
1293
1363
|
this.globalOptions = options.globalOptions;
|
|
1294
1364
|
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
1295
1365
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
1296
|
-
if (this.name
|
|
1297
|
-
}
|
|
1298
|
-
hasExplicitName;
|
|
1299
|
-
_aliases = [];
|
|
1300
|
-
get aliases() {
|
|
1301
|
-
return this._aliases;
|
|
1302
|
-
}
|
|
1303
|
-
addAlias(name) {
|
|
1304
|
-
if (this.hasExplicitName) return;
|
|
1305
|
-
this._aliases.push(name);
|
|
1306
|
-
this.renameByAliases();
|
|
1366
|
+
if (this.name === AUTO_ALIASING) WeaverContext.autoAliasTypes.add(this);
|
|
1307
1367
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
if (name) this.name = name;
|
|
1368
|
+
addAlias(alias) {
|
|
1369
|
+
if (!WeaverContext.autoAliasTypes.has(this) || !alias) return;
|
|
1370
|
+
this.name = alias.length < this.name.length ? alias : this.name;
|
|
1312
1371
|
}
|
|
1313
1372
|
hideField(name) {
|
|
1314
1373
|
this.hiddenFields.add(name);
|
|
@@ -1322,10 +1381,14 @@ var LoomObjectType = class LoomObjectType extends GraphQLObjectType {
|
|
|
1322
1381
|
mergeExtensions(extensions) {
|
|
1323
1382
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
1324
1383
|
}
|
|
1384
|
+
collectedFieldNames() {
|
|
1385
|
+
const fieldsBySuper = super.getFields();
|
|
1386
|
+
Object.entries(fieldsBySuper).forEach(([fieldName, field$1]) => field$1.type = this.getCacheType(field$1.type, fieldName));
|
|
1387
|
+
}
|
|
1325
1388
|
extraFieldMap;
|
|
1326
1389
|
getFields() {
|
|
1327
1390
|
const fieldsBySuper = super.getFields();
|
|
1328
|
-
|
|
1391
|
+
this.collectedFieldNames();
|
|
1329
1392
|
const extraFields = provideWeaverContext(() => defineFieldMap(this.mapToFieldConfig(this.extraFields)), this.weaverContext);
|
|
1330
1393
|
if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) this.extraFieldMap = extraFields;
|
|
1331
1394
|
const answer = {
|
|
@@ -1347,7 +1410,7 @@ var LoomObjectType = class LoomObjectType extends GraphQLObjectType {
|
|
|
1347
1410
|
return {
|
|
1348
1411
|
...extract(field$1),
|
|
1349
1412
|
type: outputType,
|
|
1350
|
-
args: inputToArgs(field$1["~meta"].input, { fieldName:
|
|
1413
|
+
args: inputToArgs(field$1["~meta"].input, { fieldName: parentName(this.name) + fieldName }),
|
|
1351
1414
|
resolve,
|
|
1352
1415
|
...subscribe ? { subscribe } : {}
|
|
1353
1416
|
};
|
|
@@ -1499,13 +1562,17 @@ const OPERATION_OBJECT_NAMES = new Set([
|
|
|
1499
1562
|
]);
|
|
1500
1563
|
function getCacheType(gqlType, options = {}) {
|
|
1501
1564
|
const context = options.weaverContext ?? weaverContext;
|
|
1565
|
+
const getAlias = () => {
|
|
1566
|
+
if (!options.fieldName || !options.parent) return;
|
|
1567
|
+
return parentName(options.parent.name) + pascalCase(options.fieldName);
|
|
1568
|
+
};
|
|
1502
1569
|
if (gqlType instanceof LoomObjectType) return gqlType;
|
|
1503
1570
|
if (isObjectType(gqlType)) {
|
|
1504
1571
|
const gqlObject = context.loomObjectMap?.get(gqlType);
|
|
1505
1572
|
if (gqlObject != null) return gqlObject;
|
|
1506
1573
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
1507
1574
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1508
|
-
|
|
1575
|
+
context.setAlias(loomObject, getAlias());
|
|
1509
1576
|
return loomObject;
|
|
1510
1577
|
} else if (isListType(gqlType)) return new GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1511
1578
|
else if (isNonNullType(gqlType)) return new GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
@@ -1515,10 +1582,17 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1515
1582
|
const config = gqlType.toConfig();
|
|
1516
1583
|
const unionType = new GraphQLUnionType({
|
|
1517
1584
|
...config,
|
|
1518
|
-
types: config.types.map((type) => getCacheType(type,
|
|
1585
|
+
types: config.types.map((type, i) => getCacheType(type, {
|
|
1586
|
+
...options,
|
|
1587
|
+
fieldName: options.fieldName ? `${options.fieldName}Item${i + 1}` : void 0
|
|
1588
|
+
}))
|
|
1519
1589
|
});
|
|
1520
1590
|
context.loomUnionMap?.set(gqlType, unionType);
|
|
1591
|
+
context.setAlias(unionType, getAlias());
|
|
1521
1592
|
return unionType;
|
|
1593
|
+
} else if (isEnumType(gqlType) || isInterfaceType(gqlType) || isScalarType(gqlType)) {
|
|
1594
|
+
context.setAlias(gqlType, getAlias());
|
|
1595
|
+
return gqlType;
|
|
1522
1596
|
}
|
|
1523
1597
|
return gqlType;
|
|
1524
1598
|
}
|
|
@@ -1579,18 +1653,11 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1579
1653
|
return this;
|
|
1580
1654
|
}
|
|
1581
1655
|
addType(silk$1) {
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
if (isObjectType(gqlType$1)) {
|
|
1586
|
-
const existing = this.context.loomObjectMap.get(gqlType$1);
|
|
1587
|
-
if (existing != null) return existing;
|
|
1588
|
-
const extraObject = new LoomObjectType(gqlType$1, this.fieldOptions);
|
|
1589
|
-
this.context.loomObjectMap.set(gqlType$1, extraObject);
|
|
1590
|
-
return extraObject;
|
|
1591
|
-
} else if (isUnionType(gqlType$1) || isEnumType(gqlType$1)) return gqlType$1;
|
|
1592
|
-
throw new Error(`${gqlType$1?.name ?? gqlType$1.toString()} is not a named type`);
|
|
1656
|
+
let gqlType = provideWeaverContext(() => {
|
|
1657
|
+
const gqlType$1 = getGraphQLType(silk$1);
|
|
1658
|
+
return getCacheType(gqlType$1);
|
|
1593
1659
|
}, this.context);
|
|
1660
|
+
while (isNonNullType(gqlType) || isListType(gqlType)) gqlType = gqlType.ofType;
|
|
1594
1661
|
this.types.add(gqlType);
|
|
1595
1662
|
return this;
|
|
1596
1663
|
}
|
|
@@ -1615,8 +1682,8 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1615
1682
|
let parentObject = (() => {
|
|
1616
1683
|
if (parent == null) return void 0;
|
|
1617
1684
|
let gqlType = getGraphQLType(parent);
|
|
1618
|
-
|
|
1619
|
-
if (!isObjectType(gqlType)) throw new Error(`${gqlType
|
|
1685
|
+
while (isNonNullType(gqlType) || isListType(gqlType)) gqlType = gqlType.ofType;
|
|
1686
|
+
if (!isObjectType(gqlType)) throw new Error(`${gqlType.name} is not an object type`);
|
|
1620
1687
|
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1621
1688
|
if (existing != null) return existing;
|
|
1622
1689
|
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
@@ -1740,4 +1807,4 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1740
1807
|
}
|
|
1741
1808
|
|
|
1742
1809
|
//#endregion
|
|
1743
|
-
export { BaseChainFactory, ChainResolver, EasyDataLoader, FieldChainFactory, FieldFactoryWithResolve, GraphQLSchemaLoom, LoomDataLoader, LoomObjectType, MutationChainFactory, MutationFactoryWithResolve, OPERATION_OBJECT_NAMES, ObjectChainResolver, QueryChainFactory, QueryFactoryWithResolve, symbols_exports as SYMBOLS, SubscriptionChainFactory, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
|
1810
|
+
export { AUTO_ALIASING, BaseChainFactory, ChainResolver, DERIVED_DEPENDENCIES, EasyDataLoader, FieldChainFactory, FieldFactoryWithResolve, GlobalWeaverContext, GraphQLSchemaLoom, LoomDataLoader, LoomObjectType, MutationChainFactory, MutationFactoryWithResolve, OPERATION_OBJECT_NAMES, ObjectChainResolver, QueryChainFactory, QueryFactoryWithResolve, symbols_exports as SYMBOLS, SubscriptionChainFactory, WeaverContext, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|