@gqloom/core 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -21,22 +21,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  ContextMemoization: () => ContextMemoization,
24
+ EasyDataLoader: () => EasyDataLoader,
25
+ GraphQLSchemaLoom: () => GraphQLSchemaLoom,
24
26
  LoomObjectType: () => LoomObjectType,
27
+ OPERATION_OBJECT_NAMES: () => OPERATION_OBJECT_NAMES,
25
28
  ResolverOptionsMap: () => ResolverOptionsMap,
26
29
  SYMBOLS: () => symbols_exports,
27
- SchemaWeaver: () => SchemaWeaver,
28
30
  applyMiddlewares: () => applyMiddlewares,
29
31
  baseResolver: () => baseResolver,
32
+ capitalize: () => capitalize,
30
33
  collectName: () => collectName,
31
34
  collectNames: () => collectNames,
32
35
  compose: () => compose,
36
+ createField: () => createField,
33
37
  createFieldFactory: () => createFieldFactory,
34
38
  createInputParser: () => createInputParser,
35
39
  createLoom: () => createLoom,
36
40
  createMemoization: () => createMemoization,
41
+ createMutation: () => createMutation,
37
42
  createMutationFactory: () => createMutationFactory,
43
+ createQuery: () => createQuery,
38
44
  createQueryFactory: () => createQueryFactory,
39
45
  createResolverFactory: () => createResolverFactory,
46
+ createSubscription: () => createSubscription,
40
47
  createSubscriptionFactory: () => createSubscriptionFactory,
41
48
  deepMerge: () => deepMerge,
42
49
  defaultSubscriptionResolve: () => defaultSubscriptionResolve,
