@gqloom/core 0.12.0 → 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.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/{index-B1bRSxSg.d.cts → index-BxqR3YsC.d.cts} +50 -20
- package/dist/{index-_VhWbhmU.d.ts → index-sGKC4BRu.d.ts} +50 -20
- package/dist/index.cjs +167 -114
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +166 -115
- package/package.json +1 -1
package/dist/context.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseField, Middleware, OnlyMemoizationPayload, ResolverPayload, ResolvingFields } from "./index-
|
|
1
|
+
import { BaseField, Middleware, OnlyMemoizationPayload, ResolverPayload, ResolvingFields } from "./index-BxqR3YsC.cjs";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
|
|
4
4
|
//#region src/context/context.d.ts
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseField, Middleware, OnlyMemoizationPayload, ResolverPayload, ResolvingFields } from "./index-
|
|
1
|
+
import { BaseField, Middleware, OnlyMemoizationPayload, ResolverPayload, ResolvingFields } from "./index-sGKC4BRu.js";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
|
|
4
4
|
//#region src/context/context.d.ts
|
|
@@ -1073,44 +1073,73 @@ interface SchemaWeaver {
|
|
|
1073
1073
|
declare function isSchemaVendorWeaver(some: any): some is SchemaWeaver;
|
|
1074
1074
|
//#endregion
|
|
1075
1075
|
//#region src/schema/weaver-context.d.ts
|
|
1076
|
-
|
|
1076
|
+
declare class WeaverContext {
|
|
1077
|
+
static increasingID: number;
|
|
1078
|
+
static names: WeakMap<object, string>;
|
|
1079
|
+
static autoAliasTypes: WeakSet<GraphQLNamedType>;
|
|
1080
|
+
private static _ref;
|
|
1081
|
+
static get ref(): WeaverContext | undefined;
|
|
1077
1082
|
id: number;
|
|
1078
1083
|
loomObjectMap: Map<GraphQLObjectType, LoomObjectType>;
|
|
1079
1084
|
loomUnionMap: Map<GraphQLUnionType, GraphQLUnionType>;
|
|
1080
1085
|
inputMap: Map<GraphQLObjectType | GraphQLInterfaceType, GraphQLInputObjectType>;
|
|
1081
1086
|
interfaceMap: Map<GraphQLObjectType, GraphQLInterfaceType>;
|
|
1082
1087
|
configs: Map<string | symbol, WeaverConfig>;
|
|
1083
|
-
getConfig: <TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]) => TConfig | undefined;
|
|
1084
|
-
setConfig<TConfig extends WeaverConfig>(config: TConfig): void;
|
|
1085
|
-
deleteConfig: <TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]) => void;
|
|
1086
1088
|
namedTypes: Map<string, GraphQLOutputType>;
|
|
1087
|
-
memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlType: TGraphQLType): TGraphQLType;
|
|
1088
|
-
getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
|
|
1089
|
-
names: WeakMap<object, string>;
|
|
1090
|
-
autoAliasTypes: WeakSet<GraphQLNamedType>;
|
|
1091
1089
|
vendorWeavers: Map<string, SchemaWeaver>;
|
|
1090
|
+
constructor();
|
|
1091
|
+
getConfig<TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]): TConfig | undefined;
|
|
1092
|
+
setConfig<TConfig extends WeaverConfig>(config: TConfig): void;
|
|
1093
|
+
deleteConfig<TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]): void;
|
|
1094
|
+
memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlTypeValue: TGraphQLType): TGraphQLType;
|
|
1095
|
+
getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
|
|
1096
|
+
protected static readonly namedTypes: {
|
|
1097
|
+
readonly Object: "Object";
|
|
1098
|
+
readonly Union: "Union";
|
|
1099
|
+
readonly Enum: "Enum";
|
|
1100
|
+
readonly Interface: "Interface";
|
|
1101
|
+
readonly Scalar: "Scalar";
|
|
1102
|
+
};
|
|
1103
|
+
protected aliasCounters: Partial<Record<keyof typeof WeaverContext.namedTypes, number>>;
|
|
1104
|
+
setAlias(namedType: GraphQLNamedType, alias: string | undefined): string | undefined;
|
|
1105
|
+
/**
|
|
1106
|
+
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
1107
|
+
*/
|
|
1108
|
+
protected static higherPriorityThan(a: string | undefined, b: string | undefined): number;
|
|
1109
|
+
static provide<T>(func: () => T, value: WeaverContext | undefined): T;
|
|
1092
1110
|
}
|
|
1111
|
+
declare const initWeaverContext: () => WeaverContext;
|
|
1112
|
+
declare const provideWeaverContext: typeof WeaverContext.provide & {
|
|
1113
|
+
inherit: <T>(func: () => T) => () => T;
|
|
1114
|
+
};
|
|
1093
1115
|
interface WeaverConfig {
|
|
1094
1116
|
[WEAVER_CONFIG]: string | symbol;
|
|
1095
1117
|
vendorWeaver?: SchemaWeaver;
|
|
1096
1118
|
}
|
|
1097
|
-
|
|
1098
|
-
declare
|
|
1099
|
-
var increasingID: number;
|
|
1100
|
-
}
|
|
1101
|
-
type GlobalContextRequiredKeys = "names" | "getConfig" | "setConfig" | "deleteConfig" | "getNamedType" | "memoNamedType" | "autoAliasTypes";
|
|
1102
|
-
interface GlobalWeaverContext extends Partial<Omit<WeaverContext, GlobalContextRequiredKeys>>, Pick<WeaverContext, GlobalContextRequiredKeys> {
|
|
1103
|
-
value?: WeaverContext;
|
|
1104
|
-
useConfig<TConfig extends WeaverConfig, TCallback extends () => any>(config: TConfig, callback: TCallback): ReturnType<TCallback>;
|
|
1119
|
+
type GlobalContextRequiredKeys = "getConfig" | "setConfig" | "deleteConfig" | "getNamedType" | "memoNamedType";
|
|
1120
|
+
declare class GlobalWeaverContext implements Partial<Omit<WeaverContext, GlobalContextRequiredKeys>>, Pick<WeaverContext, GlobalContextRequiredKeys> {
|
|
1105
1121
|
GraphQLTypes: WeakMap<object, GraphQLOutputType>;
|
|
1122
|
+
get id(): number | undefined;
|
|
1123
|
+
get loomObjectMap(): Map<GraphQLObjectType<any, any>, LoomObjectType> | undefined;
|
|
1124
|
+
get loomUnionMap(): Map<GraphQLUnionType, GraphQLUnionType> | undefined;
|
|
1125
|
+
get inputMap(): Map<GraphQLInterfaceType | GraphQLObjectType<any, any>, GraphQLInputObjectType> | undefined;
|
|
1126
|
+
get interfaceMap(): Map<GraphQLObjectType<any, any>, GraphQLInterfaceType> | undefined;
|
|
1127
|
+
get configs(): Map<string | symbol, WeaverConfig> | undefined;
|
|
1128
|
+
get vendorWeavers(): Map<string, SchemaWeaver> | undefined;
|
|
1129
|
+
get names(): WeakMap<object, string>;
|
|
1130
|
+
get autoAliasTypes(): WeakSet<GraphQLNamedType>;
|
|
1131
|
+
get value(): WeaverContext | undefined;
|
|
1132
|
+
getConfig<TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]): TConfig | undefined;
|
|
1133
|
+
setConfig(config: WeaverConfig): void;
|
|
1134
|
+
deleteConfig(key: string | symbol): void;
|
|
1135
|
+
useConfig<TConfig extends WeaverConfig, TCallback extends () => any>(config: TConfig, callback: TCallback): ReturnType<TCallback>;
|
|
1136
|
+
getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
|
|
1137
|
+
memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlType: TGraphQLType): TGraphQLType;
|
|
1106
1138
|
getGraphQLType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(origin: object): TGraphQLType | undefined;
|
|
1107
1139
|
memoGraphQLType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(origin: object, gqlType: TGraphQLType): TGraphQLType;
|
|
1140
|
+
setAlias(namedType: GraphQLNamedType, alias: string | undefined): string | undefined;
|
|
1108
1141
|
}
|
|
1109
1142
|
declare const weaverContext: GlobalWeaverContext;
|
|
1110
|
-
declare function provideWeaverContext<T>(func: () => T, value: WeaverContext | undefined): T;
|
|
1111
|
-
declare namespace provideWeaverContext {
|
|
1112
|
-
var inherit: <T>(func: () => T) => () => T;
|
|
1113
|
-
}
|
|
1114
1143
|
/**
|
|
1115
1144
|
* collect names for schemas
|
|
1116
1145
|
* @param namesList - names to collect
|
|
@@ -1144,6 +1173,7 @@ declare class LoomObjectType extends GraphQLObjectType {
|
|
|
1144
1173
|
hideField(name: string): void;
|
|
1145
1174
|
addField(name: string, field: BaseField, resolver: Resolver | undefined): void;
|
|
1146
1175
|
mergeExtensions(extensions: GraphQLObjectTypeConfig<any, any>["extensions"]): void;
|
|
1176
|
+
protected collectedFieldNames(): void;
|
|
1147
1177
|
private extraFieldMap?;
|
|
1148
1178
|
getFields(): GraphQLFieldMap<any, any>;
|
|
1149
1179
|
protected mapToFieldConfig(map: Map<string, BaseField>): Record<string, GraphQLFieldConfig<any, any>>;
|
|
@@ -1071,44 +1071,73 @@ interface SchemaWeaver {
|
|
|
1071
1071
|
declare function isSchemaVendorWeaver(some: any): some is SchemaWeaver;
|
|
1072
1072
|
//#endregion
|
|
1073
1073
|
//#region src/schema/weaver-context.d.ts
|
|
1074
|
-
|
|
1074
|
+
declare class WeaverContext {
|
|
1075
|
+
static increasingID: number;
|
|
1076
|
+
static names: WeakMap<object, string>;
|
|
1077
|
+
static autoAliasTypes: WeakSet<GraphQLNamedType>;
|
|
1078
|
+
private static _ref;
|
|
1079
|
+
static get ref(): WeaverContext | undefined;
|
|
1075
1080
|
id: number;
|
|
1076
1081
|
loomObjectMap: Map<GraphQLObjectType, LoomObjectType>;
|
|
1077
1082
|
loomUnionMap: Map<GraphQLUnionType, GraphQLUnionType>;
|
|
1078
1083
|
inputMap: Map<GraphQLObjectType | GraphQLInterfaceType, GraphQLInputObjectType>;
|
|
1079
1084
|
interfaceMap: Map<GraphQLObjectType, GraphQLInterfaceType>;
|
|
1080
1085
|
configs: Map<string | symbol, WeaverConfig>;
|
|
1081
|
-
getConfig: <TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]) => TConfig | undefined;
|
|
1082
|
-
setConfig<TConfig extends WeaverConfig>(config: TConfig): void;
|
|
1083
|
-
deleteConfig: <TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]) => void;
|
|
1084
1086
|
namedTypes: Map<string, GraphQLOutputType>;
|
|
1085
|
-
memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlType: TGraphQLType): TGraphQLType;
|
|
1086
|
-
getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
|
|
1087
|
-
names: WeakMap<object, string>;
|
|
1088
|
-
autoAliasTypes: WeakSet<GraphQLNamedType>;
|
|
1089
1087
|
vendorWeavers: Map<string, SchemaWeaver>;
|
|
1088
|
+
constructor();
|
|
1089
|
+
getConfig<TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]): TConfig | undefined;
|
|
1090
|
+
setConfig<TConfig extends WeaverConfig>(config: TConfig): void;
|
|
1091
|
+
deleteConfig<TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]): void;
|
|
1092
|
+
memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlTypeValue: TGraphQLType): TGraphQLType;
|
|
1093
|
+
getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
|
|
1094
|
+
protected static readonly namedTypes: {
|
|
1095
|
+
readonly Object: "Object";
|
|
1096
|
+
readonly Union: "Union";
|
|
1097
|
+
readonly Enum: "Enum";
|
|
1098
|
+
readonly Interface: "Interface";
|
|
1099
|
+
readonly Scalar: "Scalar";
|
|
1100
|
+
};
|
|
1101
|
+
protected aliasCounters: Partial<Record<keyof typeof WeaverContext.namedTypes, number>>;
|
|
1102
|
+
setAlias(namedType: GraphQLNamedType, alias: string | undefined): string | undefined;
|
|
1103
|
+
/**
|
|
1104
|
+
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
1105
|
+
*/
|
|
1106
|
+
protected static higherPriorityThan(a: string | undefined, b: string | undefined): number;
|
|
1107
|
+
static provide<T>(func: () => T, value: WeaverContext | undefined): T;
|
|
1090
1108
|
}
|
|
1109
|
+
declare const initWeaverContext: () => WeaverContext;
|
|
1110
|
+
declare const provideWeaverContext: typeof WeaverContext.provide & {
|
|
1111
|
+
inherit: <T>(func: () => T) => () => T;
|
|
1112
|
+
};
|
|
1091
1113
|
interface WeaverConfig {
|
|
1092
1114
|
[WEAVER_CONFIG]: string | symbol;
|
|
1093
1115
|
vendorWeaver?: SchemaWeaver;
|
|
1094
1116
|
}
|
|
1095
|
-
|
|
1096
|
-
declare
|
|
1097
|
-
var increasingID: number;
|
|
1098
|
-
}
|
|
1099
|
-
type GlobalContextRequiredKeys = "names" | "getConfig" | "setConfig" | "deleteConfig" | "getNamedType" | "memoNamedType" | "autoAliasTypes";
|
|
1100
|
-
interface GlobalWeaverContext extends Partial<Omit<WeaverContext, GlobalContextRequiredKeys>>, Pick<WeaverContext, GlobalContextRequiredKeys> {
|
|
1101
|
-
value?: WeaverContext;
|
|
1102
|
-
useConfig<TConfig extends WeaverConfig, TCallback extends () => any>(config: TConfig, callback: TCallback): ReturnType<TCallback>;
|
|
1117
|
+
type GlobalContextRequiredKeys = "getConfig" | "setConfig" | "deleteConfig" | "getNamedType" | "memoNamedType";
|
|
1118
|
+
declare class GlobalWeaverContext implements Partial<Omit<WeaverContext, GlobalContextRequiredKeys>>, Pick<WeaverContext, GlobalContextRequiredKeys> {
|
|
1103
1119
|
GraphQLTypes: WeakMap<object, GraphQLOutputType>;
|
|
1120
|
+
get id(): number | undefined;
|
|
1121
|
+
get loomObjectMap(): Map<GraphQLObjectType<any, any>, LoomObjectType> | undefined;
|
|
1122
|
+
get loomUnionMap(): Map<GraphQLUnionType, GraphQLUnionType> | undefined;
|
|
1123
|
+
get inputMap(): Map<GraphQLInterfaceType | GraphQLObjectType<any, any>, GraphQLInputObjectType> | undefined;
|
|
1124
|
+
get interfaceMap(): Map<GraphQLObjectType<any, any>, GraphQLInterfaceType> | undefined;
|
|
1125
|
+
get configs(): Map<string | symbol, WeaverConfig> | undefined;
|
|
1126
|
+
get vendorWeavers(): Map<string, SchemaWeaver> | undefined;
|
|
1127
|
+
get names(): WeakMap<object, string>;
|
|
1128
|
+
get autoAliasTypes(): WeakSet<GraphQLNamedType>;
|
|
1129
|
+
get value(): WeaverContext | undefined;
|
|
1130
|
+
getConfig<TConfig extends WeaverConfig>(key: TConfig[typeof WEAVER_CONFIG]): TConfig | undefined;
|
|
1131
|
+
setConfig(config: WeaverConfig): void;
|
|
1132
|
+
deleteConfig(key: string | symbol): void;
|
|
1133
|
+
useConfig<TConfig extends WeaverConfig, TCallback extends () => any>(config: TConfig, callback: TCallback): ReturnType<TCallback>;
|
|
1134
|
+
getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
|
|
1135
|
+
memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlType: TGraphQLType): TGraphQLType;
|
|
1104
1136
|
getGraphQLType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(origin: object): TGraphQLType | undefined;
|
|
1105
1137
|
memoGraphQLType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(origin: object, gqlType: TGraphQLType): TGraphQLType;
|
|
1138
|
+
setAlias(namedType: GraphQLNamedType, alias: string | undefined): string | undefined;
|
|
1106
1139
|
}
|
|
1107
1140
|
declare const weaverContext: GlobalWeaverContext;
|
|
1108
|
-
declare function provideWeaverContext<T>(func: () => T, value: WeaverContext | undefined): T;
|
|
1109
|
-
declare namespace provideWeaverContext {
|
|
1110
|
-
var inherit: <T>(func: () => T) => () => T;
|
|
1111
|
-
}
|
|
1112
1141
|
/**
|
|
1113
1142
|
* collect names for schemas
|
|
1114
1143
|
* @param namesList - names to collect
|
|
@@ -1142,6 +1171,7 @@ declare class LoomObjectType extends GraphQLObjectType {
|
|
|
1142
1171
|
hideField(name: string): void;
|
|
1143
1172
|
addField(name: string, field: BaseField, resolver: Resolver | undefined): void;
|
|
1144
1173
|
mergeExtensions(extensions: GraphQLObjectTypeConfig<any, any>["extensions"]): void;
|
|
1174
|
+
protected collectedFieldNames(): void;
|
|
1145
1175
|
private extraFieldMap?;
|
|
1146
1176
|
getFields(): GraphQLFieldMap<any, any>;
|
|
1147
1177
|
protected mapToFieldConfig(map: Map<string, BaseField>): Record<string, GraphQLFieldConfig<any, any>>;
|
package/dist/index.cjs
CHANGED
|
@@ -240,113 +240,176 @@ var EasyDataLoader = class extends LoomDataLoader {
|
|
|
240
240
|
|
|
241
241
|
//#endregion
|
|
242
242
|
//#region src/schema/weaver-context.ts
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
namedTypes
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
243
|
+
var WeaverContext = class WeaverContext {
|
|
244
|
+
static increasingID = 1;
|
|
245
|
+
static names = /* @__PURE__ */ new WeakMap();
|
|
246
|
+
static autoAliasTypes = /* @__PURE__ */ new WeakSet();
|
|
247
|
+
static _ref;
|
|
248
|
+
static get ref() {
|
|
249
|
+
return WeaverContext._ref;
|
|
250
|
+
}
|
|
251
|
+
id;
|
|
252
|
+
loomObjectMap;
|
|
253
|
+
loomUnionMap;
|
|
254
|
+
inputMap;
|
|
255
|
+
interfaceMap;
|
|
256
|
+
configs;
|
|
257
|
+
namedTypes;
|
|
258
|
+
vendorWeavers;
|
|
259
|
+
constructor() {
|
|
260
|
+
this.id = WeaverContext.increasingID++;
|
|
261
|
+
this.loomObjectMap = /* @__PURE__ */ new Map();
|
|
262
|
+
this.loomUnionMap = /* @__PURE__ */ new Map();
|
|
263
|
+
this.inputMap = /* @__PURE__ */ new Map();
|
|
264
|
+
this.interfaceMap = /* @__PURE__ */ new Map();
|
|
265
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
266
|
+
this.namedTypes = /* @__PURE__ */ new Map();
|
|
267
|
+
this.vendorWeavers = /* @__PURE__ */ new Map();
|
|
268
|
+
}
|
|
269
|
+
getConfig(key) {
|
|
270
|
+
return this.configs.get(key);
|
|
271
|
+
}
|
|
272
|
+
setConfig(config) {
|
|
273
|
+
const key = config[require_context.WEAVER_CONFIG];
|
|
274
|
+
this.configs.set(key, config);
|
|
275
|
+
}
|
|
276
|
+
deleteConfig(key) {
|
|
277
|
+
this.configs.delete(key);
|
|
278
|
+
}
|
|
279
|
+
memoNamedType(gqlTypeValue) {
|
|
280
|
+
const gqlType = gqlTypeValue;
|
|
281
|
+
if ((0, graphql.isObjectType)(gqlType) || (0, graphql.isUnionType)(gqlType) || (0, graphql.isEnumType)(gqlType) || (0, graphql.isScalarType)(gqlType)) this.namedTypes.set(gqlType.name, gqlType);
|
|
282
|
+
return gqlTypeValue;
|
|
283
|
+
}
|
|
284
|
+
getNamedType(name) {
|
|
285
|
+
return this.namedTypes.get(name);
|
|
286
|
+
}
|
|
287
|
+
static namedTypes = {
|
|
288
|
+
Object: "Object",
|
|
289
|
+
Union: "Union",
|
|
290
|
+
Enum: "Enum",
|
|
291
|
+
Interface: "Interface",
|
|
292
|
+
Scalar: "Scalar"
|
|
276
293
|
};
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
294
|
+
aliasCounters = {};
|
|
295
|
+
setAlias(namedType, alias) {
|
|
296
|
+
if (namedType.name === require_context.AUTO_ALIASING) WeaverContext.autoAliasTypes.add(namedType);
|
|
297
|
+
if (!WeaverContext.autoAliasTypes.has(namedType)) return namedType.name;
|
|
298
|
+
if (WeaverContext.higherPriorityThan(alias, namedType.name) < 0) {
|
|
299
|
+
if (alias) return namedType.name = alias;
|
|
300
|
+
}
|
|
301
|
+
if (namedType.name === require_context.AUTO_ALIASING) {
|
|
302
|
+
if ((0, graphql.isObjectType)(namedType) || (0, graphql.isInputObjectType)(namedType)) {
|
|
303
|
+
this.aliasCounters["Object"] ??= 0;
|
|
304
|
+
return namedType.name = `Object${++this.aliasCounters["Object"]}`;
|
|
305
|
+
} else if ((0, graphql.isUnionType)(namedType)) {
|
|
306
|
+
this.aliasCounters["Union"] ??= 0;
|
|
307
|
+
return namedType.name = `Union${++this.aliasCounters["Union"]}`;
|
|
308
|
+
} else if ((0, graphql.isEnumType)(namedType)) {
|
|
309
|
+
this.aliasCounters["Enum"] ??= 0;
|
|
310
|
+
return namedType.name = `Enum${++this.aliasCounters["Enum"]}`;
|
|
311
|
+
} else if ((0, graphql.isInterfaceType)(namedType)) {
|
|
312
|
+
this.aliasCounters["Interface"] ??= 0;
|
|
313
|
+
return namedType.name = `Interface${++this.aliasCounters["Interface"]}`;
|
|
314
|
+
} else if ((0, graphql.isScalarType)(namedType)) {
|
|
315
|
+
this.aliasCounters["Scalar"] ??= 0;
|
|
316
|
+
return namedType.name = `Scalar${++this.aliasCounters["Scalar"]}`;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* @returns -1 if a is better than b, 1 if b is better than a, 0 if they are equal
|
|
322
|
+
*/
|
|
323
|
+
static higherPriorityThan(a, b) {
|
|
324
|
+
if (a === require_context.AUTO_ALIASING || a === void 0) return 1;
|
|
325
|
+
else if (b === require_context.AUTO_ALIASING || b === void 0) return -1;
|
|
326
|
+
const compareLength = a.length - b.length;
|
|
327
|
+
if (compareLength !== 0) return compareLength;
|
|
328
|
+
const compareLocale = a.localeCompare(b);
|
|
329
|
+
if (compareLocale !== 0) return compareLocale;
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
static provide(func, value) {
|
|
333
|
+
const lastRef = WeaverContext._ref;
|
|
334
|
+
WeaverContext._ref = value;
|
|
335
|
+
try {
|
|
336
|
+
return func();
|
|
337
|
+
} finally {
|
|
338
|
+
WeaverContext._ref = lastRef;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const initWeaverContext = () => new WeaverContext();
|
|
343
|
+
const provideWeaverContext = Object.assign(WeaverContext.provide, { inherit: (func) => {
|
|
344
|
+
const weaverContextRef = WeaverContext.ref;
|
|
345
|
+
return () => WeaverContext.provide(func, weaverContextRef);
|
|
346
|
+
} });
|
|
347
|
+
var GlobalWeaverContext = class {
|
|
348
|
+
GraphQLTypes = /* @__PURE__ */ new WeakMap();
|
|
280
349
|
get id() {
|
|
281
|
-
return ref?.id;
|
|
282
|
-
}
|
|
350
|
+
return WeaverContext.ref?.id;
|
|
351
|
+
}
|
|
283
352
|
get loomObjectMap() {
|
|
284
|
-
return ref?.loomObjectMap;
|
|
285
|
-
}
|
|
353
|
+
return WeaverContext.ref?.loomObjectMap;
|
|
354
|
+
}
|
|
286
355
|
get loomUnionMap() {
|
|
287
|
-
return ref?.loomUnionMap;
|
|
288
|
-
}
|
|
356
|
+
return WeaverContext.ref?.loomUnionMap;
|
|
357
|
+
}
|
|
289
358
|
get inputMap() {
|
|
290
|
-
return ref?.inputMap;
|
|
291
|
-
}
|
|
359
|
+
return WeaverContext.ref?.inputMap;
|
|
360
|
+
}
|
|
292
361
|
get interfaceMap() {
|
|
293
|
-
return ref?.interfaceMap;
|
|
294
|
-
}
|
|
362
|
+
return WeaverContext.ref?.interfaceMap;
|
|
363
|
+
}
|
|
295
364
|
get configs() {
|
|
296
|
-
return ref?.configs;
|
|
297
|
-
}
|
|
365
|
+
return WeaverContext.ref?.configs;
|
|
366
|
+
}
|
|
298
367
|
get vendorWeavers() {
|
|
299
|
-
return ref?.vendorWeavers;
|
|
300
|
-
}
|
|
368
|
+
return WeaverContext.ref?.vendorWeavers;
|
|
369
|
+
}
|
|
370
|
+
get names() {
|
|
371
|
+
return WeaverContext.names;
|
|
372
|
+
}
|
|
373
|
+
get autoAliasTypes() {
|
|
374
|
+
return WeaverContext.autoAliasTypes;
|
|
375
|
+
}
|
|
376
|
+
get value() {
|
|
377
|
+
return WeaverContext.ref;
|
|
378
|
+
}
|
|
301
379
|
getConfig(key) {
|
|
302
|
-
return ref?.getConfig(key);
|
|
303
|
-
}
|
|
380
|
+
return WeaverContext.ref?.getConfig(key);
|
|
381
|
+
}
|
|
304
382
|
setConfig(config) {
|
|
305
|
-
ref?.setConfig(config);
|
|
306
|
-
}
|
|
383
|
+
WeaverContext.ref?.setConfig(config);
|
|
384
|
+
}
|
|
307
385
|
deleteConfig(key) {
|
|
308
|
-
ref?.deleteConfig(key);
|
|
309
|
-
}
|
|
310
|
-
get value() {
|
|
311
|
-
return ref;
|
|
312
|
-
},
|
|
386
|
+
WeaverContext.ref?.deleteConfig(key);
|
|
387
|
+
}
|
|
313
388
|
useConfig(config, callback) {
|
|
314
|
-
const context =
|
|
389
|
+
const context = this.value ?? initWeaverContext();
|
|
315
390
|
context.setConfig(config);
|
|
316
391
|
const result = provideWeaverContext(callback, context);
|
|
317
392
|
context.deleteConfig(config[require_context.WEAVER_CONFIG]);
|
|
318
393
|
return result;
|
|
319
|
-
}
|
|
320
|
-
names,
|
|
321
|
-
autoAliasTypes,
|
|
394
|
+
}
|
|
322
395
|
getNamedType(name) {
|
|
323
|
-
return ref?.getNamedType(name);
|
|
324
|
-
}
|
|
396
|
+
return WeaverContext.ref?.getNamedType(name);
|
|
397
|
+
}
|
|
325
398
|
memoNamedType(gqlType) {
|
|
326
|
-
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
327
|
-
}
|
|
328
|
-
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
399
|
+
return WeaverContext.ref?.memoNamedType(gqlType) ?? gqlType;
|
|
400
|
+
}
|
|
329
401
|
getGraphQLType(origin) {
|
|
330
402
|
return this.GraphQLTypes.get(origin);
|
|
331
|
-
}
|
|
403
|
+
}
|
|
332
404
|
memoGraphQLType(origin, gqlType) {
|
|
333
405
|
this.GraphQLTypes.set(origin, gqlType);
|
|
334
406
|
return gqlType;
|
|
335
407
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const lastRef = ref;
|
|
339
|
-
ref = value;
|
|
340
|
-
try {
|
|
341
|
-
return func();
|
|
342
|
-
} finally {
|
|
343
|
-
ref = lastRef;
|
|
408
|
+
setAlias(namedType, alias) {
|
|
409
|
+
return WeaverContext.ref?.setAlias(namedType, alias);
|
|
344
410
|
}
|
|
345
|
-
}
|
|
346
|
-
provideWeaverContext.inherit = (func) => {
|
|
347
|
-
const weaverContextRef = weaverContext.value;
|
|
348
|
-
return () => provideWeaverContext(func, weaverContextRef);
|
|
349
411
|
};
|
|
412
|
+
const weaverContext = new GlobalWeaverContext();
|
|
350
413
|
/**
|
|
351
414
|
* collect names for schemas
|
|
352
415
|
* @param namesList - names to collect
|
|
@@ -355,7 +418,7 @@ provideWeaverContext.inherit = (func) => {
|
|
|
355
418
|
function collectNames(...namesList) {
|
|
356
419
|
const namesRecord = {};
|
|
357
420
|
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
358
|
-
names.set(schema, name);
|
|
421
|
+
WeaverContext.names.set(schema, name);
|
|
359
422
|
namesRecord[name] = schema;
|
|
360
423
|
}
|
|
361
424
|
return namesRecord;
|
|
@@ -367,7 +430,7 @@ function collectNames(...namesList) {
|
|
|
367
430
|
* @returns schema
|
|
368
431
|
*/
|
|
369
432
|
function collectName(name, schema) {
|
|
370
|
-
names.set(schema, name);
|
|
433
|
+
WeaverContext.names.set(schema, name);
|
|
371
434
|
return schema;
|
|
372
435
|
}
|
|
373
436
|
|
|
@@ -1206,15 +1269,6 @@ var ObjectChainResolver = class extends ChainResolver {
|
|
|
1206
1269
|
}
|
|
1207
1270
|
};
|
|
1208
1271
|
|
|
1209
|
-
//#endregion
|
|
1210
|
-
//#region src/schema/alias.ts
|
|
1211
|
-
function setAlias(namedType, alias, context) {
|
|
1212
|
-
if (namedType.name === require_context.AUTO_ALIASING) context.autoAliasTypes.add(namedType);
|
|
1213
|
-
if (!context.autoAliasTypes.has(namedType) || !alias) return;
|
|
1214
|
-
if (namedType.name === require_context.AUTO_ALIASING) namedType.name = alias;
|
|
1215
|
-
namedType.name = alias.length < namedType.name.length ? alias : namedType.name;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
1272
|
//#endregion
|
|
1219
1273
|
//#region src/schema/input.ts
|
|
1220
1274
|
function inputToArgs(input, options) {
|
|
@@ -1252,7 +1306,7 @@ function ensureInputType(silkOrType, options) {
|
|
|
1252
1306
|
if ((0, graphql.isEnumType)(gqlType)) {
|
|
1253
1307
|
if (gqlType.name === require_context.AUTO_ALIASING) {
|
|
1254
1308
|
const alias = `${pascalCase(options.fieldName)}Input`;
|
|
1255
|
-
setAlias(gqlType, alias
|
|
1309
|
+
weaverContext.setAlias(gqlType, alias);
|
|
1256
1310
|
}
|
|
1257
1311
|
return gqlType;
|
|
1258
1312
|
}
|
|
@@ -1310,10 +1364,10 @@ var LoomObjectType = class extends graphql.GraphQLObjectType {
|
|
|
1310
1364
|
this.globalOptions = options.globalOptions;
|
|
1311
1365
|
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
1312
1366
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
1313
|
-
if (this.name === require_context.AUTO_ALIASING)
|
|
1367
|
+
if (this.name === require_context.AUTO_ALIASING) WeaverContext.autoAliasTypes.add(this);
|
|
1314
1368
|
}
|
|
1315
1369
|
addAlias(alias) {
|
|
1316
|
-
if (!
|
|
1370
|
+
if (!WeaverContext.autoAliasTypes.has(this) || !alias) return;
|
|
1317
1371
|
this.name = alias.length < this.name.length ? alias : this.name;
|
|
1318
1372
|
}
|
|
1319
1373
|
hideField(name) {
|
|
@@ -1328,10 +1382,14 @@ var LoomObjectType = class extends graphql.GraphQLObjectType {
|
|
|
1328
1382
|
mergeExtensions(extensions) {
|
|
1329
1383
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
1330
1384
|
}
|
|
1385
|
+
collectedFieldNames() {
|
|
1386
|
+
const fieldsBySuper = super.getFields();
|
|
1387
|
+
Object.entries(fieldsBySuper).forEach(([fieldName, field$1]) => field$1.type = this.getCacheType(field$1.type, fieldName));
|
|
1388
|
+
}
|
|
1331
1389
|
extraFieldMap;
|
|
1332
1390
|
getFields() {
|
|
1333
1391
|
const fieldsBySuper = super.getFields();
|
|
1334
|
-
|
|
1392
|
+
this.collectedFieldNames();
|
|
1335
1393
|
const extraFields = provideWeaverContext(() => defineFieldMap(this.mapToFieldConfig(this.extraFields)), this.weaverContext);
|
|
1336
1394
|
if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) this.extraFieldMap = extraFields;
|
|
1337
1395
|
const answer = {
|
|
@@ -1515,7 +1573,7 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1515
1573
|
if (gqlObject != null) return gqlObject;
|
|
1516
1574
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
1517
1575
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1518
|
-
setAlias(loomObject, getAlias()
|
|
1576
|
+
context.setAlias(loomObject, getAlias());
|
|
1519
1577
|
return loomObject;
|
|
1520
1578
|
} else if ((0, graphql.isListType)(gqlType)) return new graphql.GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1521
1579
|
else if ((0, graphql.isNonNullType)(gqlType)) return new graphql.GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
@@ -1527,14 +1585,14 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1527
1585
|
...config,
|
|
1528
1586
|
types: config.types.map((type, i) => getCacheType(type, {
|
|
1529
1587
|
...options,
|
|
1530
|
-
fieldName: options.fieldName ? `${options.fieldName}${i + 1}` : void 0
|
|
1588
|
+
fieldName: options.fieldName ? `${options.fieldName}Item${i + 1}` : void 0
|
|
1531
1589
|
}))
|
|
1532
1590
|
});
|
|
1533
1591
|
context.loomUnionMap?.set(gqlType, unionType);
|
|
1534
|
-
setAlias(unionType, getAlias()
|
|
1592
|
+
context.setAlias(unionType, getAlias());
|
|
1535
1593
|
return unionType;
|
|
1536
|
-
} else if ((0, graphql.isEnumType)(gqlType)) {
|
|
1537
|
-
setAlias(gqlType, getAlias()
|
|
1594
|
+
} else if ((0, graphql.isEnumType)(gqlType) || (0, graphql.isInterfaceType)(gqlType) || (0, graphql.isScalarType)(gqlType)) {
|
|
1595
|
+
context.setAlias(gqlType, getAlias());
|
|
1538
1596
|
return gqlType;
|
|
1539
1597
|
}
|
|
1540
1598
|
return gqlType;
|
|
@@ -1596,18 +1654,11 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1596
1654
|
return this;
|
|
1597
1655
|
}
|
|
1598
1656
|
addType(silk$1) {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
if ((0, graphql.isObjectType)(gqlType$1)) {
|
|
1603
|
-
const existing = this.context.loomObjectMap.get(gqlType$1);
|
|
1604
|
-
if (existing != null) return existing;
|
|
1605
|
-
const extraObject = new LoomObjectType(gqlType$1, this.fieldOptions);
|
|
1606
|
-
this.context.loomObjectMap.set(gqlType$1, extraObject);
|
|
1607
|
-
return extraObject;
|
|
1608
|
-
} else if ((0, graphql.isUnionType)(gqlType$1) || (0, graphql.isEnumType)(gqlType$1)) return gqlType$1;
|
|
1609
|
-
throw new Error(`${gqlType$1?.name ?? gqlType$1.toString()} is not a named type`);
|
|
1657
|
+
let gqlType = provideWeaverContext(() => {
|
|
1658
|
+
const gqlType$1 = getGraphQLType(silk$1);
|
|
1659
|
+
return getCacheType(gqlType$1);
|
|
1610
1660
|
}, this.context);
|
|
1661
|
+
while ((0, graphql.isNonNullType)(gqlType) || (0, graphql.isListType)(gqlType)) gqlType = gqlType.ofType;
|
|
1611
1662
|
this.types.add(gqlType);
|
|
1612
1663
|
return this;
|
|
1613
1664
|
}
|
|
@@ -1632,8 +1683,8 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1632
1683
|
let parentObject = (() => {
|
|
1633
1684
|
if (parent == null) return void 0;
|
|
1634
1685
|
let gqlType = getGraphQLType(parent);
|
|
1635
|
-
|
|
1636
|
-
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType
|
|
1686
|
+
while ((0, graphql.isNonNullType)(gqlType) || (0, graphql.isListType)(gqlType)) gqlType = gqlType.ofType;
|
|
1687
|
+
if (!(0, graphql.isObjectType)(gqlType)) throw new Error(`${gqlType.name} is not an object type`);
|
|
1637
1688
|
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1638
1689
|
if (existing != null) return existing;
|
|
1639
1690
|
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
@@ -1764,6 +1815,7 @@ exports.DERIVED_DEPENDENCIES = require_context.DERIVED_DEPENDENCIES;
|
|
|
1764
1815
|
exports.EasyDataLoader = EasyDataLoader;
|
|
1765
1816
|
exports.FieldChainFactory = FieldChainFactory;
|
|
1766
1817
|
exports.FieldFactoryWithResolve = FieldFactoryWithResolve;
|
|
1818
|
+
exports.GlobalWeaverContext = GlobalWeaverContext;
|
|
1767
1819
|
exports.GraphQLSchemaLoom = GraphQLSchemaLoom;
|
|
1768
1820
|
exports.LoomDataLoader = LoomDataLoader;
|
|
1769
1821
|
exports.LoomObjectType = LoomObjectType;
|
|
@@ -1780,6 +1832,7 @@ Object.defineProperty(exports, 'SYMBOLS', {
|
|
|
1780
1832
|
}
|
|
1781
1833
|
});
|
|
1782
1834
|
exports.SubscriptionChainFactory = SubscriptionChainFactory;
|
|
1835
|
+
exports.WeaverContext = WeaverContext;
|
|
1783
1836
|
exports.applyMiddlewares = applyMiddlewares;
|
|
1784
1837
|
exports.assignContextMap = require_context.assignContextMap;
|
|
1785
1838
|
exports.capitalize = capitalize;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, LoomDataLoader, LoomObjectType, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, 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, symbols_d_exports, toObjMap, tryIn, types_loom_d_exports, weave, weaverContext } from "./index-
|
|
1
|
+
import { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, LoomDataLoader, LoomObjectType, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, 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, symbols_d_exports, toObjMap, tryIn, types_loom_d_exports, weave, weaverContext } from "./index-BxqR3YsC.cjs";
|
|
2
2
|
export { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, types_loom_d_exports as Loom, LoomDataLoader, LoomObjectType, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, symbols_d_exports as SYMBOLS, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, LoomDataLoader, LoomObjectType, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, 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, symbols_d_exports, toObjMap, tryIn, types_loom_d_exports, weave, weaverContext } from "./index-
|
|
1
|
+
import { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, LoomDataLoader, LoomObjectType, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, 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, symbols_d_exports, toObjMap, tryIn, types_loom_d_exports, weave, weaverContext } from "./index-sGKC4BRu.js";
|
|
2
2
|
export { AUTO_ALIASING, BaseChainFactory, BaseField, BatchLoadFn, CallableInputParser, CallableMiddlewareOptions, ChainFactoryOptions, ChainResolver, CoreSchemaWeaverConfig, CoreSchemaWeaverConfigOptions, DERIVED_DEPENDENCIES, DirectiveItem, DirectiveRecord, EasyDataLoader, Executor, Field, FieldChainFactory, FieldFactory, FieldFactoryWithResolve, FieldFactoryWithUtils, FieldMeta, FieldOptions, FieldOrOperation, FieldOrOperationType, GQLoomExtensionAttribute, GQLoomExtensions, GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, IChainFactory, InferFieldInput, InferFieldOutput, InferInputI, InferInputO, IsAny, ListSilk, types_loom_d_exports as Loom, LoomDataLoader, LoomObjectType, MayPromise, Middleware, MiddlewareConfig, MiddlewareOperation, MiddlewareOptions, Mutation, MutationChainFactory, MutationFactory, MutationFactoryWithChain, MutationFactoryWithResolve, MutationOptions, NonNullSilk, NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, OnlyMemoizationPayload, Operation, OperationType, Query, QueryChainFactory, QueryFactory, QueryFactoryWithChain, QueryFactoryWithResolve, QueryOptions, RequireKeys, ResolvableSubscription, Resolver, ResolverFactory, ResolverMeta, ResolverOptions, ResolverOptionsWithExtensions, ResolverOptionsWithParent, ResolverPayload, ResolvingFields, ResolvingOptions, symbols_d_exports as SYMBOLS, SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactory, SubscriptionFactoryWithChain, SubscriptionNeedResolve, SubscriptionOptions, ToExecutorProps, ValueOf, WeaverConfig, 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 };
|
package/dist/index.js
CHANGED
|
@@ -239,113 +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
|
-
namedTypes
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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"
|
|
275
292
|
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
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();
|
|
279
348
|
get id() {
|
|
280
|
-
return ref?.id;
|
|
281
|
-
}
|
|
349
|
+
return WeaverContext.ref?.id;
|
|
350
|
+
}
|
|
282
351
|
get loomObjectMap() {
|
|
283
|
-
return ref?.loomObjectMap;
|
|
284
|
-
}
|
|
352
|
+
return WeaverContext.ref?.loomObjectMap;
|
|
353
|
+
}
|
|
285
354
|
get loomUnionMap() {
|
|
286
|
-
return ref?.loomUnionMap;
|
|
287
|
-
}
|
|
355
|
+
return WeaverContext.ref?.loomUnionMap;
|
|
356
|
+
}
|
|
288
357
|
get inputMap() {
|
|
289
|
-
return ref?.inputMap;
|
|
290
|
-
}
|
|
358
|
+
return WeaverContext.ref?.inputMap;
|
|
359
|
+
}
|
|
291
360
|
get interfaceMap() {
|
|
292
|
-
return ref?.interfaceMap;
|
|
293
|
-
}
|
|
361
|
+
return WeaverContext.ref?.interfaceMap;
|
|
362
|
+
}
|
|
294
363
|
get configs() {
|
|
295
|
-
return ref?.configs;
|
|
296
|
-
}
|
|
364
|
+
return WeaverContext.ref?.configs;
|
|
365
|
+
}
|
|
297
366
|
get vendorWeavers() {
|
|
298
|
-
return ref?.vendorWeavers;
|
|
299
|
-
}
|
|
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
|
+
}
|
|
300
378
|
getConfig(key) {
|
|
301
|
-
return ref?.getConfig(key);
|
|
302
|
-
}
|
|
379
|
+
return WeaverContext.ref?.getConfig(key);
|
|
380
|
+
}
|
|
303
381
|
setConfig(config) {
|
|
304
|
-
ref?.setConfig(config);
|
|
305
|
-
}
|
|
382
|
+
WeaverContext.ref?.setConfig(config);
|
|
383
|
+
}
|
|
306
384
|
deleteConfig(key) {
|
|
307
|
-
ref?.deleteConfig(key);
|
|
308
|
-
}
|
|
309
|
-
get value() {
|
|
310
|
-
return ref;
|
|
311
|
-
},
|
|
385
|
+
WeaverContext.ref?.deleteConfig(key);
|
|
386
|
+
}
|
|
312
387
|
useConfig(config, callback) {
|
|
313
|
-
const context =
|
|
388
|
+
const context = this.value ?? initWeaverContext();
|
|
314
389
|
context.setConfig(config);
|
|
315
390
|
const result = provideWeaverContext(callback, context);
|
|
316
391
|
context.deleteConfig(config[WEAVER_CONFIG]);
|
|
317
392
|
return result;
|
|
318
|
-
}
|
|
319
|
-
names,
|
|
320
|
-
autoAliasTypes,
|
|
393
|
+
}
|
|
321
394
|
getNamedType(name) {
|
|
322
|
-
return ref?.getNamedType(name);
|
|
323
|
-
}
|
|
395
|
+
return WeaverContext.ref?.getNamedType(name);
|
|
396
|
+
}
|
|
324
397
|
memoNamedType(gqlType) {
|
|
325
|
-
return ref?.memoNamedType(gqlType) ?? gqlType;
|
|
326
|
-
}
|
|
327
|
-
GraphQLTypes: /* @__PURE__ */ new WeakMap(),
|
|
398
|
+
return WeaverContext.ref?.memoNamedType(gqlType) ?? gqlType;
|
|
399
|
+
}
|
|
328
400
|
getGraphQLType(origin) {
|
|
329
401
|
return this.GraphQLTypes.get(origin);
|
|
330
|
-
}
|
|
402
|
+
}
|
|
331
403
|
memoGraphQLType(origin, gqlType) {
|
|
332
404
|
this.GraphQLTypes.set(origin, gqlType);
|
|
333
405
|
return gqlType;
|
|
334
406
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
const lastRef = ref;
|
|
338
|
-
ref = value;
|
|
339
|
-
try {
|
|
340
|
-
return func();
|
|
341
|
-
} finally {
|
|
342
|
-
ref = lastRef;
|
|
407
|
+
setAlias(namedType, alias) {
|
|
408
|
+
return WeaverContext.ref?.setAlias(namedType, alias);
|
|
343
409
|
}
|
|
344
|
-
}
|
|
345
|
-
provideWeaverContext.inherit = (func) => {
|
|
346
|
-
const weaverContextRef = weaverContext.value;
|
|
347
|
-
return () => provideWeaverContext(func, weaverContextRef);
|
|
348
410
|
};
|
|
411
|
+
const weaverContext = new GlobalWeaverContext();
|
|
349
412
|
/**
|
|
350
413
|
* collect names for schemas
|
|
351
414
|
* @param namesList - names to collect
|
|
@@ -354,7 +417,7 @@ provideWeaverContext.inherit = (func) => {
|
|
|
354
417
|
function collectNames(...namesList) {
|
|
355
418
|
const namesRecord = {};
|
|
356
419
|
for (const namesItem of namesList) for (const [name, schema] of Object.entries(namesItem)) {
|
|
357
|
-
names.set(schema, name);
|
|
420
|
+
WeaverContext.names.set(schema, name);
|
|
358
421
|
namesRecord[name] = schema;
|
|
359
422
|
}
|
|
360
423
|
return namesRecord;
|
|
@@ -366,7 +429,7 @@ function collectNames(...namesList) {
|
|
|
366
429
|
* @returns schema
|
|
367
430
|
*/
|
|
368
431
|
function collectName(name, schema) {
|
|
369
|
-
names.set(schema, name);
|
|
432
|
+
WeaverContext.names.set(schema, name);
|
|
370
433
|
return schema;
|
|
371
434
|
}
|
|
372
435
|
|
|
@@ -1205,15 +1268,6 @@ var ObjectChainResolver = class extends ChainResolver {
|
|
|
1205
1268
|
}
|
|
1206
1269
|
};
|
|
1207
1270
|
|
|
1208
|
-
//#endregion
|
|
1209
|
-
//#region src/schema/alias.ts
|
|
1210
|
-
function setAlias(namedType, alias, context) {
|
|
1211
|
-
if (namedType.name === AUTO_ALIASING) context.autoAliasTypes.add(namedType);
|
|
1212
|
-
if (!context.autoAliasTypes.has(namedType) || !alias) return;
|
|
1213
|
-
if (namedType.name === AUTO_ALIASING) namedType.name = alias;
|
|
1214
|
-
namedType.name = alias.length < namedType.name.length ? alias : namedType.name;
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
1271
|
//#endregion
|
|
1218
1272
|
//#region src/schema/input.ts
|
|
1219
1273
|
function inputToArgs(input, options) {
|
|
@@ -1251,7 +1305,7 @@ function ensureInputType(silkOrType, options) {
|
|
|
1251
1305
|
if (isEnumType(gqlType)) {
|
|
1252
1306
|
if (gqlType.name === AUTO_ALIASING) {
|
|
1253
1307
|
const alias = `${pascalCase(options.fieldName)}Input`;
|
|
1254
|
-
setAlias(gqlType, alias
|
|
1308
|
+
weaverContext.setAlias(gqlType, alias);
|
|
1255
1309
|
}
|
|
1256
1310
|
return gqlType;
|
|
1257
1311
|
}
|
|
@@ -1309,10 +1363,10 @@ var LoomObjectType = class extends GraphQLObjectType {
|
|
|
1309
1363
|
this.globalOptions = options.globalOptions;
|
|
1310
1364
|
this.weaverContext = options.weaverContext ?? initWeaverContext();
|
|
1311
1365
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
1312
|
-
if (this.name === AUTO_ALIASING)
|
|
1366
|
+
if (this.name === AUTO_ALIASING) WeaverContext.autoAliasTypes.add(this);
|
|
1313
1367
|
}
|
|
1314
1368
|
addAlias(alias) {
|
|
1315
|
-
if (!
|
|
1369
|
+
if (!WeaverContext.autoAliasTypes.has(this) || !alias) return;
|
|
1316
1370
|
this.name = alias.length < this.name.length ? alias : this.name;
|
|
1317
1371
|
}
|
|
1318
1372
|
hideField(name) {
|
|
@@ -1327,10 +1381,14 @@ var LoomObjectType = class extends GraphQLObjectType {
|
|
|
1327
1381
|
mergeExtensions(extensions) {
|
|
1328
1382
|
this.extensions = deepMerge(this.extensions, extensions);
|
|
1329
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
|
+
}
|
|
1330
1388
|
extraFieldMap;
|
|
1331
1389
|
getFields() {
|
|
1332
1390
|
const fieldsBySuper = super.getFields();
|
|
1333
|
-
|
|
1391
|
+
this.collectedFieldNames();
|
|
1334
1392
|
const extraFields = provideWeaverContext(() => defineFieldMap(this.mapToFieldConfig(this.extraFields)), this.weaverContext);
|
|
1335
1393
|
if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) this.extraFieldMap = extraFields;
|
|
1336
1394
|
const answer = {
|
|
@@ -1514,7 +1572,7 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1514
1572
|
if (gqlObject != null) return gqlObject;
|
|
1515
1573
|
const loomObject = new LoomObjectType(gqlType, options);
|
|
1516
1574
|
context.loomObjectMap?.set(gqlType, loomObject);
|
|
1517
|
-
setAlias(loomObject, getAlias()
|
|
1575
|
+
context.setAlias(loomObject, getAlias());
|
|
1518
1576
|
return loomObject;
|
|
1519
1577
|
} else if (isListType(gqlType)) return new GraphQLList(getCacheType(gqlType.ofType, options));
|
|
1520
1578
|
else if (isNonNullType(gqlType)) return new GraphQLNonNull(getCacheType(gqlType.ofType, options));
|
|
@@ -1526,14 +1584,14 @@ function getCacheType(gqlType, options = {}) {
|
|
|
1526
1584
|
...config,
|
|
1527
1585
|
types: config.types.map((type, i) => getCacheType(type, {
|
|
1528
1586
|
...options,
|
|
1529
|
-
fieldName: options.fieldName ? `${options.fieldName}${i + 1}` : void 0
|
|
1587
|
+
fieldName: options.fieldName ? `${options.fieldName}Item${i + 1}` : void 0
|
|
1530
1588
|
}))
|
|
1531
1589
|
});
|
|
1532
1590
|
context.loomUnionMap?.set(gqlType, unionType);
|
|
1533
|
-
setAlias(unionType, getAlias()
|
|
1591
|
+
context.setAlias(unionType, getAlias());
|
|
1534
1592
|
return unionType;
|
|
1535
|
-
} else if (isEnumType(gqlType)) {
|
|
1536
|
-
setAlias(gqlType, getAlias()
|
|
1593
|
+
} else if (isEnumType(gqlType) || isInterfaceType(gqlType) || isScalarType(gqlType)) {
|
|
1594
|
+
context.setAlias(gqlType, getAlias());
|
|
1537
1595
|
return gqlType;
|
|
1538
1596
|
}
|
|
1539
1597
|
return gqlType;
|
|
@@ -1595,18 +1653,11 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1595
1653
|
return this;
|
|
1596
1654
|
}
|
|
1597
1655
|
addType(silk$1) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
if (isObjectType(gqlType$1)) {
|
|
1602
|
-
const existing = this.context.loomObjectMap.get(gqlType$1);
|
|
1603
|
-
if (existing != null) return existing;
|
|
1604
|
-
const extraObject = new LoomObjectType(gqlType$1, this.fieldOptions);
|
|
1605
|
-
this.context.loomObjectMap.set(gqlType$1, extraObject);
|
|
1606
|
-
return extraObject;
|
|
1607
|
-
} else if (isUnionType(gqlType$1) || isEnumType(gqlType$1)) return gqlType$1;
|
|
1608
|
-
throw new Error(`${gqlType$1?.name ?? gqlType$1.toString()} is not a named type`);
|
|
1656
|
+
let gqlType = provideWeaverContext(() => {
|
|
1657
|
+
const gqlType$1 = getGraphQLType(silk$1);
|
|
1658
|
+
return getCacheType(gqlType$1);
|
|
1609
1659
|
}, this.context);
|
|
1660
|
+
while (isNonNullType(gqlType) || isListType(gqlType)) gqlType = gqlType.ofType;
|
|
1610
1661
|
this.types.add(gqlType);
|
|
1611
1662
|
return this;
|
|
1612
1663
|
}
|
|
@@ -1631,8 +1682,8 @@ var GraphQLSchemaLoom = class GraphQLSchemaLoom {
|
|
|
1631
1682
|
let parentObject = (() => {
|
|
1632
1683
|
if (parent == null) return void 0;
|
|
1633
1684
|
let gqlType = getGraphQLType(parent);
|
|
1634
|
-
|
|
1635
|
-
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`);
|
|
1636
1687
|
const existing = this.context.loomObjectMap.get(gqlType);
|
|
1637
1688
|
if (existing != null) return existing;
|
|
1638
1689
|
const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
|
|
@@ -1756,4 +1807,4 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1756
1807
|
}
|
|
1757
1808
|
|
|
1758
1809
|
//#endregion
|
|
1759
|
-
export { AUTO_ALIASING, BaseChainFactory, ChainResolver, DERIVED_DEPENDENCIES, EasyDataLoader, FieldChainFactory, FieldFactoryWithResolve, GraphQLSchemaLoom, LoomDataLoader, LoomObjectType, MutationChainFactory, MutationFactoryWithResolve, OPERATION_OBJECT_NAMES, ObjectChainResolver, QueryChainFactory, QueryFactoryWithResolve, symbols_exports as SYMBOLS, SubscriptionChainFactory, applyMiddlewares, assignContextMap, capitalize, collectName, collectNames, createField, createInputParser, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, filterMiddlewares, getCacheType, getDeepResolvingFields, getFieldOptions, getGraphQLType, getMemoizationMap, getOperationOptions, getResolvingFields, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseResolvingFields, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
|
|
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 };
|