@gqloom/core 0.9.7 → 0.10.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.
@@ -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 {
@@ -723,19 +718,19 @@ interface ResolvingFields {
723
718
  /**
724
719
  * Fields explicitly requested in the GraphQL query
725
720
  */
726
- requestedFields: Set<string>;
721
+ requestedFields: ReadonlySet<string>;
727
722
  /**
728
723
  * Fields that are derived from other fields (computed fields)
729
724
  */
730
- derivedFields: Set<string>;
725
+ derivedFields: ReadonlySet<string>;
731
726
  /**
732
727
  * Fields that derived fields depend on
733
728
  */
734
- derivedDependencies: Set<string>;
729
+ derivedDependencies: ReadonlySet<string>;
735
730
  /**
736
731
  * Final set of fields that need to be resolved, after processing derived fields
737
732
  */
738
- selectedFields: Set<string>;
733
+ selectedFields: ReadonlySet<string>;
739
734
  }
740
735
  /**
741
736
  * Analyzes and processes field resolution in a GraphQL query.
@@ -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 {
@@ -723,19 +718,19 @@ interface ResolvingFields {
723
718
  /**
724
719
  * Fields explicitly requested in the GraphQL query
725
720
  */
726
- requestedFields: Set<string>;
721
+ requestedFields: ReadonlySet<string>;
727
722
  /**
728
723
  * Fields that are derived from other fields (computed fields)
729
724
  */
730
- derivedFields: Set<string>;
725
+ derivedFields: ReadonlySet<string>;
731
726
  /**
732
727
  * Fields that derived fields depend on
733
728
  */
734
- derivedDependencies: Set<string>;
729
+ derivedDependencies: ReadonlySet<string>;
735
730
  /**
736
731
  * Final set of fields that need to be resolved, after processing derived fields
737
732
  */
738
- selectedFields: Set<string>;
733
+ selectedFields: ReadonlySet<string>;
739
734
  }
740
735
  /**
741
736
  * Analyzes and processes field resolution in a GraphQL query.
@@ -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-ljWuL8VA.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-ljWuL8VA.js';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  import 'graphql';
4
4
 
package/dist/index.cjs CHANGED
@@ -22,7 +22,7 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  BaseChainFactory: () => BaseChainFactory,
24
24
  ChainResolver: () => ChainResolver,
25
- EasyDataLoader: () => LoomDataLoader,
25
+ EasyDataLoader: () => EasyDataLoader,
26
26
  FieldChainFactory: () => FieldChainFactory,
27
27
  FieldFactoryWithResolve: () => FieldFactoryWithResolve,
28
28
  GraphQLSchemaLoom: () => GraphQLSchemaLoom,
@@ -412,13 +412,12 @@ function markLocation(message, ...locations) {
412
412
 
413
413
  // src/utils/loader.ts
414
414
  var LoomDataLoader = class _LoomDataLoader {
415
- constructor(batchLoadFn) {
416
- this.batchLoadFn = batchLoadFn;
415
+ results;
416
+ resolvers;
417
+ constructor() {
417
418
  this.results = /* @__PURE__ */ new Map();
418
419
  this.resolvers = /* @__PURE__ */ new Map();
419
420
  }
420
- results;
421
- resolvers;
422
421
  /**
423
422
  * Load data for a given key.
424
423
  * @param key - The key to load data for.
@@ -447,7 +446,7 @@ var LoomDataLoader = class _LoomDataLoader {
447
446
  this.resolvers = /* @__PURE__ */ new Map();
448
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
452
  const [resolve, reject] = resolvers.get(keys[i]) ?? [];
@@ -483,6 +482,15 @@ var LoomDataLoader = class _LoomDataLoader {
483
482
  return new Promise((resolve) => setTimeout(resolve));
484
483
  }
485
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
+ };
486
494
 
487
495
  // src/utils/symbols.ts
488
496
  var symbols_exports = {};
@@ -840,6 +848,38 @@ var BaseChainFactory = class _BaseChainFactory {
840
848
  });
841
849
  }
842
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
+ };
843
883
  var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
844
884
  /**
845
885
  * Returns the available methods for the field chain factory
@@ -902,31 +942,19 @@ var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
902
942
  * by batching them together and handling caching automatically.
903
943
  *
904
944
  * @template TParent - The parent type that extends GraphQLSilk
905
- * @param resolve - A function that handles batch loading of data. The function receives:
906
- * - When no input type is defined: An array of parent objects
907
- * - When input type is defined: An array of tuples containing [parent, input]
908
- * - An array of resolver payloads
945
+ * @param resolve - A function that handles batch loading of data.
909
946
  * @returns A GraphQL field resolver that implements batch loading
910
947
  */