@@ -67,6 +74,7 @@ __export(src_exports, {
67
74
  onlyMemoization: () => onlyMemoization,
68
75
  parseInputValue: () => parseInputValue,
69
76
  parseSilk: () => parseSilk,
77
+ pascalCase: () => pascalCase,
70
78
  provideWeaverContext: () => provideWeaverContext,
71
79
  query: () => query,
72
80
  resolver: () => resolver,
@@ -263,7 +271,7 @@ function listSilk(origin) {
263
271
  [GET_GRAPHQL_TYPE]: () => {
264
272
  let originType = getGraphQLType(origin);
265
273
  if (originType instanceof import_graphql2.GraphQLNonNull && originType.ofType instanceof import_graphql2.GraphQLList) {
266
- originType = originType.ofType;
274
+ originType = originType.ofType.ofType;
267
275
  }
268
276
  if (originType instanceof import_graphql2.GraphQLList) {
269
277
  originType = originType.ofType;
@@ -497,6 +505,16 @@ function deepMerge(...objects) {
497
505
  return result;
498
506
  }
499
507
 
508
+ // src/utils/string.ts
509
+ function pascalCase(str) {
510
+ return str.split(/[\s-_]+/).map(
511
+ (word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)
512
+ ).join("");
513
+ }
514
+ function capitalize(str) {
515
+ return str.slice(0, 1).toUpperCase() + str.slice(1);
516
+ }
517
+
500
518
  // src/utils/error.ts
501
519
  function markErrorLocation(error, ...locations) {
502
520
  if (error instanceof Error) {
@@ -525,6 +543,72 @@ function markLocation(message, ...locations) {
525
543
  return `[${combinedLocation}] ${newMessage}`;
526
544
  }
527
545
 
546
+ // src/utils/loader.ts
547
+ var EasyDataLoader = class _EasyDataLoader {
548
+ constructor(batchLoadFn) {
549
+ this.batchLoadFn = batchLoadFn;
550
+ this.queue = [];
551
+ this.cache = /* @__PURE__ */ new Map();
552
+ this.resolvers = /* @__PURE__ */ new Map();
553
+ }
554
+ queue;
555
+ cache;
556
+ resolvers;
557
+ load(key) {
558
+ const existing = this.cache.get(key);
559
+ if (existing) return existing;
560
+ const promise = new Promise((resolve, reject) => {
561
+ this.queue.push(key);
562
+ this.resolvers.set(key, [resolve, reject]);
563
+ this.nextTickBatchLoad();
564
+ });
565
+ this.cache.set(key, promise);
566
+ return promise;
567
+ }
568
+ clear() {
569
+ this.queue = [];
570
+ this.cache = /* @__PURE__ */ new Map();
571
+ this.resolvers = /* @__PURE__ */ new Map();
572
+ }
573
+ clearByKey(key) {
574
+ this.queue = this.queue.filter((k) => k !== key);
575
+ this.cache.delete(key);
576
+ this.resolvers.delete(key);
577
+ }
578
+ async executeBatchLoad() {
579
+ if (this.queue.length === 0) return;
580
+ const [keys, resolvers] = [this.queue, this.resolvers];
581
+ this.queue = [];
582
+ this.resolvers = /* @__PURE__ */ new Map();
583
+ try {
584
+ const list = await this.batchLoadFn(keys);
585
+ for (let i = 0; i < list.length; i++) {
586
+ const data = list[i];
587
+ const resolve = resolvers.get(keys[i])?.[0];
588
+ const reject = resolvers.get(keys[i])?.[1];
589
+ if (data instanceof Error) {
590
+ reject?.(data);
591
+ } else {
592
+ resolve?.(data);
593
+ }
594
+ }
595
+ } catch (error) {
596
+ for (const key of keys) {
597
+ const reject = resolvers.get(key)?.[1];
598
+ reject?.(error);
599
+ }
600
+ }
601
+ }
602
+ nextTickPromise;
603
+ nextTickBatchLoad() {
604
+ this.nextTickPromise ??= _EasyDataLoader.nextTick().then(() => this.executeBatchLoad()).finally(() => this.nextTickPromise = void 0);
605
+ return this.nextTickPromise;
606
+ }
607
+ static nextTick() {
608
+ return new Promise((resolve) => setTimeout(resolve));
609
+ }
610
+ };
611
+
528
612
  // src/resolver/input.ts
529
613
  var import_graphql3 = require("graphql");
530
614
  function createInputParser(schema, value) {
@@ -578,8 +662,168 @@ function getStandardValue(result) {
578
662
  else throw new import_graphql3.GraphQLError("Invalid input");
579
663
  }
580
664
 
665
+ // src/resolver/resolver-chain-factory.ts
666
+ var BaseChainFactory = class _BaseChainFactory {
667
+ constructor(options) {
668
+ this.options = options;
669
+ }
670
+ static methods() {
671
+ return {
672
+ description: _BaseChainFactory.prototype.description,
673
+ deprecationReason: _BaseChainFactory.prototype.deprecationReason,
674
+ extensions: _BaseChainFactory.prototype.extensions
675
+ };
676
+ }
677
+ description(description) {
678
+ return this.clone({ description });
679
+ }
680
+ deprecationReason(deprecationReason) {
681
+ return this.clone({ deprecationReason });
682
+ }
683
+ extensions(extensions) {
684
+ return this.clone({ extensions });
685
+ }
686
+ use(...middlewares) {
687
+ return this.clone({
688
+ middlewares: [...this.options?.middlewares ?? [], ...middlewares]
689
+ });
690
+ }
691
+ };
692
+ var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
693
+ static methods() {
694
+ return {
695
+ ...BaseChainFactory.methods(),
696
+ output: _FieldChainFactory.prototype.output,
697
+ input: _FieldChainFactory.prototype.input,
698
+ resolve: _FieldChainFactory.prototype.resolve,
699
+ clone: _FieldChainFactory.prototype.clone
700
+ };
701
+ }
702
+ clone(options) {
703
+ return new _FieldChainFactory({ ...this.options, ...options });
704
+ }
705
+ use(...middlewares) {
706
+ return super.use(...middlewares);
707
+ }
708
+ output(output) {
709
+ return new _FieldChainFactory({ ...this.options, output });
710
+ }
711
+ input(input) {
712
+ return new _FieldChainFactory({ ...this.options, input });
713
+ }
714
+ resolve(resolve) {
715
+ return createField(this.options?.output, {
716
+ ...this.options,
717
+ resolve
718
+ });
719
+ }
720
+ };
721
+ var QueryChainFactory = class _QueryChainFactory extends BaseChainFactory {
722
+ static methods() {
723
+ return {
724
+ ...BaseChainFactory.methods(),
725
+ output: _QueryChainFactory.prototype.output,
726
+ input: _QueryChainFactory.prototype.input,
727
+ resolve: _QueryChainFactory.prototype.resolve,
728
+ clone: _QueryChainFactory.prototype.clone
729
+ };
730
+ }
731
+ clone(options) {
732
+ return new _QueryChainFactory({ ...this.options, ...options });
733
+ }
734
+ use(...middlewares) {
735
+ return super.use(...middlewares);
736
+ }
737
+ output(output) {
738
+ return new _QueryChainFactory({ ...this.options, output });
739
+ }
740
+ input(input) {
741
+ return new _QueryChainFactory({ ...this.options, input });
742
+ }
743
+ resolve(resolve) {
744
+ return createQuery(this.options?.output, {
745
+ ...this.options,
746
+ resolve
747
+ });
748
+ }
749
+ };
750
+ var MutationChainFactory = class _MutationChainFactory extends BaseChainFactory {
751
+ static methods() {
752
+ return {
753
+ ...BaseChainFactory.methods(),
754
+ output: _MutationChainFactory.prototype.output,
755
+ input: _MutationChainFactory.prototype.input,
756
+ resolve: _MutationChainFactory.prototype.resolve,
757
+ clone: _MutationChainFactory.prototype.clone
758
+ };
759
+ }
760
+ clone(options) {
761
+ return new _MutationChainFactory({ ...this.options, ...options });
762
+ }
763
+ use(...middlewares) {
764
+ return super.use(...middlewares);
765
+ }
766
+ output(output) {
767
+ return new _MutationChainFactory({ ...this.options, output });
768
+ }
769
+ input(input) {
770
+ return new _MutationChainFactory({ ...this.options, input });
771
+ }
772
+ resolve(resolve) {
773
+ return createMutation(this.options?.output, {
774
+ ...this.options,
775
+ resolve
776
+ });
777
+ }
778
+ };
779
+ var SubscriptionChainFactory = class _SubscriptionChainFactory extends BaseChainFactory {
780
+ static methods() {
781
+ return {
782
+ ...BaseChainFactory.methods(),
783
+ output: _SubscriptionChainFactory.prototype.output,
784
+ input: _SubscriptionChainFactory.prototype.input,
785
+ subscribe: _SubscriptionChainFactory.prototype.subscribe,
786
+ clone: _SubscriptionChainFactory.prototype.clone
787
+ };
788
+ }
789
+ clone(options) {
790
+ return new _SubscriptionChainFactory({ ...this.options, ...options });
791
+ }
792
+ use(...middlewares) {
793
+ return super.use(...middlewares);
794
+ }
795
+ output(output) {
796
+ return new _SubscriptionChainFactory({ ...this.options, output });
797
+ }
798
+ input(input) {
799
+ return new _SubscriptionChainFactory({ ...this.options, input });
800
+ }
801
+ subscribe(subscribe) {
802
+ const options = this.options;
803
+ const subscription2 = createSubscription(options?.output, {
804
+ ...options,
805
+ subscribe
806
+ });
807
+ const subscriptionResolve = subscription2.resolve;
808
+ const resolve = (...args) => {
809
+ if (args.length === 1 && typeof args[0] === "function") {
810
+ return createSubscription(options?.output, {
811
+ ...options,
812
+ resolve: args[0],
813
+ subscribe
814
+ });
815
+ }
816
+ return subscriptionResolve(...args);
817
+ };
818
+ return Object.assign(subscription2, { resolve });
819
+ }
820
+ };
821
+
581
822
  // src/resolver/resolver.ts
582
- var query = (output, resolveOrOptions) => {
823
+ var createQuery = (output, resolveOrOptions) => {
824
+ if (resolveOrOptions == null) {
825
+ return new QueryChainFactory({ output });
826
+ }
583
827
  const options = getOperationOptions(resolveOrOptions);
584
828
  const type = "query";
585
829
  return {
@@ -597,7 +841,14 @@ var query = (output, resolveOrOptions) => {
597
841
  type
598
842
  };
599
843
  };
600
- var mutation = (output, resolveOrOptions) => {
844
+ var query = Object.assign(
845
+ createQuery,
846
+ QueryChainFactory.methods()
847
+ );
848
+ var createMutation = (output, resolveOrOptions) => {
849
+ if (resolveOrOptions == null) {
850
+ return new MutationChainFactory({ output });
851
+ }
601
852
  const options = getOperationOptions(resolveOrOptions);
602
853
  const type = "mutation";
603
854
  return {
@@ -615,7 +866,14 @@ var mutation = (output, resolveOrOptions) => {
615
866
  type
616
867
  };
617
868
  };
618
- var baseSilkField = (output, resolveOrOptions) => {
869
+ var mutation = Object.assign(
870
+ createMutation,
871
+ MutationChainFactory.methods()
872
+ );
873
+ var createField = (output, resolveOrOptions) => {
874
+ if (resolveOrOptions == null) {
875
+ return new FieldChainFactory({ output });
876
+ }
619
877
  const options = getOperationOptions(resolveOrOptions);
620
878
  const type = "field";
621
879
  return {
@@ -634,13 +892,15 @@ var baseSilkField = (output, resolveOrOptions) => {
634
892
  };
635
893
  };
636
894
  var field = Object.assign(
637
- baseSilkField,
638
- {
639
- hidden: FIELD_HIDDEN
640
- }
895
+ createField,
896
+ { hidden: FIELD_HIDDEN },
897
+ FieldChainFactory.methods()
641
898
  );
642
899
  var defaultSubscriptionResolve = (source) => source;
643
- var subscription = (output, subscribeOrOptions) => {
900
+ var createSubscription = (output, subscribeOrOptions) => {
901
+ if (subscribeOrOptions == null) {
902
+ return new SubscriptionChainFactory({ output });
903
+ }
644
904
  const options = getSubscriptionOptions(subscribeOrOptions);
645
905
  const type = "subscription";
646
906
  return {
@@ -662,6 +922,10 @@ var subscription = (output, subscribeOrOptions) => {
662
922
  type
663
923
  };
664
924
  };
925
+ var subscription = Object.assign(
926
+ createSubscription,
927
+ SubscriptionChainFactory.methods()
928
+ );
665
929
  var ResolverOptionsMap = /* @__PURE__ */ new WeakMap();
666
930
  function baseResolver(operations, options) {
667
931
  const record = {};
@@ -742,6 +1006,9 @@ function createResolverFactory(toSilk) {
742
1006
  }
743
1007
  function createFieldFactory(toSilk, isSchema) {
744
1008
  const baseFieldFunc = (output, resolveOrOptions) => {
1009
+ if (resolveOrOptions == null) {
1010
+ return new FieldChainFactory({ output: toSilk(output) });
1011
+ }
745
1012
  const options = getOperationOptions(
746
1013
  resolveOrOptions
747
1014
  );
@@ -750,12 +1017,17 @@ function createFieldFactory(toSilk, isSchema) {
750
1017
  input: toSilkInput(options.input, toSilk, isSchema)
751
1018
  });
752
1019
  };
753
- return Object.assign(baseFieldFunc, {
754
- hidden: FIELD_HIDDEN
755
- });
1020
+ return Object.assign(
1021
+ baseFieldFunc,
1022
+ { hidden: FIELD_HIDDEN },
1023
+ FieldChainFactory.methods()
1024
+ );
756
1025
  }
757
1026
  function createQueryFactory(toSilk, isSchema) {
758
1027
  return (output, resolveOrOptions) => {
1028
+ if (resolveOrOptions == null) {
1029
+ return new QueryChainFactory({ output: toSilk(output) });
1030
+ }
759
1031
  const options = getOperationOptions(resolveOrOptions);
760
1032
  return query(toSilk(output), {
761
1033
  ...options,
@@ -765,6 +1037,9 @@ function createQueryFactory(toSilk, isSchema) {
765
1037
  }
766
1038
  function createMutationFactory(toSilk, isSchema) {
767
1039
  return (output, resolveOrOptions) => {
1040
+ if (resolveOrOptions == null) {
1041
+ return new MutationChainFactory({ output: toSilk(output) });
1042
+ }
768
1043
  const options = getOperationOptions(resolveOrOptions);
769
1044
  return mutation(toSilk(output), {
770
1045
  ...options,
@@ -774,6 +1049,9 @@ function createMutationFactory(toSilk, isSchema) {
774
1049
  }
775
1050
  function createSubscriptionFactory(toSilk, isSchema) {
776
1051
  return (output, resolveOrOptions) => {
1052
+ if (resolveOrOptions == null) {
1053
+ return new SubscriptionChainFactory({ output: toSilk(output) });
1054
+ }
777
1055
  const options = getSubscriptionOptions(resolveOrOptions);
778
1056
  return subscription(toSilk(output), {
779
1057
  ...options,
@@ -796,31 +1074,38 @@ var import_graphql5 = require("graphql");
796
1074
 
797
1075
  // src/schema/input.ts
798
1076
  var import_graphql4 = require("graphql");
799
- function inputToArgs(input) {
1077
+ function inputToArgs(input, options) {
800
1078
  if (input === void 0) return void 0;
801
1079
  if (isSilk(input)) {
802
1080
  let inputType = getGraphQLType(input);
803
1081
  if ((0, import_graphql4.isNonNullType)(inputType)) inputType = inputType.ofType;
804
1082
  if ((0, import_graphql4.isObjectType)(inputType)) {
805
- return mapValue(
806
- inputType.toConfig().fields,
807
- (it) => toInputFieldConfig(it)
808
- );
1083
+ return mapValue(inputType.toConfig().fields, (it, key) => {
1084
+ let fieldName;
1085
+ if (options?.fieldName) {
1086
+ fieldName = `${pascalCase(options.fieldName)}${pascalCase(key)}`;
1087
+ }
1088
+ return toInputFieldConfig(it, { fieldName });
1089
+ });
809
1090
  }
810
1091
  throw new Error(`Cannot convert ${inputType.toString()} to input type`);
811
1092
  }
812
1093
  const args = {};
813
1094
  Object.entries(input).forEach(([name, field2]) => {
814
1095
  tryIn(() => {
1096
+ let fieldName;
1097
+ if (options?.fieldName) {
1098
+ fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
1099
+ }
815
1100
  args[name] = {
816
1101
  ...field2,
817
- type: ensureInputType(field2)
1102
+ type: ensureInputType(field2, { fieldName })
818
1103
  };
819
1104
  }, name);
820
1105
  });
821
1106
  return args;
822
1107
  }
823
- function ensureInputType(silkOrType) {
1108
+ function ensureInputType(silkOrType, options) {
824
1109
  const gqlType = (() => {
825
1110
  if (isSilk(silkOrType)) {
826
1111
  return getGraphQLType(silkOrType);
@@ -830,48 +1115,56 @@ function ensureInputType(silkOrType) {
830
1115
  if ((0, import_graphql4.isUnionType)(gqlType))
831
1116
  throw new Error(`Cannot convert union type ${gqlType.name} to input type`);
832
1117
  if ((0, import_graphql4.isNonNullType)(gqlType)) {
833
- return new import_graphql4.GraphQLNonNull(ensureInputType(gqlType.ofType));
1118
+ return new import_graphql4.GraphQLNonNull(ensureInputType(gqlType.ofType, options));
834
1119
  }
835
1120
  if ((0, import_graphql4.isListType)(gqlType)) {
836
- return new import_graphql4.GraphQLList(ensureInputType(gqlType.ofType));
1121
+ return new import_graphql4.GraphQLList(ensureInputType(gqlType.ofType, options));
837
1122
  }
838
1123
  if ((0, import_graphql4.isObjectType)(gqlType) || (0, import_graphql4.isInterfaceType)(gqlType))
839
- return ensureInputObjectType(gqlType);
1124
+ return ensureInputObjectType(gqlType, options);
840
1125
  return gqlType;
841
1126
  }
842
- function ensureInputObjectType(object) {
1127
+ function ensureInputObjectType(object, options) {
843
1128
  if ((0, import_graphql4.isInputObjectType)(object)) return object;
844
1129
  const existing = weaverContext.inputMap?.get(object);
845
1130
  if (existing != null) return existing;
846
- const {
847
- astNode: _,
848
- extensionASTNodes: __,
849
- fields,
850
- ...config
851
- } = object.toConfig();
852
- const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((name) => name);
1131
+ const { astNode, extensionASTNodes, fields, ...config } = object.toConfig();
1132
+ let name = object.name;
1133
+ if (name === LoomObjectType.AUTO_ALIASING) {
1134
+ name = `${pascalCase(options?.fieldName ?? "")}Input`;
1135
+ }
1136
+ const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n);
1137
+ name = getInputObjectName(name);
853
1138
  const input = new import_graphql4.GraphQLInputObjectType({
854
1139
  ...config,
855
- name: getInputObjectName(object.name),
1140
+ name,
856
1141
  fields: provideWeaverContext.inherit(
857
- () => mapValue(fields, (it) => toInputFieldConfig(it))
1142
+ () => mapValue(
1143
+ fields,
1144
+ (it, key) => toInputFieldConfig(it, {
1145
+ fieldName: inputFieldName(name) + pascalCase(key)
1146
+ })
1147
+ )
858
1148
  )
859
1149
  });
860
1150
  weaverContext.inputMap?.set(object, input);
861
1151
  return input;
862
1152
  }
863
- function toInputFieldConfig({
864
- astNode: _,
865
- resolve: _1,
866
- ...config
867
- }) {
868
- return { ...config, type: ensureInputType(config.type) };
1153
+ function toInputFieldConfig({ astNode, resolve, ...config }, options) {
1154
+ return { ...config, type: ensureInputType(config.type, options) };
1155
+ }
1156
+ function inputFieldName(name) {
1157
+ while (name.endsWith("Input")) {
1158
+ name = name.slice(0, -"Input".length);
1159
+ }
1160
+ return name;
869
1161
  }
870
1162
 
871
1163
  // src/schema/object.ts
872
- var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
1164
+ var LoomObjectType = class _LoomObjectType extends import_graphql5.GraphQLObjectType {
873
1165
  extraFields = /* @__PURE__ */ new Map();
874
1166
  hiddenFields = /* @__PURE__ */ new Set();
1167
+ static AUTO_ALIASING = "__gqloom_auto_aliasing";
875
1168
  weaverContext;
876
1169
  resolverOptions;
877
1170
  constructor(objectOrGetter, options = {}) {
@@ -888,6 +1181,28 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
888
1181
  super(config);
889
1182
  this.resolverOptions = options.resolverOptions;
890
1183
  this.weaverContext = options.weaverContext ?? initWeaverContext();
1184
+ if (this.name !== _LoomObjectType.AUTO_ALIASING) {
1185
+ this.hasExplicitName = true;
1186
+ }
1187
+ }
1188
+ hasExplicitName;
1189
+ _aliases = [];
1190
+ get aliases() {
1191
+ return this._aliases;
1192
+ }
1193
+ addAlias(name) {
1194
+ if (this.hasExplicitName) return;
1195
+ this._aliases.push(name);
1196
+ this.renameByAliases();
1197
+ }
1198
+ renameByAliases() {
1199
+ let name;
1200
+ for (const alias of this.aliases) {
1201
+ if (name === void 0 || alias.length < name.length) {
1202
+ name = alias;
1203
+ }
1204
+ }
1205
+ if (name) this.name = name;
891
1206
  }
892
1207
  hideField(name) {
893
1208
  this.hiddenFields.add(name);
@@ -905,8 +1220,8 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
905
1220
  extraFieldMap;
906
1221
  getFields() {
907
1222
  const fieldsBySuper = super.getFields();
908
- Object.values(fieldsBySuper).forEach(
909
- (field2) => field2.type = this.getCacheType(field2.type)
1223
+ Object.entries(fieldsBySuper).forEach(
1224
+ ([fieldName, field2]) => field2.type = this.getCacheType(field2.type, fieldName)
910
1225
  );
911
1226
  const extraFields = provideWeaverContext(
912
1227
  () => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
@@ -927,17 +1242,22 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
927
1242
  mapToFieldConfig(map) {
928
1243
  const record = {};
929
1244
  for (const [name, field2] of map.entries()) {
930
- record[name] = this.toFieldConfig(field2);
1245
+ record[name] = this.toFieldConfig(field2, name);
931
1246
  }
932
1247
  return record;
933
1248
  }
934
- toFieldConfig(field2) {
1249
+ toFieldConfig(field2, fieldName) {
935
1250
  try {
936
- const outputType = this.getCacheType(getGraphQLType(field2.output));
1251
+ const outputType = this.getCacheType(
1252
+ getGraphQLType(field2.output),
1253
+ fieldName
1254
+ );
937
1255
  return {
938
1256
  ...extract(field2),
939
1257
  type: outputType,
940
- args: inputToArgs(field2.input),
1258
+ args: inputToArgs(field2.input, {
1259
+ fieldName: fieldName ? parentName(this.name) + fieldName : void 0
1260
+ }),
941
1261
  ...this.provideForResolve(field2),
942
1262
  ...this.provideForSubscribe(field2)
943
1263
  };
@@ -970,8 +1290,8 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
970
1290
  )
971
1291
  };
972
1292
  }
973
- getCacheType(gqlType) {
974
- return getCacheType(gqlType, this.options);
1293
+ getCacheType(gqlType, fieldName) {
1294
+ return getCacheType(gqlType, { ...this.options, fieldName, parent: this });
975
1295
  }
976
1296
  get options() {
977
1297
  const { resolverOptions, weaverContext: weaverContext2 } = this;
@@ -1017,6 +1337,11 @@ function defineArguments(args) {
1017
1337
  astNode: argConfig.astNode
1018
1338
  }));
1019
1339
  }
1340
+ var OPERATION_OBJECT_NAMES = /* @__PURE__ */ new Set([
1341
+ "Query",
1342
+ "Mutation",
1343
+ "Subscription"
1344
+ ]);
1020
1345
  function getCacheType(gqlType, options = {}) {
1021
1346
  const context = options.weaverContext ?? weaverContext;
1022
1347
  if (gqlType instanceof LoomObjectType) return gqlType;
@@ -1025,6 +1350,11 @@ function getCacheType(gqlType, options = {}) {
1025
1350
  if (gqlObject != null) return gqlObject;
1026
1351
  const loomObject = new LoomObjectType(gqlType, options);
1027
1352
  context.loomObjectMap?.set(gqlType, loomObject);
1353
+ if (options.fieldName && options.parent) {
1354
+ loomObject.addAlias(
1355
+ parentName(options.parent.name) + pascalCase(options.fieldName)
1356
+ );
1357
+ }
1028
1358
  return loomObject;
1029
1359
  } else if ((0, import_graphql5.isListType)(gqlType)) {
1030
1360
  return new import_graphql5.GraphQLList(getCacheType(gqlType.ofType, options));
@@ -1045,8 +1375,12 @@ function getCacheType(gqlType, options = {}) {
1045
1375
  }
1046
1376
  return gqlType;
1047
1377
  }
1378
+ function parentName(name) {
1379
+ if (OPERATION_OBJECT_NAMES.has(name)) name = "";
1380
+ return name;
1381
+ }
1048
1382
 
1049
- // src/schema/schema-vendor-weaver.ts
1383
+ // src/schema/schema-weaver.ts
1050
1384
  function isSchemaVendorWeaver(some) {
1051
1385
  if (typeof some !== "object" && typeof some !== "function") return false;
1052
1386
  if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function")
@@ -1055,9 +1389,9 @@ function isSchemaVendorWeaver(some) {
1055
1389
  return true;
1056
1390
  }
1057
1391
 
1058
- // src/schema/schema-weaver.ts
1392
+ // src/schema/schema-loom.ts
1059
1393
  var import_graphql6 = require("graphql");
1060
- var SchemaWeaver = class _SchemaWeaver {
1394
+ var GraphQLSchemaLoom = class _GraphQLSchemaLoom {
1061
1395
  query;
1062
1396
  mutation;
1063
1397
  subscription;
@@ -1224,12 +1558,12 @@ var SchemaWeaver = class _SchemaWeaver {
1224
1558
  }
1225
1559
  /**
1226
1560
  * Weave a GraphQL Schema from resolvers
1227
- * @param inputs Resolvers, Global Middlewares or WeaverConfigs
1228
- * @returns GraphQ LSchema
1561
+ * @param inputs Resolvers, Global Middlewares, WeaverConfigs Or SchemaWeaver
1562
+ * @returns GraphQL Schema
1229
1563
  */
1230
1564
  static weave(...inputs) {
1231
- const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
1232
- const weaver = new _SchemaWeaver({}, context);
1565
+ const { context, configs, middlewares, resolvers, silks, weavers } = _GraphQLSchemaLoom.optionsFrom(...inputs);
1566
+ const weaver = new _GraphQLSchemaLoom({}, context);
1233
1567
  configs.forEach((it) => weaver.setConfig(it));
1234
1568
  weavers.forEach((it) => weaver.addVendor(it));
1235
1569
  middlewares.forEach((it) => weaver.use(it));
@@ -1238,7 +1572,7 @@ var SchemaWeaver = class _SchemaWeaver {
1238
1572
  return weaver.weaveGraphQLSchema();
1239
1573
  }
1240
1574
  };
1241
- var weave = SchemaWeaver.weave;
1575
+ var weave = GraphQLSchemaLoom.weave;
1242
1576
 
1243
1577
  // src/schema/interface.ts
1244
1578
  var import_graphql7 = require("graphql");
@@ -1268,22 +1602,29 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1268
1602
  // Annotate the CommonJS export names for ESM import in node:
1269
1603
  0 && (module.exports = {
1270
1604
  ContextMemoization,
1605
+ EasyDataLoader,
1606
+ GraphQLSchemaLoom,
1271
1607
  LoomObjectType,
1608
+ OPERATION_OBJECT_NAMES,
1272
1609
  ResolverOptionsMap,
1273
1610
  SYMBOLS,
1274
- SchemaWeaver,
1275
1611
  applyMiddlewares,
1276
1612
  baseResolver,
1613
+ capitalize,
1277
1614
  collectName,
1278
1615
  collectNames,
1279
1616
  compose,
1617
+ createField,
1280
1618
  createFieldFactory,
1281
1619
  createInputParser,
1282
1620
  createLoom,
1283
1621
  createMemoization,
1622
+ createMutation,
1284
1623
  createMutationFactory,
1624
+ createQuery,
1285
1625
  createQueryFactory,
1286
1626
  createResolverFactory,
1627
+ createSubscription,
1287
1628
  createSubscriptionFactory,
1288
1629
  deepMerge,
1289
1630
  defaultSubscriptionResolve,
@@ -1314,6 +1655,7 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1314
1655
  onlyMemoization,
1315
1656
  parseInputValue,
1316
1657
  parseSilk,
1658
+ pascalCase,
1317
1659
  provideWeaverContext,
1318
1660
  query,
1319
1661
  resolver,