@gqloom/core 0.9.6 → 0.10.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.
@@ -276,16 +276,10 @@ declare class FieldChainFactory<TOutput extends GraphQLSilk = never, TInput exte
276
276
  * by batching them together and handling caching automatically.
277
277
  *
278
278
  * @template TParent - The parent type that extends GraphQLSilk
279
- * @param resolve - A function that handles batch loading of data. The function receives:
280
- * - When no input type is defined: An array of parent objects
281
- * - When input type is defined: An array of tuples containing [parent, input]
282
- * - An array of resolver payloads
279
+ * @param resolve - A function that handles batch loading of data.
283
280
  * @returns A GraphQL field resolver that implements batch loading
284
281
  */
285
- load<TParent extends GraphQLSilk>(resolve: (parameters: InferInputO<TInput> extends void | undefined ? InferParent<TParent, TDependencies>[] : [
286
- parent: InferParent<TParent, TDependencies>,
287
- input: InferInputO<TInput>
288
- ][], payloads: (ResolverPayload | undefined)[]) => MayPromise<StandardSchemaV1.InferOutput<TOutput>[]>): Field<TParent, TOutput, TInput, TDependencies>;
282
+ load<TParent extends GraphQLSilk>(resolve: (parents: InferParent<TParent, TDependencies>[], input: InferInputO<TInput>, payloads: (ResolverPayload | undefined)[]) => MayPromise<StandardSchemaV1.InferOutput<TOutput>[]>): Field<TParent, TOutput, TInput, TDependencies>;
289
283
  }
290
284
  type InferParent<TParent extends GraphQLSilk, TDependencies extends string[] | undefined = undefined> = TDependencies extends string[] ? RequireKeys<NonNullable<StandardSchemaV1.InferOutput<TParent>>, TDependencies[number]> : NonNullable<StandardSchemaV1.InferOutput<TParent>>;
291
285
  /**
@@ -451,13 +445,14 @@ declare class MutationFactoryWithResolve<TInputO, TOutput extends GraphQLSilk, T
451
445
  input<TInputNew extends GraphQLSilk<TInputO>>(input: TInputNew): MutationFactoryWithResolve<TInputO, TOutput, TInputNew>;
452
446
  output<TOutputNew extends GraphQLSilk>(output: TOutputNew, transform: (output: StandardSchemaV1.InferOutput<TOutput>) => MayPromise<StandardSchemaV1.InferOutput<TOutputNew>>): MutationFactoryWithResolve<TInputO, TOutputNew, TInput>;
453
447
  }
454
- declare class FieldFactoryWithResolve<TParent extends GraphQLSilk, TOutput extends GraphQLSilk> extends BaseChainFactory<Field<TParent, TOutput, undefined, string[] | undefined>> {
448
+ declare class FieldFactoryWithResolve<TParent extends GraphQLSilk, TOutput extends GraphQLSilk, TInputO = never, TInput extends GraphQLSilk<TInputO> | void = void> extends BaseChainFactory<Field<TParent, TOutput, TInput, string[] | undefined>> {
455
449
  protected outputSilk: TOutput;
456
- protected readonly options: FieldOptions<TParent, TOutput, undefined, string[] | undefined>;
457
- get "~meta"(): Field<TParent, TOutput, undefined, string[] | undefined>["~meta"];
458
- constructor(outputSilk: TOutput, options: FieldOptions<TParent, TOutput, undefined, string[] | undefined>);
450
+ protected readonly options: FieldOptions<TParent, TOutput, TInput, string[] | undefined>;
451
+ get "~meta"(): Field<TParent, TOutput, TInput, string[] | undefined>["~meta"];
452
+ constructor(outputSilk: TOutput, options: FieldOptions<TParent, TOutput, TInput, string[] | undefined>);
459
453
  protected clone(options?: Partial<typeof this.options> | undefined): this;
460
- output<TOutputNew extends GraphQLSilk>(output: TOutputNew, transform: (output: StandardSchemaV1.InferOutput<TOutput>) => MayPromise<StandardSchemaV1.InferOutput<TOutputNew>>): FieldFactoryWithResolve<TParent, TOutputNew>;
454
+ input<TInputNew extends GraphQLSilk<TInputO>>(input: TInputNew): FieldFactoryWithResolve<TParent, TOutput, TInputO, TInputNew>;
455
+ output<TOutputNew extends GraphQLSilk>(output: TOutputNew, transform: (output: StandardSchemaV1.InferOutput<TOutput>) => MayPromise<StandardSchemaV1.InferOutput<TOutputNew>>): FieldFactoryWithResolve<TParent, TOutputNew, TInputO, TInput>;
461
456
  }
462
457
 
463
458
  interface FieldMeta extends GraphQLFieldOptions {
@@ -276,16 +276,10 @@ declare class FieldChainFactory<TOutput extends GraphQLSilk = never, TInput exte
276
276
  * by batching them together and handling caching automatically.
277
277
  *
278
278
  * @template TParent - The parent type that extends GraphQLSilk
279
- * @param resolve - A function that handles batch loading of data. The function receives:
280
- * - When no input type is defined: An array of parent objects
281
- * - When input type is defined: An array of tuples containing [parent, input]
282
- * - An array of resolver payloads
279
+ * @param resolve - A function that handles batch loading of data.
283
280
  * @returns A GraphQL field resolver that implements batch loading
284
281
  */