911
948
  load(resolve) {
912
949
  if (!this.options?.output) throw new Error("Output is required");
913
- const hasInput = typeof this.options.input !== "undefined";
914
- const initLoader = () => new LoomDataLoader((args) => {
915
- const parents = args.map(
916
- ([parent, input]) => hasInput ? [parent, input] : parent
917
- );
918
- const payloads = args.map(([, , payload]) => payload);
919
- return resolve(parents, payloads);
920
- });
921
950
  return createField(this.options.output, {
922
951
  ...this.options,
923
952
  resolve: (parent, input, payload) => {
924
- const loader = (() => {
925
- if (!payload) return initLoader();
926
- const memoMap = getMemoizationMap(payload);
927
- if (!memoMap.has(resolve)) memoMap.set(resolve, initLoader());
928
- return memoMap.get(resolve);
929
- })();
953
+ const loader = FieldLoader.getByPath(
954
+ payload,
955
+ resolve,
956
+ this.options?.input != null
957
+ );
930
958
  return loader.load([parent, input, payload]);
931
959
  }
932
960
  });
@@ -1178,7 +1206,10 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
1178
1206
  this.options = options;
1179
1207
  }
1180
1208
  get "~meta"() {
1181
- return loom.field(this.outputSilk, this.options)["~meta"];
1209
+ return loom.field(
1210
+ this.outputSilk,
1211
+ this.options
1212
+ )["~meta"];
1182
1213
  }
1183
1214
  clone(options) {
1184
1215
  return new _FieldFactoryWithResolve(this.outputSilk, {
@@ -1186,6 +1217,12 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
1186
1217
  ...options
1187
1218
  });
1188
1219
  }
