@gqloom/core 0.5.0 → 0.6.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/README.md CHANGED
@@ -8,25 +8,24 @@ The design of GQLoom is inspired by [tRPC](https://trpc.io/), [TypeGraphQL](http
8
8
 
9
9
  ## Features
10
10
 
11
- - 🚀 GraphQL: flexible and efficient, reducing redundant data transfers;
12
- - 🔒 Robust type safety: enjoy intelligent hints at development time to detect potential problems at compile time;
13
- - 🔋 Ready to go: middleware, contexts, subscriptions, federated graphs are ready to go;
14
- - 🔮 No extra magic: no decorators, no metadata and reflection, no code generation, you just need JavaScript/TypeScript;
15
- - 🧩 Familiar schema libraries: use the schema libraries you already know (Zod, Yup, Valibot) to build GraphQL Schema and validate inputs;
16
- - 🧑‍💻 Develop happily: highly readable and semantic APIs designed to keep your code tidy;
11
+ * 🚀 GraphQL: flexible and efficient, reducing redundant data transfers;
12
+ * 🔒 Robust type safety: enjoy intelligent hints at development time to detect potential problems at compile time;
13
+ * 🔋 Ready to go: middleware, contexts, subscriptions, federated graphs are ready to go;
14
+ * 🔮 No extra magic: no decorators, no metadata and reflection, no code generation, you just need JavaScript/TypeScript;
15
+ * 🧩 Familiar schema libraries: use the schema libraries you already know (Zod, Yup, Valibot) to build GraphQL Schema and validate inputs;
16
+ * 🧑‍💻 Develop happily: highly readable and semantic APIs designed to keep your code tidy;
17
17
 
18
18
  ## Hello World
19
19
 
20
20
  ```ts
21
- import { resolver, query, weave } from "@gqloom/core"
22
- import { ValibotWeaver } from "@gqloom/valibot"
21
+ import { resolver, query, ValibotWeaver } from "@gqloom/valibot"
23
22
  import * as v from "valibot"
24
23
 
25
24
  const helloResolver = resolver({
26
25
  hello: query(v.string(), () => "world"),
27
26
  })
28
27
 
29
- export const schema = weave(ValibotWeaver, helloResolver)
28
+ export const schema = ValibotWeaver.weave(helloResolver)
30
29
  ```
31
30
 
32
31
  Read [Introduction](https://gqloom.dev/guide/introduction.html) to learn more about GQLoom.
package/dist/index.cjs CHANGED
@@ -21,10 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  ContextMemoization: () => ContextMemoization,
24
+ GraphQLSchemaLoom: () => GraphQLSchemaLoom,
24
25
  LoomObjectType: () => LoomObjectType,
26
+ OPERATION_OBJECT_NAMES: () => OPERATION_OBJECT_NAMES,
25
27
  ResolverOptionsMap: () => ResolverOptionsMap,
26
28
  SYMBOLS: () => symbols_exports,
27
- SchemaWeaver: () => SchemaWeaver,
28
29
  applyMiddlewares: () => applyMiddlewares,
29
30
  baseResolver: () => baseResolver,
30
31
  collectName: () => collectName,
@@ -67,6 +68,7 @@ __export(src_exports, {
67
68
  onlyMemoization: () => onlyMemoization,
68
69
  parseInputValue: () => parseInputValue,
69
70
  parseSilk: () => parseSilk,
71
+ pascalCase: () => pascalCase,
70
72
  provideWeaverContext: () => provideWeaverContext,
71
73
  query: () => query,
72
74
  resolver: () => resolver,
@@ -497,6 +499,13 @@ function deepMerge(...objects) {
497
499
  return result;
498
500
  }
499
501
 
502
+ // src/utils/string.ts
503
+ function pascalCase(str) {
504
+ return str.split(/[\s-_]+/).map(
505
+ (word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)
506
+ ).join("");
507
+ }
508
+
500
509
  // src/utils/error.ts
501
510
  function markErrorLocation(error, ...locations) {
502
511
  if (error instanceof Error) {
@@ -796,31 +805,38 @@ var import_graphql5 = require("graphql");
796
805
 
797
806
  // src/schema/input.ts
798
807
  var import_graphql4 = require("graphql");
799
- function inputToArgs(input) {
808
+ function inputToArgs(input, options) {
800
809
  if (input === void 0) return void 0;
801
810
  if (isSilk(input)) {
802
811
  let inputType = getGraphQLType(input);
803
812
  if ((0, import_graphql4.isNonNullType)(inputType)) inputType = inputType.ofType;
804
813
  if ((0, import_graphql4.isObjectType)(inputType)) {
805
- return mapValue(
806
- inputType.toConfig().fields,
807
- (it) => toInputFieldConfig(it)
808
- );
814
+ return mapValue(inputType.toConfig().fields, (it, key) => {
815
+ let fieldName;
816
+ if (options?.fieldName) {
817
+ fieldName = `${pascalCase(options.fieldName)}${pascalCase(key)}`;
818
+ }
819
+ return toInputFieldConfig(it, { fieldName });
820
+ });
809
821
  }
810
822
  throw new Error(`Cannot convert ${inputType.toString()} to input type`);
811
823
  }
812
824
  const args = {};
813
825
  Object.entries(input).forEach(([name, field2]) => {
814
826
  tryIn(() => {
827
+ let fieldName;
828
+ if (options?.fieldName) {
829
+ fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
830
+ }
815
831
  args[name] = {
816
832
  ...field2,
817
- type: ensureInputType(field2)
833
+ type: ensureInputType(field2, { fieldName })
818
834
  };
819
835
  }, name);
820
836
  });
821
837
  return args;
822
838
  }
823
- function ensureInputType(silkOrType) {
839
+ function ensureInputType(silkOrType, options) {
824
840
  const gqlType = (() => {
825
841
  if (isSilk(silkOrType)) {
826
842
  return getGraphQLType(silkOrType);
@@ -830,48 +846,56 @@ function ensureInputType(silkOrType) {
830
846
  if ((0, import_graphql4.isUnionType)(gqlType))
831
847
  throw new Error(`Cannot convert union type ${gqlType.name} to input type`);
832
848
  if ((0, import_graphql4.isNonNullType)(gqlType)) {
833
- return new import_graphql4.GraphQLNonNull(ensureInputType(gqlType.ofType));
849
+ return new import_graphql4.GraphQLNonNull(ensureInputType(gqlType.ofType, options));
834
850
  }
835
851
  if ((0, import_graphql4.isListType)(gqlType)) {
836
- return new import_graphql4.GraphQLList(ensureInputType(gqlType.ofType));
852
+ return new import_graphql4.GraphQLList(ensureInputType(gqlType.ofType, options));
837
853
  }
838
854
  if ((0, import_graphql4.isObjectType)(gqlType) || (0, import_graphql4.isInterfaceType)(gqlType))
839
- return ensureInputObjectType(gqlType);
855
+ return ensureInputObjectType(gqlType, options);
840
856
  return gqlType;
841
857
  }
842
- function ensureInputObjectType(object) {
858
+ function ensureInputObjectType(object, options) {
843
859
  if ((0, import_graphql4.isInputObjectType)(object)) return object;
844
860
  const existing = weaverContext.inputMap?.get(object);
845
861
  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);
862
+ const { astNode, extensionASTNodes, fields, ...config } = object.toConfig();
863
+ let name = object.name;
864
+ if (name === LoomObjectType.AUTO_ALIASING) {
865
+ name = `${pascalCase(options?.fieldName ?? "")}Input`;
866
+ }
867
+ const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n);
868
+ name = getInputObjectName(name);
853
869
  const input = new import_graphql4.GraphQLInputObjectType({
854
870
  ...config,
855
- name: getInputObjectName(object.name),
871
+ name,
856
872
  fields: provideWeaverContext.inherit(
857
- () => mapValue(fields, (it) => toInputFieldConfig(it))
873
+ () => mapValue(
874
+ fields,
875
+ (it, key) => toInputFieldConfig(it, {
876
+ fieldName: inputFieldName(name) + pascalCase(key)
877
+ })
878
+ )
858
879
  )
859
880
  });
860
881
  weaverContext.inputMap?.set(object, input);
861
882
  return input;
862
883
  }
863
- function toInputFieldConfig({
864
- astNode: _,
865
- resolve: _1,
866
- ...config
867
- }) {
868
- return { ...config, type: ensureInputType(config.type) };
884
+ function toInputFieldConfig({ astNode, resolve, ...config }, options) {
885
+ return { ...config, type: ensureInputType(config.type, options) };
886
+ }
887
+ function inputFieldName(name) {
888
+ while (name.endsWith("Input")) {
889
+ name = name.slice(0, -"Input".length);
890
+ }
891
+ return name;
869
892
  }
870
893
 
871
894
  // src/schema/object.ts
872
- var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
895
+ var LoomObjectType = class _LoomObjectType extends import_graphql5.GraphQLObjectType {
873
896
  extraFields = /* @__PURE__ */ new Map();
874
897
  hiddenFields = /* @__PURE__ */ new Set();
898
+ static AUTO_ALIASING = "__gqloom_auto_aliasing";
875
899
  weaverContext;
876
900
  resolverOptions;
877
901
  constructor(objectOrGetter, options = {}) {
@@ -888,6 +912,28 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
888
912
  super(config);
889
913
  this.resolverOptions = options.resolverOptions;
890
914
  this.weaverContext = options.weaverContext ?? initWeaverContext();
915
+ if (this.name !== _LoomObjectType.AUTO_ALIASING) {
916
+ this.hasExplicitName = true;
917
+ }
918
+ }
919
+ hasExplicitName;
920
+ _aliases = [];
921
+ get aliases() {
922
+ return this._aliases;
923
+ }
924
+ addAlias(name) {
925
+ if (this.hasExplicitName) return;
926
+ this._aliases.push(name);
927
+ this.renameByAliases();
928
+ }
929
+ renameByAliases() {
930
+ let name;
931
+ for (const alias of this.aliases) {
932
+ if (name === void 0 || alias.length < name.length) {
933
+ name = alias;
934
+ }
935
+ }
936
+ if (name) this.name = name;
891
937
  }
892
938
  hideField(name) {
893
939
  this.hiddenFields.add(name);
@@ -905,8 +951,8 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
905
951
  extraFieldMap;
906
952
  getFields() {
907
953
  const fieldsBySuper = super.getFields();
908
- Object.values(fieldsBySuper).forEach(
909
- (field2) => field2.type = this.getCacheType(field2.type)
954
+ Object.entries(fieldsBySuper).forEach(
955
+ ([fieldName, field2]) => field2.type = this.getCacheType(field2.type, fieldName)
910
956
  );
911
957
  const extraFields = provideWeaverContext(
912
958
  () => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
@@ -927,17 +973,22 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
927
973
  mapToFieldConfig(map) {
928
974
  const record = {};
929
975
  for (const [name, field2] of map.entries()) {
930
- record[name] = this.toFieldConfig(field2);
976
+ record[name] = this.toFieldConfig(field2, name);
931
977
  }
932
978
  return record;
933
979
  }
934
- toFieldConfig(field2) {
980
+ toFieldConfig(field2, fieldName) {
935
981
  try {
936
- const outputType = this.getCacheType(getGraphQLType(field2.output));
982
+ const outputType = this.getCacheType(
983
+ getGraphQLType(field2.output),
984
+ fieldName
985
+ );
937
986
  return {
938
987
  ...extract(field2),
939
988
  type: outputType,
940
- args: inputToArgs(field2.input),
989
+ args: inputToArgs(field2.input, {
990
+ fieldName: fieldName ? parentName(this.name) + fieldName : void 0
991
+ }),
941
992
  ...this.provideForResolve(field2),
942
993
  ...this.provideForSubscribe(field2)
943
994
  };
@@ -970,8 +1021,8 @@ var LoomObjectType = class extends import_graphql5.GraphQLObjectType {
970
1021
  )
971
1022
  };
972
1023
  }
973
- getCacheType(gqlType) {
974
- return getCacheType(gqlType, this.options);
1024
+ getCacheType(gqlType, fieldName) {
1025
+ return getCacheType(gqlType, { ...this.options, fieldName, parent: this });
975
1026
  }
976
1027
  get options() {
977
1028
  const { resolverOptions, weaverContext: weaverContext2 } = this;
@@ -1017,6 +1068,11 @@ function defineArguments(args) {
1017
1068
  astNode: argConfig.astNode
1018
1069
  }));
1019
1070
  }
1071
+ var OPERATION_OBJECT_NAMES = /* @__PURE__ */ new Set([
1072
+ "Query",
1073
+ "Mutation",
1074
+ "Subscription"
1075
+ ]);
1020
1076
  function getCacheType(gqlType, options = {}) {
1021
1077
  const context = options.weaverContext ?? weaverContext;
1022
1078
  if (gqlType instanceof LoomObjectType) return gqlType;
@@ -1025,6 +1081,11 @@ function getCacheType(gqlType, options = {}) {
1025
1081
  if (gqlObject != null) return gqlObject;
1026
1082
  const loomObject = new LoomObjectType(gqlType, options);
1027
1083
  context.loomObjectMap?.set(gqlType, loomObject);
1084
+ if (options.fieldName && options.parent) {
1085
+ loomObject.addAlias(
1086
+ parentName(options.parent.name) + pascalCase(options.fieldName)
1087
+ );
1088
+ }
1028
1089
  return loomObject;
1029
1090
  } else if ((0, import_graphql5.isListType)(gqlType)) {
1030
1091
  return new import_graphql5.GraphQLList(getCacheType(gqlType.ofType, options));
@@ -1045,8 +1106,12 @@ function getCacheType(gqlType, options = {}) {
1045
1106
  }
1046
1107
  return gqlType;
1047
1108
  }
1109
+ function parentName(name) {
1110
+ if (OPERATION_OBJECT_NAMES.has(name)) name = "";
1111
+ return name;
1112
+ }
1048
1113
 
1049
- // src/schema/schema-vendor-weaver.ts
1114
+ // src/schema/schema-weaver.ts
1050
1115
  function isSchemaVendorWeaver(some) {
1051
1116
  if (typeof some !== "object" && typeof some !== "function") return false;
1052
1117
  if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function")
@@ -1055,9 +1120,9 @@ function isSchemaVendorWeaver(some) {
1055
1120
  return true;
1056
1121
  }
1057
1122
 
1058
- // src/schema/schema-weaver.ts
1123
+ // src/schema/schema-loom.ts
1059
1124
  var import_graphql6 = require("graphql");
1060
- var SchemaWeaver = class _SchemaWeaver {
1125
+ var GraphQLSchemaLoom = class _GraphQLSchemaLoom {
1061
1126
  query;
1062
1127
  mutation;
1063
1128
  subscription;
@@ -1224,12 +1289,12 @@ var SchemaWeaver = class _SchemaWeaver {
1224
1289
  }
1225
1290
  /**
1226
1291
  * Weave a GraphQL Schema from resolvers
1227
- * @param inputs Resolvers, Global Middlewares or WeaverConfigs
1228
- * @returns GraphQ LSchema
1292
+ * @param inputs Resolvers, Global Middlewares, WeaverConfigs Or SchemaWeaver
1293
+ * @returns GraphQL Schema
1229
1294
  */
1230
1295
  static weave(...inputs) {
1231
- const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
1232
- const weaver = new _SchemaWeaver({}, context);
1296
+ const { context, configs, middlewares, resolvers, silks, weavers } = _GraphQLSchemaLoom.optionsFrom(...inputs);
1297
+ const weaver = new _GraphQLSchemaLoom({}, context);
1233
1298
  configs.forEach((it) => weaver.setConfig(it));
1234
1299
  weavers.forEach((it) => weaver.addVendor(it));
1235
1300
  middlewares.forEach((it) => weaver.use(it));
@@ -1238,7 +1303,7 @@ var SchemaWeaver = class _SchemaWeaver {
1238
1303
  return weaver.weaveGraphQLSchema();
1239
1304
  }
1240
1305
  };
1241
- var weave = SchemaWeaver.weave;
1306
+ var weave = GraphQLSchemaLoom.weave;
1242
1307
 
1243
1308
  // src/schema/interface.ts
1244
1309
  var import_graphql7 = require("graphql");
@@ -1268,10 +1333,11 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1268
1333
  // Annotate the CommonJS export names for ESM import in node:
1269
1334
  0 && (module.exports = {
1270
1335
  ContextMemoization,
1336
+ GraphQLSchemaLoom,
1271
1337
  LoomObjectType,
1338
+ OPERATION_OBJECT_NAMES,
1272
1339
  ResolverOptionsMap,
1273
1340
  SYMBOLS,
1274
- SchemaWeaver,
1275
1341
  applyMiddlewares,
1276
1342
  baseResolver,
1277
1343
  collectName,
@@ -1314,6 +1380,7 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1314
1380
  onlyMemoization,
1315
1381
  parseInputValue,
1316
1382
  parseSilk,
1383
+ pascalCase,
1317
1384
  provideWeaverContext,
1318
1385
  query,
1319
1386
  resolver,
package/dist/index.d.cts CHANGED
@@ -450,6 +450,8 @@ interface ReadOnlyObjMap<T> {
450
450
  readonly [key: string]: T;
451
451
  }
452
452
 
453
+ declare function pascalCase(str: string): string;
454
+
453
455
  declare function markErrorLocation<TError>(error: TError, ...locations: string[]): TError;
454
456
  declare function tryIn<T>(func: () => T, ...locations: string[]): T;
455
457
  /**
@@ -541,11 +543,11 @@ declare function createLoom<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema:
541
543
  subscription: SubscriptionFactory<TSchemaIO>;
542
544
  };
543
545
 
544
- interface SchemaVendorWeaver {
546
+ interface SchemaWeaver {
545
547
  vendor: string;
546
548
  getGraphQLType: (schema: any) => GraphQLOutputType;
547
549
  }
548
- declare function isSchemaVendorWeaver(some: any): some is SchemaVendorWeaver;
550
+ declare function isSchemaVendorWeaver(some: any): some is SchemaWeaver;
549
551
 
550
552
  interface WeaverContext {
551
553
  id: number;
@@ -561,11 +563,11 @@ interface WeaverContext {
561
563
  memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlType: TGraphQLType): TGraphQLType;
562
564
  getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
563
565
  names: WeakMap<object, string>;
564
- vendorWeavers: Map<string, SchemaVendorWeaver>;
566
+ vendorWeavers: Map<string, SchemaWeaver>;
565
567
  }
566
568
  interface WeaverConfig {
567
569
  [WEAVER_CONFIG]: string | symbol;
568
- vendorWeaver?: SchemaVendorWeaver;
570
+ vendorWeaver?: SchemaWeaver;
569
571
  }
570
572
  declare function initWeaverContext(): WeaverContext;
571
573
  declare namespace initWeaverContext {
@@ -615,35 +617,44 @@ interface CoreSchemaWeaverConfig extends WeaverConfig, CoreSchemaWeaverConfigOpt
615
617
  declare class LoomObjectType extends GraphQLObjectType {
616
618
  protected extraFields: Map<string, SilkFieldOrOperation>;
617
619
  protected hiddenFields: Set<string>;
620
+ static AUTO_ALIASING: "__gqloom_auto_aliasing";
618
621
  protected weaverContext: WeaverContext;
619
622
  protected resolverOptions?: ResolvingOptions;
620
623
  constructor(objectOrGetter: string | GraphQLObjectType | GraphQLObjectTypeConfig<any, any> | (() => GraphQLObjectType | GraphQLObjectTypeConfig<any, any>), options?: {
621
624
  weaverContext?: WeaverContext;
622
625
  resolverOptions?: ResolvingOptions;
623
626
  });
627
+ protected hasExplicitName?: boolean;
628
+ protected _aliases: string[];
629
+ get aliases(): string[];
630
+ addAlias(name: string): void;
631
+ protected renameByAliases(): void;
624
632
  hideField(name: string): void;
625
633
  addField(name: string, resolver: SilkFieldOrOperation): void;
626
634
  mergeExtensions(extensions: GraphQLObjectTypeConfig<any, any>["extensions"]): void;
627
635
  private extraFieldMap?;
628
636
  getFields(): GraphQLFieldMap<any, any>;
629
637
  protected mapToFieldConfig(map: Map<string, SilkFieldOrOperation>): Record<string, GraphQLFieldConfig<any, any>>;
630
- toFieldConfig(field: SilkFieldOrOperation): GraphQLFieldConfig<any, any>;
638
+ toFieldConfig(field: SilkFieldOrOperation, fieldName?: string): GraphQLFieldConfig<any, any>;
631
639
  protected provideForResolve(field: SilkFieldOrOperation): Pick<GraphQLFieldConfig<any, any>, "resolve"> | undefined;
632
640
  protected provideForSubscribe(field: SilkFieldOrOperation): Pick<GraphQLFieldConfig<any, any>, "subscribe"> | undefined;
633
- protected getCacheType(gqlType: GraphQLOutputType): GraphQLOutputType;
641
+ protected getCacheType(gqlType: GraphQLOutputType, fieldName?: string): GraphQLOutputType;
634
642
  get options(): {
635
643
  resolverOptions: ResolvingOptions | undefined;
636
644
  weaverContext: WeaverContext;
637
645
  };
638
646
  }
647
+ declare const OPERATION_OBJECT_NAMES: Set<string>;
639
648
  declare function getCacheType(gqlType: GraphQLOutputType, options?: {
640
649
  weaverContext?: WeaverContext;
641
650
  resolverOptions?: ResolvingOptions;
651
+ fieldName?: string;
652
+ parent?: LoomObjectType;
642
653
  }): GraphQLOutputType;
643
654
 
644
655
  interface SchemaWeaverParameters extends Partial<Record<"query" | "mutation" | "subscription", LoomObjectType>>, Pick<GraphQLSchemaConfig, "types"> {
645
656
  }
646
- declare class SchemaWeaver {
657
+ declare class GraphQLSchemaLoom {
647
658
  query?: LoomObjectType;
648
659
  mutation?: LoomObjectType;
649
660
  subscription?: LoomObjectType;
@@ -659,7 +670,7 @@ declare class SchemaWeaver {
659
670
  constructor({ query, mutation, subscription, types }?: SchemaWeaverParameters, context?: WeaverContext);
660
671
  use(...middlewares: Middleware[]): this;
661
672
  add(resolver: SilkResolver): this;
662
- addVendor(weaver: SchemaVendorWeaver): this;
673
+ addVendor(weaver: SchemaWeaver): this;
663
674
  addType(silk: GraphQLSilk): this;
664
675
  setConfig<TConfig extends WeaverConfig>(config: TConfig): this;
665
676
  weaveGraphQLSchema(): GraphQLSchema;
@@ -669,31 +680,34 @@ declare class SchemaWeaver {
669
680
  resolverOptions: ResolvingOptions | undefined;
670
681
  weaverContext: WeaverContext;
671
682
  };
672
- static optionsFrom(...inputs: (SilkResolver | Middleware | SchemaVendorWeaver | WeaverConfig | GraphQLSilk)[]): {
683
+ static optionsFrom(...inputs: (SilkResolver | Middleware | SchemaWeaver | WeaverConfig | GraphQLSilk)[]): {
673
684
  context: WeaverContext | undefined;
674
685
  configs: Set<WeaverConfig>;
675
686
  middlewares: Set<Middleware>;
676
687
  resolvers: Set<SilkResolver>;
677
688
  silks: Set<GraphQLSilk<any, any>>;
678
- weavers: Set<SchemaVendorWeaver>;
689
+ weavers: Set<SchemaWeaver>;
679
690
  };
680
691
  /**
681
692
  * Weave a GraphQL Schema from resolvers
682
- * @param inputs Resolvers, Global Middlewares or WeaverConfigs
683
- * @returns GraphQ LSchema
693
+ * @param inputs Resolvers, Global Middlewares, WeaverConfigs Or SchemaWeaver
694
+ * @returns GraphQL Schema
684
695
  */
685
- static weave(...inputs: (SilkResolver | Middleware | SchemaVendorWeaver | WeaverConfig | GraphQLSilk)[]): GraphQLSchema;
696
+ static weave(...inputs: (SilkResolver | Middleware | SchemaWeaver | WeaverConfig | GraphQLSilk)[]): GraphQLSchema;
686
697
  }
687
698
  /**
688
699
  * Weave a GraphQL Schema from resolvers
689
700
  * @param inputs Resolvers, Global Middlewares or WeaverConfigs
690
701
  * @returns GraphQ LSchema
691
702
  */
692
- declare const weave: typeof SchemaWeaver.weave;
703
+ declare const weave: typeof GraphQLSchemaLoom.weave;
693
704
 
694
- declare function inputToArgs(input: InputSchema<GraphQLSilk>): GraphQLFieldConfigArgumentMap | undefined;
695
- declare function ensureInputType(silkOrType: GraphQLType | GraphQLSilk): GraphQLInputType;
696
- declare function ensureInputObjectType(object: GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType): GraphQLInputObjectType;
705
+ interface EnsureInputOptions {
706
+ fieldName?: string;
707
+ }
708
+ declare function inputToArgs(input: InputSchema<GraphQLSilk>, options: EnsureInputOptions | undefined): GraphQLFieldConfigArgumentMap | undefined;
709
+ declare function ensureInputType(silkOrType: GraphQLType | GraphQLSilk, options: EnsureInputOptions | undefined): GraphQLInputType;
710
+ declare function ensureInputObjectType(object: GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType, options: EnsureInputOptions | undefined): GraphQLInputObjectType;
697
711
 
698
712
  declare function ensureInterfaceType(gqlType: GraphQLOutputType, interfaceConfig?: Partial<GraphQLInterfaceTypeConfig<any, any>>): GraphQLInterfaceType;
699
713
 
@@ -711,4 +725,4 @@ interface GQLoomExtensionAttribute {
711
725
  directives?: string[];
712
726
  }
713
727
 
714
- export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaVendorWeaver, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
728
+ export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, GraphQLSchemaLoom, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, pascalCase, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
package/dist/index.d.ts CHANGED
@@ -450,6 +450,8 @@ interface ReadOnlyObjMap<T> {
450
450
  readonly [key: string]: T;
451
451
  }
452
452
 
453
+ declare function pascalCase(str: string): string;
454
+
453
455
  declare function markErrorLocation<TError>(error: TError, ...locations: string[]): TError;
454
456
  declare function tryIn<T>(func: () => T, ...locations: string[]): T;
455
457
  /**
@@ -541,11 +543,11 @@ declare function createLoom<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema:
541
543
  subscription: SubscriptionFactory<TSchemaIO>;
542
544
  };
543
545
 
544
- interface SchemaVendorWeaver {
546
+ interface SchemaWeaver {
545
547
  vendor: string;
546
548
  getGraphQLType: (schema: any) => GraphQLOutputType;
547
549
  }
548
- declare function isSchemaVendorWeaver(some: any): some is SchemaVendorWeaver;
550
+ declare function isSchemaVendorWeaver(some: any): some is SchemaWeaver;
549
551
 
550
552
  interface WeaverContext {
551
553
  id: number;
@@ -561,11 +563,11 @@ interface WeaverContext {
561
563
  memoNamedType<TGraphQLType extends GraphQLOutputType = GraphQLOutputType>(gqlType: TGraphQLType): TGraphQLType;
562
564
  getNamedType<T extends GraphQLOutputType>(name: string): T | undefined;
563
565
  names: WeakMap<object, string>;
564
- vendorWeavers: Map<string, SchemaVendorWeaver>;
566
+ vendorWeavers: Map<string, SchemaWeaver>;
565
567
  }
566
568
  interface WeaverConfig {
567
569
  [WEAVER_CONFIG]: string | symbol;
568
- vendorWeaver?: SchemaVendorWeaver;
570
+ vendorWeaver?: SchemaWeaver;
569
571
  }
570
572
  declare function initWeaverContext(): WeaverContext;
571
573
  declare namespace initWeaverContext {
@@ -615,35 +617,44 @@ interface CoreSchemaWeaverConfig extends WeaverConfig, CoreSchemaWeaverConfigOpt
615
617
  declare class LoomObjectType extends GraphQLObjectType {
616
618
  protected extraFields: Map<string, SilkFieldOrOperation>;
617
619
  protected hiddenFields: Set<string>;
620
+ static AUTO_ALIASING: "__gqloom_auto_aliasing";
618
621
  protected weaverContext: WeaverContext;
619
622
  protected resolverOptions?: ResolvingOptions;
620
623
  constructor(objectOrGetter: string | GraphQLObjectType | GraphQLObjectTypeConfig<any, any> | (() => GraphQLObjectType | GraphQLObjectTypeConfig<any, any>), options?: {
621
624
  weaverContext?: WeaverContext;
622
625
  resolverOptions?: ResolvingOptions;
623
626
  });
627
+ protected hasExplicitName?: boolean;
628
+ protected _aliases: string[];
629
+ get aliases(): string[];
630
+ addAlias(name: string): void;
631
+ protected renameByAliases(): void;
624
632
  hideField(name: string): void;
625
633
  addField(name: string, resolver: SilkFieldOrOperation): void;
626
634
  mergeExtensions(extensions: GraphQLObjectTypeConfig<any, any>["extensions"]): void;
627
635
  private extraFieldMap?;
628
636
  getFields(): GraphQLFieldMap<any, any>;
629
637
  protected mapToFieldConfig(map: Map<string, SilkFieldOrOperation>): Record<string, GraphQLFieldConfig<any, any>>;
630
- toFieldConfig(field: SilkFieldOrOperation): GraphQLFieldConfig<any, any>;
638
+ toFieldConfig(field: SilkFieldOrOperation, fieldName?: string): GraphQLFieldConfig<any, any>;
631
639
  protected provideForResolve(field: SilkFieldOrOperation): Pick<GraphQLFieldConfig<any, any>, "resolve"> | undefined;
632
640
  protected provideForSubscribe(field: SilkFieldOrOperation): Pick<GraphQLFieldConfig<any, any>, "subscribe"> | undefined;
633
- protected getCacheType(gqlType: GraphQLOutputType): GraphQLOutputType;
641
+ protected getCacheType(gqlType: GraphQLOutputType, fieldName?: string): GraphQLOutputType;
634
642
  get options(): {
635
643
  resolverOptions: ResolvingOptions | undefined;
636
644
  weaverContext: WeaverContext;
637
645
  };
638
646
  }
647
+ declare const OPERATION_OBJECT_NAMES: Set<string>;
639
648
  declare function getCacheType(gqlType: GraphQLOutputType, options?: {
640
649
  weaverContext?: WeaverContext;
641
650
  resolverOptions?: ResolvingOptions;
651
+ fieldName?: string;
652
+ parent?: LoomObjectType;
642
653
  }): GraphQLOutputType;
643
654
 
644
655
  interface SchemaWeaverParameters extends Partial<Record<"query" | "mutation" | "subscription", LoomObjectType>>, Pick<GraphQLSchemaConfig, "types"> {
645
656
  }
646
- declare class SchemaWeaver {
657
+ declare class GraphQLSchemaLoom {
647
658
  query?: LoomObjectType;
648
659
  mutation?: LoomObjectType;
649
660
  subscription?: LoomObjectType;
@@ -659,7 +670,7 @@ declare class SchemaWeaver {
659
670
  constructor({ query, mutation, subscription, types }?: SchemaWeaverParameters, context?: WeaverContext);
660
671
  use(...middlewares: Middleware[]): this;
661
672
  add(resolver: SilkResolver): this;
662
- addVendor(weaver: SchemaVendorWeaver): this;
673
+ addVendor(weaver: SchemaWeaver): this;
663
674
  addType(silk: GraphQLSilk): this;
664
675
  setConfig<TConfig extends WeaverConfig>(config: TConfig): this;
665
676
  weaveGraphQLSchema(): GraphQLSchema;
@@ -669,31 +680,34 @@ declare class SchemaWeaver {
669
680
  resolverOptions: ResolvingOptions | undefined;
670
681
  weaverContext: WeaverContext;
671
682
  };
672
- static optionsFrom(...inputs: (SilkResolver | Middleware | SchemaVendorWeaver | WeaverConfig | GraphQLSilk)[]): {
683
+ static optionsFrom(...inputs: (SilkResolver | Middleware | SchemaWeaver | WeaverConfig | GraphQLSilk)[]): {
673
684
  context: WeaverContext | undefined;
674
685
  configs: Set<WeaverConfig>;
675
686
  middlewares: Set<Middleware>;
676
687
  resolvers: Set<SilkResolver>;
677
688
  silks: Set<GraphQLSilk<any, any>>;
678
- weavers: Set<SchemaVendorWeaver>;
689
+ weavers: Set<SchemaWeaver>;
679
690
  };
680
691
  /**
681
692
  * Weave a GraphQL Schema from resolvers
682
- * @param inputs Resolvers, Global Middlewares or WeaverConfigs
683
- * @returns GraphQ LSchema
693
+ * @param inputs Resolvers, Global Middlewares, WeaverConfigs Or SchemaWeaver
694
+ * @returns GraphQL Schema
684
695
  */
685
- static weave(...inputs: (SilkResolver | Middleware | SchemaVendorWeaver | WeaverConfig | GraphQLSilk)[]): GraphQLSchema;
696
+ static weave(...inputs: (SilkResolver | Middleware | SchemaWeaver | WeaverConfig | GraphQLSilk)[]): GraphQLSchema;
686
697
  }
687
698
  /**
688
699
  * Weave a GraphQL Schema from resolvers
689
700
  * @param inputs Resolvers, Global Middlewares or WeaverConfigs
690
701
  * @returns GraphQ LSchema
691
702
  */
692
- declare const weave: typeof SchemaWeaver.weave;
703
+ declare const weave: typeof GraphQLSchemaLoom.weave;
693
704
 
694
- declare function inputToArgs(input: InputSchema<GraphQLSilk>): GraphQLFieldConfigArgumentMap | undefined;
695
- declare function ensureInputType(silkOrType: GraphQLType | GraphQLSilk): GraphQLInputType;
696
- declare function ensureInputObjectType(object: GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType): GraphQLInputObjectType;
705
+ interface EnsureInputOptions {
706
+ fieldName?: string;
707
+ }
708
+ declare function inputToArgs(input: InputSchema<GraphQLSilk>, options: EnsureInputOptions | undefined): GraphQLFieldConfigArgumentMap | undefined;
709
+ declare function ensureInputType(silkOrType: GraphQLType | GraphQLSilk, options: EnsureInputOptions | undefined): GraphQLInputType;
710
+ declare function ensureInputObjectType(object: GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType, options: EnsureInputOptions | undefined): GraphQLInputObjectType;
697
711
 
698
712
  declare function ensureInterfaceType(gqlType: GraphQLOutputType, interfaceConfig?: Partial<GraphQLInterfaceTypeConfig<any, any>>): GraphQLInterfaceType;
699
713
 
@@ -711,4 +725,4 @@ interface GQLoomExtensionAttribute {
711
725
  directives?: string[];
712
726
  }
713
727
 
714
- export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaVendorWeaver, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
728
+ export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, GraphQLSchemaLoom, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, pascalCase, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
package/dist/index.js CHANGED
@@ -426,6 +426,13 @@ function deepMerge(...objects) {
426
426
  return result;
427
427
  }
428
428
 
429
+ // src/utils/string.ts
430
+ function pascalCase(str) {
431
+ return str.split(/[\s-_]+/).map(
432
+ (word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)
433
+ ).join("");
434
+ }
435
+
429
436
  // src/utils/error.ts
430
437
  function markErrorLocation(error, ...locations) {
431
438
  if (error instanceof Error) {
@@ -746,31 +753,38 @@ import {
746
753
  isObjectType as isObjectType2,
747
754
  isUnionType as isUnionType2
748
755
  } from "graphql";
749
- function inputToArgs(input) {
756
+ function inputToArgs(input, options) {
750
757
  if (input === void 0) return void 0;
751
758
  if (isSilk(input)) {
752
759
  let inputType = getGraphQLType(input);
753
760
  if (isNonNullType(inputType)) inputType = inputType.ofType;
754
761
  if (isObjectType2(inputType)) {
755
- return mapValue(
756
- inputType.toConfig().fields,
757
- (it) => toInputFieldConfig(it)
758
- );
762
+ return mapValue(inputType.toConfig().fields, (it, key) => {
763
+ let fieldName;
764
+ if (options?.fieldName) {
765
+ fieldName = `${pascalCase(options.fieldName)}${pascalCase(key)}`;
766
+ }
767
+ return toInputFieldConfig(it, { fieldName });
768
+ });
759
769
  }
760
770
  throw new Error(`Cannot convert ${inputType.toString()} to input type`);
761
771
  }
762
772
  const args = {};
763
773
  Object.entries(input).forEach(([name, field2]) => {
764
774
  tryIn(() => {
775
+ let fieldName;
776
+ if (options?.fieldName) {
777
+ fieldName = `${pascalCase(options.fieldName)}${pascalCase(name)}`;
778
+ }
765
779
  args[name] = {
766
780
  ...field2,
767
- type: ensureInputType(field2)
781
+ type: ensureInputType(field2, { fieldName })
768
782
  };
769
783
  }, name);
770
784
  });
771
785
  return args;
772
786
  }
773
- function ensureInputType(silkOrType) {
787
+ function ensureInputType(silkOrType, options) {
774
788
  const gqlType = (() => {
775
789
  if (isSilk(silkOrType)) {
776
790
  return getGraphQLType(silkOrType);
@@ -780,48 +794,56 @@ function ensureInputType(silkOrType) {
780
794
  if (isUnionType2(gqlType))
781
795
  throw new Error(`Cannot convert union type ${gqlType.name} to input type`);
782
796
  if (isNonNullType(gqlType)) {
783
- return new GraphQLNonNull2(ensureInputType(gqlType.ofType));
797
+ return new GraphQLNonNull2(ensureInputType(gqlType.ofType, options));
784
798
  }
785
799
  if (isListType(gqlType)) {
786
- return new GraphQLList2(ensureInputType(gqlType.ofType));
800
+ return new GraphQLList2(ensureInputType(gqlType.ofType, options));
787
801
  }
788
802
  if (isObjectType2(gqlType) || isInterfaceType(gqlType))
789
- return ensureInputObjectType(gqlType);
803
+ return ensureInputObjectType(gqlType, options);
790
804
  return gqlType;
791
805
  }
792
- function ensureInputObjectType(object) {
806
+ function ensureInputObjectType(object, options) {
793
807
  if (isInputObjectType(object)) return object;
794
808
  const existing = weaverContext.inputMap?.get(object);
795
809
  if (existing != null) return existing;
796
- const {
797
- astNode: _,
798
- extensionASTNodes: __,
799
- fields,
800
- ...config
801
- } = object.toConfig();
802
- const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((name) => name);
810
+ const { astNode, extensionASTNodes, fields, ...config } = object.toConfig();
811
+ let name = object.name;
812
+ if (name === LoomObjectType.AUTO_ALIASING) {
813
+ name = `${pascalCase(options?.fieldName ?? "")}Input`;
814
+ }
815
+ const getInputObjectName = weaverContext.getConfig("gqloom.core.schema")?.getInputObjectName ?? ((n) => n);
816
+ name = getInputObjectName(name);
803
817
  const input = new GraphQLInputObjectType({
804
818
  ...config,
805
- name: getInputObjectName(object.name),
819
+ name,
806
820
  fields: provideWeaverContext.inherit(
807
- () => mapValue(fields, (it) => toInputFieldConfig(it))
821
+ () => mapValue(
822
+ fields,
823
+ (it, key) => toInputFieldConfig(it, {
824
+ fieldName: inputFieldName(name) + pascalCase(key)
825
+ })
826
+ )
808
827
  )
809
828
  });
810
829
  weaverContext.inputMap?.set(object, input);
811
830
  return input;
812
831
  }
813
- function toInputFieldConfig({
814
- astNode: _,
815
- resolve: _1,
816
- ...config
817
- }) {
818
- return { ...config, type: ensureInputType(config.type) };
832
+ function toInputFieldConfig({ astNode, resolve, ...config }, options) {
833
+ return { ...config, type: ensureInputType(config.type, options) };
834
+ }
835
+ function inputFieldName(name) {
836
+ while (name.endsWith("Input")) {
837
+ name = name.slice(0, -"Input".length);
838
+ }
839
+ return name;
819
840
  }
820
841
 
821
842
  // src/schema/object.ts
822
- var LoomObjectType = class extends GraphQLObjectType {
843
+ var LoomObjectType = class _LoomObjectType extends GraphQLObjectType {
823
844
  extraFields = /* @__PURE__ */ new Map();
824
845
  hiddenFields = /* @__PURE__ */ new Set();
846
+ static AUTO_ALIASING = "__gqloom_auto_aliasing";
825
847
  weaverContext;
826
848
  resolverOptions;
827
849
  constructor(objectOrGetter, options = {}) {
@@ -838,6 +860,28 @@ var LoomObjectType = class extends GraphQLObjectType {
838
860
  super(config);
839
861
  this.resolverOptions = options.resolverOptions;
840
862
  this.weaverContext = options.weaverContext ?? initWeaverContext();
863
+ if (this.name !== _LoomObjectType.AUTO_ALIASING) {
864
+ this.hasExplicitName = true;
865
+ }
866
+ }
867
+ hasExplicitName;
868
+ _aliases = [];
869
+ get aliases() {
870
+ return this._aliases;
871
+ }
872
+ addAlias(name) {
873
+ if (this.hasExplicitName) return;
874
+ this._aliases.push(name);
875
+ this.renameByAliases();
876
+ }
877
+ renameByAliases() {
878
+ let name;
879
+ for (const alias of this.aliases) {
880
+ if (name === void 0 || alias.length < name.length) {
881
+ name = alias;
882
+ }
883
+ }
884
+ if (name) this.name = name;
841
885
  }
842
886
  hideField(name) {
843
887
  this.hiddenFields.add(name);
@@ -855,8 +899,8 @@ var LoomObjectType = class extends GraphQLObjectType {
855
899
  extraFieldMap;
856
900
  getFields() {
857
901
  const fieldsBySuper = super.getFields();
858
- Object.values(fieldsBySuper).forEach(
859
- (field2) => field2.type = this.getCacheType(field2.type)
902
+ Object.entries(fieldsBySuper).forEach(
903
+ ([fieldName, field2]) => field2.type = this.getCacheType(field2.type, fieldName)
860
904
  );
861
905
  const extraFields = provideWeaverContext(
862
906
  () => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
@@ -877,17 +921,22 @@ var LoomObjectType = class extends GraphQLObjectType {
877
921
  mapToFieldConfig(map) {
878
922
  const record = {};
879
923
  for (const [name, field2] of map.entries()) {
880
- record[name] = this.toFieldConfig(field2);
924
+ record[name] = this.toFieldConfig(field2, name);
881
925
  }
882
926
  return record;
883
927
  }
884
- toFieldConfig(field2) {
928
+ toFieldConfig(field2, fieldName) {
885
929
  try {
886
- const outputType = this.getCacheType(getGraphQLType(field2.output));
930
+ const outputType = this.getCacheType(
931
+ getGraphQLType(field2.output),
932
+ fieldName
933
+ );
887
934
  return {
888
935
  ...extract(field2),
889
936
  type: outputType,
890
- args: inputToArgs(field2.input),
937
+ args: inputToArgs(field2.input, {
938
+ fieldName: fieldName ? parentName(this.name) + fieldName : void 0
939
+ }),
891
940
  ...this.provideForResolve(field2),
892
941
  ...this.provideForSubscribe(field2)
893
942
  };
@@ -920,8 +969,8 @@ var LoomObjectType = class extends GraphQLObjectType {
920
969
  )
921
970
  };
922
971
  }
923
- getCacheType(gqlType) {
924
- return getCacheType(gqlType, this.options);
972
+ getCacheType(gqlType, fieldName) {
973
+ return getCacheType(gqlType, { ...this.options, fieldName, parent: this });
925
974
  }
926
975
  get options() {
927
976
  const { resolverOptions, weaverContext: weaverContext2 } = this;
@@ -967,6 +1016,11 @@ function defineArguments(args) {
967
1016
  astNode: argConfig.astNode
968
1017
  }));
969
1018
  }
1019
+ var OPERATION_OBJECT_NAMES = /* @__PURE__ */ new Set([
1020
+ "Query",
1021
+ "Mutation",
1022
+ "Subscription"
1023
+ ]);
970
1024
  function getCacheType(gqlType, options = {}) {
971
1025
  const context = options.weaverContext ?? weaverContext;
972
1026
  if (gqlType instanceof LoomObjectType) return gqlType;
@@ -975,6 +1029,11 @@ function getCacheType(gqlType, options = {}) {
975
1029
  if (gqlObject != null) return gqlObject;
976
1030
  const loomObject = new LoomObjectType(gqlType, options);
977
1031
  context.loomObjectMap?.set(gqlType, loomObject);
1032
+ if (options.fieldName && options.parent) {
1033
+ loomObject.addAlias(
1034
+ parentName(options.parent.name) + pascalCase(options.fieldName)
1035
+ );
1036
+ }
978
1037
  return loomObject;
979
1038
  } else if (isListType2(gqlType)) {
980
1039
  return new GraphQLList3(getCacheType(gqlType.ofType, options));
@@ -995,8 +1054,12 @@ function getCacheType(gqlType, options = {}) {
995
1054
  }
996
1055
  return gqlType;
997
1056
  }
1057
+ function parentName(name) {
1058
+ if (OPERATION_OBJECT_NAMES.has(name)) name = "";
1059
+ return name;
1060
+ }
998
1061
 
999
- // src/schema/schema-vendor-weaver.ts
1062
+ // src/schema/schema-weaver.ts
1000
1063
  function isSchemaVendorWeaver(some) {
1001
1064
  if (typeof some !== "object" && typeof some !== "function") return false;
1002
1065
  if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function")
@@ -1005,7 +1068,7 @@ function isSchemaVendorWeaver(some) {
1005
1068
  return true;
1006
1069
  }
1007
1070
 
1008
- // src/schema/schema-weaver.ts
1071
+ // src/schema/schema-loom.ts
1009
1072
  import {
1010
1073
  GraphQLSchema,
1011
1074
  isEnumType as isEnumType2,
@@ -1013,7 +1076,7 @@ import {
1013
1076
  isObjectType as isObjectType4,
1014
1077
  isUnionType as isUnionType4
1015
1078
  } from "graphql";
1016
- var SchemaWeaver = class _SchemaWeaver {
1079
+ var GraphQLSchemaLoom = class _GraphQLSchemaLoom {
1017
1080
  query;
1018
1081
  mutation;
1019
1082
  subscription;
@@ -1180,12 +1243,12 @@ var SchemaWeaver = class _SchemaWeaver {
1180
1243
  }
1181
1244
  /**
1182
1245
  * Weave a GraphQL Schema from resolvers
1183
- * @param inputs Resolvers, Global Middlewares or WeaverConfigs
1184
- * @returns GraphQ LSchema
1246
+ * @param inputs Resolvers, Global Middlewares, WeaverConfigs Or SchemaWeaver
1247
+ * @returns GraphQL Schema
1185
1248
  */
1186
1249
  static weave(...inputs) {
1187
- const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
1188
- const weaver = new _SchemaWeaver({}, context);
1250
+ const { context, configs, middlewares, resolvers, silks, weavers } = _GraphQLSchemaLoom.optionsFrom(...inputs);
1251
+ const weaver = new _GraphQLSchemaLoom({}, context);
1189
1252
  configs.forEach((it) => weaver.setConfig(it));
1190
1253
  weavers.forEach((it) => weaver.addVendor(it));
1191
1254
  middlewares.forEach((it) => weaver.use(it));
@@ -1194,7 +1257,7 @@ var SchemaWeaver = class _SchemaWeaver {
1194
1257
  return weaver.weaveGraphQLSchema();
1195
1258
  }
1196
1259
  };
1197
- var weave = SchemaWeaver.weave;
1260
+ var weave = GraphQLSchemaLoom.weave;
1198
1261
 
1199
1262
  // src/schema/interface.ts
1200
1263
  import {
@@ -1227,10 +1290,11 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1227
1290
  }
1228
1291
  export {
1229
1292
  ContextMemoization,
1293
+ GraphQLSchemaLoom,
1230
1294
  LoomObjectType,
1295
+ OPERATION_OBJECT_NAMES,
1231
1296
  ResolverOptionsMap,
1232
1297
  symbols_exports as SYMBOLS,
1233
- SchemaWeaver,
1234
1298
  applyMiddlewares,
1235
1299
  baseResolver,
1236
1300
  collectName,
@@ -1273,6 +1337,7 @@ export {
1273
1337
  onlyMemoization,
1274
1338
  parseInputValue,
1275
1339
  parseSilk,
1340
+ pascalCase,
1276
1341
  provideWeaverContext,
1277
1342
  query,
1278
1343
  resolver,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gqloom/core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Create GraphQL schema and resolvers with TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,6 +14,10 @@
14
14
  "require": {
15
15
  "types": "./dist/index.d.cts",
16
16
  "default": "./dist/index.cjs"
17
+ },
18
+ "source": {
19
+ "types": "./src/index.ts",
20
+ "default": "./src/index.ts"
17
21
  }
18
22
  }
19
23
  },