285
- load<TParent extends GraphQLSilk>(resolve: (parameters: InferInputO<TInput> extends void | undefined ? InferParent<TParent, TDependencies>[] : [
286
- parent: InferParent<TParent, TDependencies>,
287
- input: InferInputO<TInput>
288
- ][], payloads: (ResolverPayload | undefined)[]) => MayPromise<StandardSchemaV1.InferOutput<TOutput>[]>): Field<TParent, TOutput, TInput, TDependencies>;
282
+ load<TParent extends GraphQLSilk>(resolve: (parents: InferParent<TParent, TDependencies>[], input: InferInputO<TInput>, payloads: (ResolverPayload | undefined)[]) => MayPromise<StandardSchemaV1.InferOutput<TOutput>[]>): Field<TParent, TOutput, TInput, TDependencies>;
289
283
  }
290
284
  type InferParent<TParent extends GraphQLSilk, TDependencies extends string[] | undefined = undefined> = TDependencies extends string[] ? RequireKeys<NonNullable<StandardSchemaV1.InferOutput<TParent>>, TDependencies[number]> : NonNullable<StandardSchemaV1.InferOutput<TParent>>;
291
285
  /**
@@ -451,13 +445,14 @@ declare class MutationFactoryWithResolve<TInputO, TOutput extends GraphQLSilk, T
451
445
  input<TInputNew extends GraphQLSilk<TInputO>>(input: TInputNew): MutationFactoryWithResolve<TInputO, TOutput, TInputNew>;
452
446
  output<TOutputNew extends GraphQLSilk>(output: TOutputNew, transform: (output: StandardSchemaV1.InferOutput<TOutput>) => MayPromise<StandardSchemaV1.InferOutput<TOutputNew>>): MutationFactoryWithResolve<TInputO, TOutputNew, TInput>;
453
447
  }
454
- declare class FieldFactoryWithResolve<TParent extends GraphQLSilk, TOutput extends GraphQLSilk> extends BaseChainFactory<Field<TParent, TOutput, undefined, string[] | undefined>> {
448
+ declare class FieldFactoryWithResolve<TParent extends GraphQLSilk, TOutput extends GraphQLSilk, TInputO = never, TInput extends GraphQLSilk<TInputO> | void = void> extends BaseChainFactory<Field<TParent, TOutput, TInput, string[] | undefined>> {
455
449
  protected outputSilk: TOutput;
456
- protected readonly options: FieldOptions<TParent, TOutput, undefined, string[] | undefined>;
457
- get "~meta"(): Field<TParent, TOutput, undefined, string[] | undefined>["~meta"];
458
- constructor(outputSilk: TOutput, options: FieldOptions<TParent, TOutput, undefined, string[] | undefined>);
450
+ protected readonly options: FieldOptions<TParent, TOutput, TInput, string[] | undefined>;
451
+ get "~meta"(): Field<TParent, TOutput, TInput, string[] | undefined>["~meta"];
452
+ constructor(outputSilk: TOutput, options: FieldOptions<TParent, TOutput, TInput, string[] | undefined>);
459
453
  protected clone(options?: Partial<typeof this.options> | undefined): this;
460
- output<TOutputNew extends GraphQLSilk>(output: TOutputNew, transform: (output: StandardSchemaV1.InferOutput<TOutput>) => MayPromise<StandardSchemaV1.InferOutput<TOutputNew>>): FieldFactoryWithResolve<TParent, TOutputNew>;
454
+ input<TInputNew extends GraphQLSilk<TInputO>>(input: TInputNew): FieldFactoryWithResolve<TParent, TOutput, TInputO, TInputNew>;
455
+ output<TOutputNew extends GraphQLSilk>(output: TOutputNew, transform: (output: StandardSchemaV1.InferOutput<TOutput>) => MayPromise<StandardSchemaV1.InferOutput<TOutputNew>>): FieldFactoryWithResolve<TParent, TOutputNew, TInputO, TInput>;
461
456
  }
462
457
 
463
458
  interface FieldMeta extends GraphQLFieldOptions {
@@ -1,4 +1,4 @@
1
- import { P as OnlyMemoizationPayload, R as ResolverPayload, B as BaseField, v as Middleware, K as ResolvingFields } from './context-D0Bwgtgg.cjs';
1
+ import { P as OnlyMemoizationPayload, R as ResolverPayload, B as BaseField, v as Middleware, K as ResolvingFields } from './context-uzUlbx3r.cjs';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  import 'graphql';
4
4
 
package/dist/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as OnlyMemoizationPayload, R as ResolverPayload, B as BaseField, v as Middleware, K as ResolvingFields } from './context-D0Bwgtgg.js';
1
+ import { P as OnlyMemoizationPayload, R as ResolverPayload, B as BaseField, v as Middleware, K as ResolvingFields } from './context-uzUlbx3r.js';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  import 'graphql';
4
4
 
package/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ __export(src_exports, {
26
26
  FieldChainFactory: () => FieldChainFactory,
27
27
  FieldFactoryWithResolve: () => FieldFactoryWithResolve,
28
28
  GraphQLSchemaLoom: () => GraphQLSchemaLoom,
29
+ LoomDataLoader: () => LoomDataLoader,
29
30
  LoomObjectType: () => LoomObjectType,
30
31
  MutationChainFactory: () => MutationChainFactory,
31
32
  MutationFactoryWithResolve: () => MutationFactoryWithResolve,
@@ -410,48 +411,45 @@ function markLocation(message, ...locations) {
410
411
  }
411
412
 
412
413
  // src/utils/loader.ts
413
- var EasyDataLoader = class _EasyDataLoader {
414
- constructor(batchLoadFn) {
415
- this.batchLoadFn = batchLoadFn;
416
- this.queue = [];
417
- this.cache = /* @__PURE__ */ new Map();
414
+ var LoomDataLoader = class _LoomDataLoader {
415
+ results;
416
+ resolvers;
417
+ constructor() {
418
+ this.results = /* @__PURE__ */ new Map();
418
419
  this.resolvers = /* @__PURE__ */ new Map();
419
420
  }
420
- queue;
421
- cache;
422
- resolvers;
421
+ /**
422
+ * Load data for a given key.
423
+ * @param key - The key to load data for.
424
+ * @returns A promise that resolves to the loaded data.
425
+ */
423
426
  load(key) {
424
- const existing = this.cache.get(key);
427
+ const existing = this.results.get(key);
425
428
  if (existing) return existing;
426
429
  const promise = new Promise((resolve, reject) => {
427
- this.queue.push(key);
428
430
  this.resolvers.set(key, [resolve, reject]);
429
431
  this.nextTickBatchLoad();
430
432
  });
431
- this.cache.set(key, promise);
433
+ this.results.set(key, promise);
432
434
  return promise;
433
435
  }
436
+ /**
437
+ * Clear the cache and reset the loader.
438
+ */
434
439
  clear() {
435
- this.queue = [];
436
- this.cache = /* @__PURE__ */ new Map();
440
+ this.results = /* @__PURE__ */ new Map();
437
441
  this.resolvers = /* @__PURE__ */ new Map();
438
442
  }
439
- clearByKey(key) {
440
- this.queue = this.queue.filter((k) => k !== key);
441
- this.cache.delete(key);
442
- this.resolvers.delete(key);
443
- }
444
443
  async executeBatchLoad() {
445
- if (this.queue.length === 0) return;
446
- const [keys, resolvers] = [this.queue, this.resolvers];
447
- this.queue = [];
444
+ if (this.resolvers.size === 0) return;
445
+ const resolvers = this.resolvers;
448
446
  this.resolvers = /* @__PURE__ */ new Map();
447
+ const keys = Array.from(resolvers.keys());
449
448
  try {
450
- const list = await this.batchLoadFn(keys);
449
+ const list = await this.batchLoad(keys);
451
450
  for (let i = 0; i < list.length; i++) {
452
451
  const data = list[i];
453
- const resolve = resolvers.get(keys[i])?.[0];
454
- const reject = resolvers.get(keys[i])?.[1];
452
+ const [resolve, reject] = resolvers.get(keys[i]) ?? [];
455
453
  if (data instanceof Error) {
456
454
  reject?.(data);
457
455
  } else {
@@ -467,13 +465,32 @@ var EasyDataLoader = class _EasyDataLoader {
467
465
  }
468
466
  nextTickPromise;
469
467
  nextTickBatchLoad() {
470
- this.nextTickPromise ??= _EasyDataLoader.nextTick().then(() => this.executeBatchLoad()).finally(() => this.nextTickPromise = void 0);
468
+ const load = async () => {
469
+ try {
470
+ while (this.resolvers.size > 0) {
471
+ await _LoomDataLoader.nextTick();
472
+ await this.executeBatchLoad();
473
+ }
474
+ } finally {
475
+ this.nextTickPromise = void 0;
476
+ }
477
+ };
478
+ this.nextTickPromise ??= load();
471
479
  return this.nextTickPromise;
472
480
  }
473
481
  static nextTick() {
474
482
  return new Promise((resolve) => setTimeout(resolve));
475
483
  }
476
484
  };
485
+ var EasyDataLoader = class extends LoomDataLoader {
486
+ constructor(batchLoadFn) {
487
+ super();
488
+ this.batchLoadFn = batchLoadFn;
489
+ }
490
+ batchLoad(keys) {
491
+ return this.batchLoadFn(keys);
492
+ }
493
+ };
477
494
 
478
495
  // src/utils/symbols.ts
479
496
  var symbols_exports = {};
@@ -831,6 +848,38 @@ var BaseChainFactory = class _BaseChainFactory {
831
848
  });
832
849
  }
833
850
  };
851
+ var FieldLoader = class _FieldLoader extends LoomDataLoader {
852
+ constructor(resolve) {
853
+ super();
854
+ this.resolve = resolve;
855
+ }
856
+ static getByPath(payload, resolve, getByPath = true) {
857
+ if (!payload) return new _FieldLoader(resolve);
858
+ const memoMap = getMemoizationMap(payload);
859
+ if (!getByPath) {
860
+ const loader = memoMap.get(resolve) ?? new _FieldLoader(resolve);
861
+ memoMap.set(resolve, loader);
862
+ return loader;
863
+ }
864
+ const fullPath = [];
865
+ let path = payload.info.path;
866
+ while (path) {
867
+ fullPath.push(path);
868
+ path = path.prev;
869
+ }
870
+ const pathKey = fullPath.reverse().map((p) => typeof p.key === "number" ? "[n]" : p.key).join(".");
871
+ const fieldLoaders = memoMap.get(resolve) ?? /* @__PURE__ */ new Map();
872
+ memoMap.set(resolve, fieldLoaders);
873
+ const fieldLoader = fieldLoaders.get(pathKey) ?? new _FieldLoader(resolve);
874
+ fieldLoaders.set(pathKey, fieldLoader);
875
+ return fieldLoader;
876
+ }
877
+ batchLoad(args) {
878
+ const parents = args.map(([parent]) => parent);
879
+ const payloads = args.map(([, , payload]) => payload);
880
+ return this.resolve(parents, args[0]?.[1], payloads);
881
+ }
882
+ };
834
883
  var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
835
884
  /**
836
885
  * Returns the available methods for the field chain factory
@@ -893,31 +942,19 @@ var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
893
942
  * by batching them together and handling caching automatically.
894
943
  *
895
944
  * @template TParent - The parent type that extends GraphQLSilk
896
- * @param resolve - A function that handles batch loading of data. The function receives:
897
- * - When no input type is defined: An array of parent objects
898
- * - When input type is defined: An array of tuples containing [parent, input]
899
- * - An array of resolver payloads
945
+ * @param resolve - A function that handles batch loading of data.
900
946
  * @returns A GraphQL field resolver that implements batch loading
901
947
  */
902
948
  load(resolve) {
903
949
  if (!this.options?.output) throw new Error("Output is required");
904
- const hasInput = typeof this.options.input !== "undefined";
905
- const initLoader = () => new EasyDataLoader((args) => {
906
- const parents = args.map(
907
- ([parent, input]) => hasInput ? [parent, input] : parent
908
- );
909
- const payloads = args.map(([, , payload]) => payload);
910
- return resolve(parents, payloads);
911
- });
912
950
  return createField(this.options.output, {
913
951
  ...this.options,
914
952
  resolve: (parent, input, payload) => {
915
- const loader = (() => {
916
- if (!payload) return initLoader();
917
- const memoMap = getMemoizationMap(payload);
918
- if (!memoMap.has(resolve)) memoMap.set(resolve, initLoader());
919
- return memoMap.get(resolve);
920
- })();
953
+ const loader = FieldLoader.getByPath(
954
+ payload,
955
+ resolve,
956
+ this.options?.input != null
957
+ );
921
958
  return loader.load([parent, input, payload]);
922
959
  }
923
960
  });
@@ -1169,7 +1206,10 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
1169
1206
  this.options = options;
1170
1207
  }
1171
1208
  get "~meta"() {
1172
- return loom.field(this.outputSilk, this.options)["~meta"];
1209
+ return loom.field(
1210
+ this.outputSilk,
1211
+ this.options
1212
+ )["~meta"];
1173
1213
  }
1174
1214
  clone(options) {
1175
1215
  return new _FieldFactoryWithResolve(this.outputSilk, {
@@ -1177,6 +1217,12 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
1177
1217
  ...options
1178
1218
  });
1179
1219
  }
1220
+ input(input) {
1221
+ return new _FieldFactoryWithResolve(this.outputSilk, {
1222
+ ...this.options,
1223
+ input
1224
+ });
1225
+ }
1180
1226
  output(output, transform) {
1181
1227
  return new _FieldFactoryWithResolve(output, {
1182
1228
  ...this.options,
@@ -2041,6 +2087,7 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
2041
2087
  FieldChainFactory,
2042
2088
  FieldFactoryWithResolve,
2043
2089
  GraphQLSchemaLoom,
2090
+ LoomDataLoader,
2044
2091
  LoomObjectType,
2045
2092
  MutationChainFactory,
2046
2093
  MutationFactoryWithResolve,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldOptions, Q as QueryOptions, M as MutationOptions, R as ResolverPayload, S as SubscriptionOptions, G as GraphQLFieldOptions, a as StandardSchemaV1, b as GraphQLSilk, c as MayPromise, d as Query, e as QueryChainFactory, f as QueryFactoryWithChain, g as Mutation, h as MutationChainFactory, i as MutationFactoryWithChain, j as Field, k as FieldChainFactory, l as FieldFactoryWithUtils, m as SubscriptionChainFactory, n as Subscription, o as SubscriptionFactoryWithChain, O as Operation, p as FIELD_HIDDEN, q as ResolverOptionsWithExtensions, r as OmitInUnion, V as ValueOf, s as ResolverOptions, t as FieldOrOperation, u as Resolver, I as IS_RESOLVER, v as Middleware, w as InferInputI, W as WEAVER_CONFIG, B as BaseField } from './context-D0Bwgtgg.cjs';
2
- export { $ as BaseChainFactory, ai as CallableInputParser, D as CallableMiddlewareOptions, _ as ChainFactoryOptions, ae as FieldFactory, a4 as FieldFactoryWithResolve, ag as FieldMeta, a9 as FieldOrOperationType, Z as IChainFactory, aa as InferFieldInput, ab as InferFieldOutput, ah as InferInputO, y as IsAny, a5 as Loom, E as MiddlewareConfig, A as MiddlewareOperation, C as MiddlewareOptions, ad as MutationFactory, a3 as MutationFactoryWithResolve, P as OnlyMemoizationPayload, a8 as OperationType, ac as QueryFactory, a2 as QueryFactoryWithResolve, z as RequireKeys, a0 as ResolvableSubscription, a6 as ResolverOptionsWithParent, K as ResolvingFields, a7 as ResolvingOptions, x as SYMBOLS, af as SubscriptionFactory, a1 as SubscriptionNeedResolve, H as applyMiddlewares, Y as assignContextMap, aj as createInputParser, J as filterMiddlewares, X as getMemoizationMap, L as getResolvingFields, al as getStandardValue, U as isOnlyMemoryPayload, T as onlyMemoization, ak as parseInputValue, N as parseResolvingFields } from './context-D0Bwgtgg.cjs';
1
+ import { F as FieldOptions, Q as QueryOptions, M as MutationOptions, R as ResolverPayload, S as SubscriptionOptions, G as GraphQLFieldOptions, a as StandardSchemaV1, b as GraphQLSilk, c as MayPromise, d as Query, e as QueryChainFactory, f as QueryFactoryWithChain, g as Mutation, h as MutationChainFactory, i as MutationFactoryWithChain, j as Field, k as FieldChainFactory, l as FieldFactoryWithUtils, m as SubscriptionChainFactory, n as Subscription, o as SubscriptionFactoryWithChain, O as Operation, p as FIELD_HIDDEN, q as ResolverOptionsWithExtensions, r as OmitInUnion, V as ValueOf, s as ResolverOptions, t as FieldOrOperation, u as Resolver, I as IS_RESOLVER, v as Middleware, w as InferInputI, W as WEAVER_CONFIG, B as BaseField } from './context-uzUlbx3r.cjs';
2
+ export { $ as BaseChainFactory, ai as CallableInputParser, D as CallableMiddlewareOptions, _ as ChainFactoryOptions, ae as FieldFactory, a4 as FieldFactoryWithResolve, ag as FieldMeta, a9 as FieldOrOperationType, Z as IChainFactory, aa as InferFieldInput, ab as InferFieldOutput, ah as InferInputO, y as IsAny, a5 as Loom, E as MiddlewareConfig, A as MiddlewareOperation, C as MiddlewareOptions, ad as MutationFactory, a3 as MutationFactoryWithResolve, P as OnlyMemoizationPayload, a8 as OperationType, ac as QueryFactory, a2 as QueryFactoryWithResolve, z as RequireKeys, a0 as ResolvableSubscription, a6 as ResolverOptionsWithParent, K as ResolvingFields, a7 as ResolvingOptions, x as SYMBOLS, af as SubscriptionFactory, a1 as SubscriptionNeedResolve, H as applyMiddlewares, Y as assignContextMap, aj as createInputParser, J as filterMiddlewares, X as getMemoizationMap, L as getResolvingFields, al as getStandardValue, U as isOnlyMemoryPayload, T as onlyMemoization, ak as parseInputValue, N as parseResolvingFields } from './context-uzUlbx3r.cjs';
3
3
  import { GraphQLFieldExtensions, GraphQLScalarType, GraphQLObjectType, GraphQLOutputType, GraphQLNullableType, GraphQLList, GraphQLNonNull, GraphQLObjectTypeConfig, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLFieldMap, GraphQLFieldConfig, GraphQLSchemaConfig, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig } from 'graphql';
4
4
 
5
5
  declare function getOperationOptions(resolveOrOptions: ((...args: any) => any) | FieldOptions<any, any, any, any> | QueryOptions<any, any> | MutationOptions<any, any>): any;
@@ -271,23 +271,37 @@ declare function tryIn<T>(func: () => T, ...locations: string[]): T;
271
271
  declare function markLocation(message: string, ...locations: string[]): string;
272
272
 
273
273
  type BatchLoadFn<TKey, TData> = (keys: TKey[]) => Promise<(TData | Error)[]>;
274
- declare class EasyDataLoader<TKey, TData> {
275
- protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
276
- protected queue: TKey[];
277
- protected cache: Map<TKey, Promise<TData>>;
274
+ /**
275
+ * GraphQL Loom built-in data loader.
276
+ */
277
+ declare abstract class LoomDataLoader<TKey, TData> {
278
+ protected abstract batchLoad(keys: TKey[]): Promise<(TData | Error)[]>;
279
+ protected results: Map<TKey, Promise<TData>>;
278
280
  protected resolvers: Map<TKey, [
279
281
  resolve: (value: TData | PromiseLike<TData>) => void,
280
282
  reject: (reason?: any) => void
281
283
  ]>;
282
- constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
284
+ constructor();
285
+ /**
286
+ * Load data for a given key.
287
+ * @param key - The key to load data for.
288
+ * @returns A promise that resolves to the loaded data.
289
+ */
283
290
  load(key: TKey): Promise<TData>;
291
+ /**
292
+ * Clear the cache and reset the loader.
293
+ */
284
294
  clear(): void;
285
- clearByKey(key: TKey): void;
286
295
  protected executeBatchLoad(): Promise<void>;
287
296
  protected nextTickPromise?: Promise<void>;
288
297
  protected nextTickBatchLoad(): Promise<void>;
289
298
  static nextTick(): Promise<void>;
290
299
  }
300
+ declare class EasyDataLoader<TKey, TData> extends LoomDataLoader<TKey, TData> {
301
+ protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
302
+ protected batchLoad(keys: TKey[]): Promise<(TData | Error)[]>;
303
+ constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
304
+ }
291
305
 
292
306
  interface SchemaWeaver {
293
307
  vendor: string;
@@ -467,4 +481,4 @@ interface GQLoomExtensionAttribute {
467
481
  directives?: string[];
468
482
  }
469
483
 
470
- export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type Executor, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
484
+ export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type Executor, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomDataLoader, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldOptions, Q as QueryOptions, M as MutationOptions, R as ResolverPayload, S as SubscriptionOptions, G as GraphQLFieldOptions, a as StandardSchemaV1, b as GraphQLSilk, c as MayPromise, d as Query, e as QueryChainFactory, f as QueryFactoryWithChain, g as Mutation, h as MutationChainFactory, i as MutationFactoryWithChain, j as Field, k as FieldChainFactory, l as FieldFactoryWithUtils, m as SubscriptionChainFactory, n as Subscription, o as SubscriptionFactoryWithChain, O as Operation, p as FIELD_HIDDEN, q as ResolverOptionsWithExtensions, r as OmitInUnion, V as ValueOf, s as ResolverOptions, t as FieldOrOperation, u as Resolver, I as IS_RESOLVER, v as Middleware, w as InferInputI, W as WEAVER_CONFIG, B as BaseField } from './context-D0Bwgtgg.js';
2
- export { $ as BaseChainFactory, ai as CallableInputParser, D as CallableMiddlewareOptions, _ as ChainFactoryOptions, ae as FieldFactory, a4 as FieldFactoryWithResolve, ag as FieldMeta, a9 as FieldOrOperationType, Z as IChainFactory, aa as InferFieldInput, ab as InferFieldOutput, ah as InferInputO, y as IsAny, a5 as Loom, E as MiddlewareConfig, A as MiddlewareOperation, C as MiddlewareOptions, ad as MutationFactory, a3 as MutationFactoryWithResolve, P as OnlyMemoizationPayload, a8 as OperationType, ac as QueryFactory, a2 as QueryFactoryWithResolve, z as RequireKeys, a0 as ResolvableSubscription, a6 as ResolverOptionsWithParent, K as ResolvingFields, a7 as ResolvingOptions, x as SYMBOLS, af as SubscriptionFactory, a1 as SubscriptionNeedResolve, H as applyMiddlewares, Y as assignContextMap, aj as createInputParser, J as filterMiddlewares, X as getMemoizationMap, L as getResolvingFields, al as getStandardValue, U as isOnlyMemoryPayload, T as onlyMemoization, ak as parseInputValue, N as parseResolvingFields } from './context-D0Bwgtgg.js';
1
+ import { F as FieldOptions, Q as QueryOptions, M as MutationOptions, R as ResolverPayload, S as SubscriptionOptions, G as GraphQLFieldOptions, a as StandardSchemaV1, b as GraphQLSilk, c as MayPromise, d as Query, e as QueryChainFactory, f as QueryFactoryWithChain, g as Mutation, h as MutationChainFactory, i as MutationFactoryWithChain, j as Field, k as FieldChainFactory, l as FieldFactoryWithUtils, m as SubscriptionChainFactory, n as Subscription, o as SubscriptionFactoryWithChain, O as Operation, p as FIELD_HIDDEN, q as ResolverOptionsWithExtensions, r as OmitInUnion, V as ValueOf, s as ResolverOptions, t as FieldOrOperation, u as Resolver, I as IS_RESOLVER, v as Middleware, w as InferInputI, W as WEAVER_CONFIG, B as BaseField } from './context-uzUlbx3r.js';
2
+ export { $ as BaseChainFactory, ai as CallableInputParser, D as CallableMiddlewareOptions, _ as ChainFactoryOptions, ae as FieldFactory, a4 as FieldFactoryWithResolve, ag as FieldMeta, a9 as FieldOrOperationType, Z as IChainFactory, aa as InferFieldInput, ab as InferFieldOutput, ah as InferInputO, y as IsAny, a5 as Loom, E as MiddlewareConfig, A as MiddlewareOperation, C as MiddlewareOptions, ad as MutationFactory, a3 as MutationFactoryWithResolve, P as OnlyMemoizationPayload, a8 as OperationType, ac as QueryFactory, a2 as QueryFactoryWithResolve, z as RequireKeys, a0 as ResolvableSubscription, a6 as ResolverOptionsWithParent, K as ResolvingFields, a7 as ResolvingOptions, x as SYMBOLS, af as SubscriptionFactory, a1 as SubscriptionNeedResolve, H as applyMiddlewares, Y as assignContextMap, aj as createInputParser, J as filterMiddlewares, X as getMemoizationMap, L as getResolvingFields, al as getStandardValue, U as isOnlyMemoryPayload, T as onlyMemoization, ak as parseInputValue, N as parseResolvingFields } from './context-uzUlbx3r.js';
3
3
  import { GraphQLFieldExtensions, GraphQLScalarType, GraphQLObjectType, GraphQLOutputType, GraphQLNullableType, GraphQLList, GraphQLNonNull, GraphQLObjectTypeConfig, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLFieldMap, GraphQLFieldConfig, GraphQLSchemaConfig, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig } from 'graphql';
4
4
 
5
5
  declare function getOperationOptions(resolveOrOptions: ((...args: any) => any) | FieldOptions<any, any, any, any> | QueryOptions<any, any> | MutationOptions<any, any>): any;
@@ -271,23 +271,37 @@ declare function tryIn<T>(func: () => T, ...locations: string[]): T;
271
271
  declare function markLocation(message: string, ...locations: string[]): string;
272
272
 
273
273
  type BatchLoadFn<TKey, TData> = (keys: TKey[]) => Promise<(TData | Error)[]>;
274
- declare class EasyDataLoader<TKey, TData> {
275
- protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
276
- protected queue: TKey[];
277
- protected cache: Map<TKey, Promise<TData>>;
274
+ /**
275
+ * GraphQL Loom built-in data loader.
276
+ */
277
+ declare abstract class LoomDataLoader<TKey, TData> {
278
+ protected abstract batchLoad(keys: TKey[]): Promise<(TData | Error)[]>;
279
+ protected results: Map<TKey, Promise<TData>>;
278
280
  protected resolvers: Map<TKey, [
279
281
  resolve: (value: TData | PromiseLike<TData>) => void,
280
282
  reject: (reason?: any) => void
281
283
  ]>;
282
- constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
284
+ constructor();
285
+ /**
286
+ * Load data for a given key.
287
+ * @param key - The key to load data for.
288
+ * @returns A promise that resolves to the loaded data.
289
+ */
283
290
  load(key: TKey): Promise<TData>;
291
+ /**
292
+ * Clear the cache and reset the loader.
293
+ */
284
294
  clear(): void;
285
- clearByKey(key: TKey): void;
286
295
  protected executeBatchLoad(): Promise<void>;
287
296
  protected nextTickPromise?: Promise<void>;
288
297
  protected nextTickBatchLoad(): Promise<void>;
289
298
  static nextTick(): Promise<void>;
290
299
  }
300
+ declare class EasyDataLoader<TKey, TData> extends LoomDataLoader<TKey, TData> {
301
+ protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
302
+ protected batchLoad(keys: TKey[]): Promise<(TData | Error)[]>;
303
+ constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
304
+ }
291
305
 
292
306
  interface SchemaWeaver {
293
307
  vendor: string;
@@ -467,4 +481,4 @@ interface GQLoomExtensionAttribute {
467
481
  directives?: string[];
468
482
  }
469
483
 
470
- export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type Executor, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
484
+ export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type Executor, Field, FieldChainFactory, FieldFactoryWithUtils, FieldOptions, FieldOrOperation, type GQLoomExtensionAttribute, type GQLoomExtensions, type GlobalWeaverContext, GraphQLFieldOptions, GraphQLSchemaLoom, GraphQLSilk, InferInputI, type ListSilk, LoomDataLoader, LoomObjectType, MayPromise, Middleware, Mutation, MutationChainFactory, MutationFactoryWithChain, MutationOptions, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, ObjectChainResolver, OmitInUnion, Operation, Query, QueryChainFactory, QueryFactoryWithChain, QueryOptions, Resolver, type ResolverFactory, ResolverOptions, ResolverOptionsWithExtensions, ResolverPayload, type SchemaWeaver, StandardSchemaV1, Subscription, SubscriptionChainFactory, SubscriptionFactoryWithChain, SubscriptionOptions, type ToExecutorProps, ValueOf, type WeaverConfig, type WeaverContext, capitalize, collectName, collectNames, createField, createMutation, createQuery, createSubscription, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, meta, mutation, nonNullSilk, notNullish, nullableSilk, parseSilk, pascalCase, provideWeaverContext, query, resolver, screamingSnakeCase, silk, subscription, toObjMap, tryIn, weave, weaverContext };
package/dist/index.js CHANGED
@@ -169,48 +169,45 @@ function markLocation(message, ...locations) {
169
169
  }
170
170
 
171
171
  // src/utils/loader.ts
172
- var EasyDataLoader = class _EasyDataLoader {
173
- constructor(batchLoadFn) {
174
- this.batchLoadFn = batchLoadFn;
175
- this.queue = [];
176
- this.cache = /* @__PURE__ */ new Map();
172
+ var LoomDataLoader = class _LoomDataLoader {
173
+ results;
174
+ resolvers;
175
+ constructor() {
176
+ this.results = /* @__PURE__ */ new Map();
177
177
  this.resolvers = /* @__PURE__ */ new Map();
178
178
  }
179
- queue;
180
- cache;
181
- resolvers;
179
+ /**
180
+ * Load data for a given key.
181
+ * @param key - The key to load data for.
182
+ * @returns A promise that resolves to the loaded data.
183
+ */
182
184
  load(key) {
183
- const existing = this.cache.get(key);
185
+ const existing = this.results.get(key);
184
186
  if (existing) return existing;
185
187
  const promise = new Promise((resolve, reject) => {
186
- this.queue.push(key);
187
188
  this.resolvers.set(key, [resolve, reject]);
188
189
  this.nextTickBatchLoad();
189
190
  });
190
- this.cache.set(key, promise);
191
+ this.results.set(key, promise);
191
192
  return promise;
192
193
  }
194
+ /**
195
+ * Clear the cache and reset the loader.
196
+ */
193
197
  clear() {
194
- this.queue = [];
195
- this.cache = /* @__PURE__ */ new Map();
198
+ this.results = /* @__PURE__ */ new Map();
196
199
  this.resolvers = /* @__PURE__ */ new Map();
197
200
  }
198
- clearByKey(key) {
199
- this.queue = this.queue.filter((k) => k !== key);
200
- this.cache.delete(key);
201
- this.resolvers.delete(key);
202
- }
203
201
  async executeBatchLoad() {
204
- if (this.queue.length === 0) return;
205
- const [keys, resolvers] = [this.queue, this.resolvers];
206
- this.queue = [];
202
+ if (this.resolvers.size === 0) return;
203
+ const resolvers = this.resolvers;
207
204
  this.resolvers = /* @__PURE__ */ new Map();
205
+ const keys = Array.from(resolvers.keys());
208
206
  try {
209
- const list = await this.batchLoadFn(keys);
207
+ const list = await this.batchLoad(keys);
210
208
  for (let i = 0; i < list.length; i++) {
211
209
  const data = list[i];
212
- const resolve = resolvers.get(keys[i])?.[0];
213
- const reject = resolvers.get(keys[i])?.[1];
210
+ const [resolve, reject] = resolvers.get(keys[i]) ?? [];
214
211
  if (data instanceof Error) {
215
212
  reject?.(data);
216
213
  } else {
@@ -226,13 +223,32 @@ var EasyDataLoader = class _EasyDataLoader {
226
223
  }
227
224
  nextTickPromise;
228
225
  nextTickBatchLoad() {
229
- this.nextTickPromise ??= _EasyDataLoader.nextTick().then(() => this.executeBatchLoad()).finally(() => this.nextTickPromise = void 0);
226
+ const load = async () => {
227
+ try {
228
+ while (this.resolvers.size > 0) {
229
+ await _LoomDataLoader.nextTick();
230
+ await this.executeBatchLoad();
231
+ }
232
+ } finally {
233
+ this.nextTickPromise = void 0;
234
+ }
235
+ };
236
+ this.nextTickPromise ??= load();
230
237
  return this.nextTickPromise;
231
238
  }
232
239
  static nextTick() {
233
240
  return new Promise((resolve) => setTimeout(resolve));
234
241
  }
235
242
  };
243
+ var EasyDataLoader = class extends LoomDataLoader {
244
+ constructor(batchLoadFn) {
245
+ super();
246
+ this.batchLoadFn = batchLoadFn;
247
+ }
248
+ batchLoad(keys) {
249
+ return this.batchLoadFn(keys);
250
+ }
251
+ };
236
252
 
237
253
  // src/resolver/silk.ts
238
254
  import {
@@ -562,6 +578,38 @@ var BaseChainFactory = class _BaseChainFactory {
562
578
  });
563
579
  }
564
580
  };
581
+ var FieldLoader = class _FieldLoader extends LoomDataLoader {
582
+ constructor(resolve) {
583
+ super();
584
+ this.resolve = resolve;
585
+ }
586
+ static getByPath(payload, resolve, getByPath = true) {
587
+ if (!payload) return new _FieldLoader(resolve);
588
+ const memoMap = getMemoizationMap(payload);
589
+ if (!getByPath) {
590
+ const loader = memoMap.get(resolve) ?? new _FieldLoader(resolve);
591
+ memoMap.set(resolve, loader);
592
+ return loader;
593
+ }
594
+ const fullPath = [];
595
+ let path = payload.info.path;
596
+ while (path) {
597
+ fullPath.push(path);
598
+ path = path.prev;
599
+ }
600
+ const pathKey = fullPath.reverse().map((p) => typeof p.key === "number" ? "[n]" : p.key).join(".");
601
+ const fieldLoaders = memoMap.get(resolve) ?? /* @__PURE__ */ new Map();
602
+ memoMap.set(resolve, fieldLoaders);
603
+ const fieldLoader = fieldLoaders.get(pathKey) ?? new _FieldLoader(resolve);
604
+ fieldLoaders.set(pathKey, fieldLoader);
605
+ return fieldLoader;
606
+ }
607
+ batchLoad(args) {
608
+ const parents = args.map(([parent]) => parent);
609
+ const payloads = args.map(([, , payload]) => payload);
610
+ return this.resolve(parents, args[0]?.[1], payloads);
611
+ }
612
+ };
565
613
  var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
566
614
  /**
567
615
  * Returns the available methods for the field chain factory
@@ -624,31 +672,19 @@ var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
624
672
  * by batching them together and handling caching automatically.
625
673
  *
626
674
  * @template TParent - The parent type that extends GraphQLSilk
627
- * @param resolve - A function that handles batch loading of data. The function receives:
628
- * - When no input type is defined: An array of parent objects
629
- * - When input type is defined: An array of tuples containing [parent, input]
630
- * - An array of resolver payloads
675
+ * @param resolve - A function that handles batch loading of data.
631
676
  * @returns A GraphQL field resolver that implements batch loading
632
677
  */
633
678
  load(resolve) {
634
679
  if (!this.options?.output) throw new Error("Output is required");
635
- const hasInput = typeof this.options.input !== "undefined";
636
- const initLoader = () => new EasyDataLoader((args) => {
637
- const parents = args.map(
638
- ([parent, input]) => hasInput ? [parent, input] : parent
639
- );
640
- const payloads = args.map(([, , payload]) => payload);
641
- return resolve(parents, payloads);
642
- });
643
680
  return createField(this.options.output, {
644
681
  ...this.options,
645
682
  resolve: (parent, input, payload) => {
646
- const loader = (() => {
647
- if (!payload) return initLoader();
648
- const memoMap = getMemoizationMap(payload);
649
- if (!memoMap.has(resolve)) memoMap.set(resolve, initLoader());
650
- return memoMap.get(resolve);
651
- })();
683
+ const loader = FieldLoader.getByPath(
684
+ payload,
685
+ resolve,
686
+ this.options?.input != null
687
+ );
652
688
  return loader.load([parent, input, payload]);
653
689
  }
654
690
  });
@@ -900,7 +936,10 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
900
936
  this.options = options;
901
937
  }
902
938
  get "~meta"() {
903
- return loom.field(this.outputSilk, this.options)["~meta"];
939
+ return loom.field(
940
+ this.outputSilk,
941
+ this.options
942
+ )["~meta"];
904
943
  }
905
944
  clone(options) {
906
945
  return new _FieldFactoryWithResolve(this.outputSilk, {
@@ -908,6 +947,12 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
908
947
  ...options
909
948
  });
910
949
  }
950
+ input(input) {
951
+ return new _FieldFactoryWithResolve(this.outputSilk, {
952
+ ...this.options,
953
+ input
954
+ });
955
+ }
911
956
  output(output, transform) {
912
957
  return new _FieldFactoryWithResolve(output, {
913
958
  ...this.options,
@@ -1802,6 +1847,7 @@ export {
1802
1847
  FieldChainFactory,
1803
1848
  FieldFactoryWithResolve,
1804
1849
  GraphQLSchemaLoom,
1850
+ LoomDataLoader,
1805
1851
  LoomObjectType,
1806
1852
  MutationChainFactory,
1807
1853
  MutationFactoryWithResolve,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gqloom/core",
3
- "version": "0.9.6",
3
+ "version": "0.10.0",
4
4
  "description": "Create GraphQL schema and resolvers with TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",