1220
+ input(input) {
1221
+ return new _FieldFactoryWithResolve(this.outputSilk, {
1222
+ ...this.options,
1223
+ input
1224
+ });
1225
+ }
1189
1226
  output(output, transform) {
1190
1227
  return new _FieldFactoryWithResolve(output, {
1191
1228
  ...this.options,
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-ljWuL8VA.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-ljWuL8VA.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;
@@ -274,14 +274,14 @@ type BatchLoadFn<TKey, TData> = (keys: TKey[]) => Promise<(TData | Error)[]>;
274
274
  /**
275
275
  * GraphQL Loom built-in data loader.
276
276
  */
277
- declare class LoomDataLoader<TKey, TData> {
278
- protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
277
+ declare abstract class LoomDataLoader<TKey, TData> {
278
+ protected abstract batchLoad(keys: TKey[]): Promise<(TData | Error)[]>;
279
279
  protected results: Map<TKey, Promise<TData>>;
280
280
  protected resolvers: Map<TKey, [
281
281
  resolve: (value: TData | PromiseLike<TData>) => void,
282
282
  reject: (reason?: any) => void
283
283
  ]>;
284
- constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
284
+ constructor();
285
285
  /**
286
286
  * Load data for a given key.
287
287
  * @param key - The key to load data for.
@@ -297,6 +297,11 @@ declare class LoomDataLoader<TKey, TData> {
297
297
  protected nextTickBatchLoad(): Promise<void>;
298
298
  static nextTick(): Promise<void>;
299
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
+ }
300
305
 
301
306
  interface SchemaWeaver {
302
307
  vendor: string;
@@ -476,4 +481,4 @@ interface GQLoomExtensionAttribute {
476
481
  directives?: string[];
477
482
  }
478
483
 
479
- export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, LoomDataLoader as 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 };
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-ljWuL8VA.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-ljWuL8VA.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;
@@ -274,14 +274,14 @@ type BatchLoadFn<TKey, TData> = (keys: TKey[]) => Promise<(TData | Error)[]>;
274
274
  /**
275
275
  * GraphQL Loom built-in data loader.
276
276
  */
277
- declare class LoomDataLoader<TKey, TData> {
278
- protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
277
+ declare abstract class LoomDataLoader<TKey, TData> {
278
+ protected abstract batchLoad(keys: TKey[]): Promise<(TData | Error)[]>;
279
279
  protected results: Map<TKey, Promise<TData>>;
280
280
  protected resolvers: Map<TKey, [
281
281
  resolve: (value: TData | PromiseLike<TData>) => void,
282
282
  reject: (reason?: any) => void
283
283
  ]>;
284
- constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
284
+ constructor();
285
285
  /**
286
286
  * Load data for a given key.
287
287
  * @param key - The key to load data for.
@@ -297,6 +297,11 @@ declare class LoomDataLoader<TKey, TData> {
297
297
  protected nextTickBatchLoad(): Promise<void>;
298
298
  static nextTick(): Promise<void>;
299
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
+ }
300
305
 
301
306
  interface SchemaWeaver {
302
307
  vendor: string;
@@ -476,4 +481,4 @@ interface GQLoomExtensionAttribute {
476
481
  directives?: string[];
477
482
  }
478
483
 
479
- export { BaseField, type BatchLoadFn, ChainResolver, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, LoomDataLoader as 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 };
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
@@ -170,13 +170,12 @@ function markLocation(message, ...locations) {
170
170
 
171
171
  // src/utils/loader.ts
172
172
  var LoomDataLoader = class _LoomDataLoader {
173
- constructor(batchLoadFn) {
174
- this.batchLoadFn = batchLoadFn;
173
+ results;
174
+ resolvers;
175
+ constructor() {
175
176
  this.results = /* @__PURE__ */ new Map();
176
177
  this.resolvers = /* @__PURE__ */ new Map();
177
178
  }
178
- results;
179
- resolvers;
180
179
  /**
181
180
  * Load data for a given key.
182
181
  * @param key - The key to load data for.
@@ -205,7 +204,7 @@ var LoomDataLoader = class _LoomDataLoader {
205
204
  this.resolvers = /* @__PURE__ */ new Map();
206
205
  const keys = Array.from(resolvers.keys());
207
206
  try {
208
- const list = await this.batchLoadFn(keys);
207
+ const list = await this.batchLoad(keys);
209
208
  for (let i = 0; i < list.length; i++) {
210
209
  const data = list[i];
211
210
  const [resolve, reject] = resolvers.get(keys[i]) ?? [];
@@ -241,6 +240,15 @@ var LoomDataLoader = class _LoomDataLoader {
241
240
  return new Promise((resolve) => setTimeout(resolve));
242
241
  }
243
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
+ };
244
252
 
245
253
  // src/resolver/silk.ts
246
254
  import {
@@ -570,6 +578,38 @@ var BaseChainFactory = class _BaseChainFactory {
570
578
  });
571
579
  }
572
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
+ };
573
613
  var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
574
614
  /**
575
615
  * Returns the available methods for the field chain factory
@@ -632,31 +672,19 @@ var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
632
672
  * by batching them together and handling caching automatically.
633
673
  *
634
674
  * @template TParent - The parent type that extends GraphQLSilk
635
- * @param resolve - A function that handles batch loading of data. The function receives:
636
- * - When no input type is defined: An array of parent objects
637
- * - When input type is defined: An array of tuples containing [parent, input]
638
- * - An array of resolver payloads
675
+ * @param resolve - A function that handles batch loading of data.
639
676
  * @returns A GraphQL field resolver that implements batch loading
640
677
  */
641
678
  load(resolve) {
642
679
  if (!this.options?.output) throw new Error("Output is required");
643
- const hasInput = typeof this.options.input !== "undefined";
644
- const initLoader = () => new LoomDataLoader((args) => {
645
- const parents = args.map(
646
- ([parent, input]) => hasInput ? [parent, input] : parent
647
- );
648
- const payloads = args.map(([, , payload]) => payload);
649
- return resolve(parents, payloads);
650
- });
651
680
  return createField(this.options.output, {
652
681
  ...this.options,
653
682
  resolve: (parent, input, payload) => {
654
- const loader = (() => {
655
- if (!payload) return initLoader();
656
- const memoMap = getMemoizationMap(payload);
657
- if (!memoMap.has(resolve)) memoMap.set(resolve, initLoader());
658
- return memoMap.get(resolve);
659
- })();
683
+ const loader = FieldLoader.getByPath(
684
+ payload,
685
+ resolve,
686
+ this.options?.input != null
687
+ );
660
688
  return loader.load([parent, input, payload]);
661
689
  }
662
690
  });
@@ -908,7 +936,10 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
908
936
  this.options = options;
909
937
  }
910
938
  get "~meta"() {
911
- return loom.field(this.outputSilk, this.options)["~meta"];
939
+ return loom.field(
940
+ this.outputSilk,
941
+ this.options
942
+ )["~meta"];
912
943
  }
913
944
  clone(options) {
914
945
  return new _FieldFactoryWithResolve(this.outputSilk, {
@@ -916,6 +947,12 @@ var FieldFactoryWithResolve = class _FieldFactoryWithResolve extends BaseChainFa
916
947
  ...options
917
948
  });
918
949
  }
950
+ input(input) {
951
+ return new _FieldFactoryWithResolve(this.outputSilk, {
952
+ ...this.options,
953
+ input
954
+ });
955
+ }
919
956
  output(output, transform) {
920
957
  return new _FieldFactoryWithResolve(output, {
921
958
  ...this.options,
@@ -1806,7 +1843,7 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1806
1843
  export {
1807
1844
  BaseChainFactory,
1808
1845
  ChainResolver,
1809
- LoomDataLoader as EasyDataLoader,
1846
+ EasyDataLoader,
1810
1847
  FieldChainFactory,
1811
1848
  FieldFactoryWithResolve,
1812
1849
  GraphQLSchemaLoom,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gqloom/core",
3
- "version": "0.9.7",
3
+ "version": "0.10.1",
4
4
  "description": "Create GraphQL schema and resolvers with TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",