@gqloom/core 0.2.1 → 0.3.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
@@ -1,20 +1,21 @@
1
- # GQLoom
1
+ ![GQLoom Logo](https://github.com/modevol-com/gqloom/blob/main/gqloom.svg?raw=true)
2
2
 
3
- English | [简体中文](./README.zh-CN.md)
3
+ # GQLoom
4
4
 
5
- GQLoom is a GraphQL weaver for TypeScript/JavaScript, using Zod, Yup, or Valibot to easily weave GraphQL schemas, providing the best development experience with complete type inference.
5
+ GQLoom is a GraphQL weaver for TypeScript/JavaScript that weaves GraphQL Schema using Valibot, Zod, or Yup, and supports sophisticated type inference to provide the best development experience.
6
6
 
7
- GQLoom is inspired by [tRPC](https://trpc.io/), [TypeGraphQL](https://typegraphql.com/), and [Pothos](https://pothos-graphql.dev/).
7
+ The design of GQLoom is inspired by [tRPC](https://trpc.io/), [TypeGraphQL](https://typegraphql.com/), [Pothos](https://pothos-graphql.dev/).
8
8
 
9
9
  ## Features
10
10
 
11
- - 📦 Use popular pattern libraries (Zod, Yup, Valibot) to build and validate GraphQL schemas.
12
- - 🔒 Complete type safety, discover potential issues during compilation.
13
- - 🧩 Classic middleware system: authentication, caching, logging, etc.
14
- - 🪄 Accessible Context and DataLoader everywhere.
15
- - 🔮 No code generation and experimental decorator features.
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;
16
17
 
17
- ## Hello, World!
18
+ ## Hello World
18
19
 
19
20
  ```ts
20
21
  import { resolver, query, weave } from "@gqloom/valibot"
@@ -26,3 +27,9 @@ const HelloResolver = resolver({
26
27
 
27
28
  export const schema = weave(HelloResolver)
28
29
  ```
30
+
31
+ Read [Introduction](https://gqloom.dev/guide/introduction.html) to learn more about GQLoom.
32
+
33
+ ## Getting Started
34
+
35
+ See [Getting Started](https://gqloom.dev/guide/getting-started.html) to learn how to use GQLoom.
package/dist/index.cjs CHANGED
@@ -27,16 +27,17 @@ __export(src_exports, {
27
27
  SchemaWeaver: () => SchemaWeaver,
28
28
  applyMiddlewares: () => applyMiddlewares,
29
29
  baseResolver: () => baseResolver,
30
+ collectName: () => collectName,
30
31
  collectNames: () => collectNames,
31
32
  compose: () => compose,
32
- createFieldBobbin: () => createFieldBobbin,
33
+ createFieldFactory: () => createFieldFactory,
33
34
  createInputParser: () => createInputParser,
34
35
  createLoom: () => createLoom,
35
36
  createMemoization: () => createMemoization,
36
- createMutationBobbin: () => createMutationBobbin,
37
- createQueryBobbin: () => createQueryBobbin,
38
- createResolverBobbin: () => createResolverBobbin,
39
- createSubscriptionBobbin: () => createSubscriptionBobbin,
37
+ createMutationFactory: () => createMutationFactory,
38
+ createQueryFactory: () => createQueryFactory,
39
+ createResolverFactory: () => createResolverFactory,
40
+ createSubscriptionFactory: () => createSubscriptionFactory,
40
41
  deepMerge: () => deepMerge,
41
42
  defaultSubscriptionResolve: () => defaultSubscriptionResolve,
42
43
  ensureInputObjectType: () => ensureInputObjectType,
@@ -56,7 +57,6 @@ __export(src_exports, {
56
57
  mapValue: () => mapValue,
57
58
  markErrorLocation: () => markErrorLocation,
58
59
  markLocation: () => markLocation,
59
- mergeExtensions: () => mergeExtensions,
60
60
  nonNullSilk: () => nonNullSilk,
61
61
  notNullish: () => notNullish,
62
62
  nullableSilk: () => nullableSilk,
@@ -88,6 +88,7 @@ var import_graphql = require("graphql");
88
88
  var symbols_exports = {};
89
89
  __export(symbols_exports, {
90
90
  CONTEXT_MEMORY_MAP_KEY: () => CONTEXT_MEMORY_MAP_KEY,
91
+ FIELD_HIDDEN: () => FIELD_HIDDEN,
91
92
  GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
92
93
  PARSE: () => PARSE,
93
94
  RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
@@ -98,6 +99,7 @@ var PARSE = Symbol.for("gqloom.parse");
98
99
  var WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
99
100
  var RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
100
101
  var CONTEXT_MEMORY_MAP_KEY = Symbol.for("gqloom.context-memory");
102
+ var FIELD_HIDDEN = Symbol.for("gqloom.field-hidden");
101
103
 
102
104
  // src/resolver/silk.ts
103
105
  function silk(type, parse) {
@@ -455,7 +457,7 @@ var silkMutation = (output, resolveOrOptions) => {
455
457
  type
456
458
  };
457
459
  };
458
- var silkField = (output, resolveOrOptions) => {
460
+ var baseSilkField = (output, resolveOrOptions) => {
459
461
  const options = getOperationOptions(resolveOrOptions);
460
462
  const type = "field";
461
463
  return {
@@ -473,6 +475,12 @@ var silkField = (output, resolveOrOptions) => {
473
475
  type
474
476
  };
475
477
  };
478
+ var silkField = Object.assign(
479
+ baseSilkField,
480
+ {
481
+ hidden: FIELD_HIDDEN
482
+ }
483
+ );
476
484
  var defaultSubscriptionResolve = (source) => source;
477
485
  var silkSubscription = (output, subscribeOrOptions) => {
478
486
  const options = getSubscriptionOptions(subscribeOrOptions);
@@ -507,6 +515,7 @@ function baseResolver(operations, options) {
507
515
  }
508
516
  function extraOperationOptions(operation, options) {
509
517
  const composeMiddlewares = (extraOptions) => compose(extraOptions?.middlewares, options?.middlewares);
518
+ if (typeof operation === "symbol") return operation;
510
519
  switch (operation.type) {
511
520
  case "field":
512
521
  return {
@@ -565,7 +574,7 @@ function toSilkInput(schema, toSilk, isSchema) {
565
574
  }
566
575
  return record;
567
576
  }
568
- function createResolverBobbin(toSilk) {
577
+ function createResolverFactory(toSilk) {
569
578
  return Object.assign(baseResolver, {
570
579
  of: (parent, operations, options) => baseResolver(
571
580
  operations,
@@ -573,8 +582,8 @@ function createResolverBobbin(toSilk) {
573
582
  )
574
583
  });
575
584
  }
576
- function createFieldBobbin(toSilk, isSchema) {
577
- return (output, resolveOrOptions) => {
585
+ function createFieldFactory(toSilk, isSchema) {
586
+ const baseFieldFunc = (output, resolveOrOptions) => {
578
587
  const options = getOperationOptions(
579
588
  resolveOrOptions
580
589
  );
@@ -583,8 +592,11 @@ function createFieldBobbin(toSilk, isSchema) {
583
592
  input: toSilkInput(options.input, toSilk, isSchema)
584
593
  });
585
594
  };
595
+ return Object.assign(baseFieldFunc, {
596
+ hidden: FIELD_HIDDEN
597
+ });
586
598
  }
587
- function createQueryBobbin(toSilk, isSchema) {
599
+ function createQueryFactory(toSilk, isSchema) {
588
600
  return (output, resolveOrOptions) => {
589
601
  const options = getOperationOptions(resolveOrOptions);
590
602
  return silkQuery(toSilk(output), {
@@ -593,7 +605,7 @@ function createQueryBobbin(toSilk, isSchema) {
593
605
  });
594
606
  };
595
607
  }
596
- function createMutationBobbin(toSilk, isSchema) {
608
+ function createMutationFactory(toSilk, isSchema) {
597
609
  return (output, resolveOrOptions) => {
598
610
  const options = getOperationOptions(resolveOrOptions);
599
611
  return silkMutation(toSilk(output), {
@@ -602,7 +614,7 @@ function createMutationBobbin(toSilk, isSchema) {
602
614
  });
603
615
  };
604
616
  }
605
- function createSubscriptionBobbin(toSilk, isSchema) {
617
+ function createSubscriptionFactory(toSilk, isSchema) {
606
618
  return (output, resolveOrOptions) => {
607
619
  const options = getSubscriptionOptions(resolveOrOptions);
608
620
  return silkSubscription(toSilk(output), {
@@ -613,11 +625,11 @@ function createSubscriptionBobbin(toSilk, isSchema) {
613
625
  }
614
626
  function createLoom(toSilk, isSchema) {
615
627
  return {
616
- query: createQueryBobbin(toSilk, isSchema),
617
- mutation: createMutationBobbin(toSilk, isSchema),
618
- field: createFieldBobbin(toSilk, isSchema),
619
- resolver: createResolverBobbin(toSilk),
620
- subscription: createSubscriptionBobbin(toSilk, isSchema)
628
+ query: createQueryFactory(toSilk, isSchema),
629
+ mutation: createMutationFactory(toSilk, isSchema),
630
+ field: createFieldFactory(toSilk, isSchema),
631
+ resolver: createResolverFactory(toSilk),
632
+ subscription: createSubscriptionFactory(toSilk, isSchema)
621
633
  };
622
634
  }
623
635
 
@@ -630,6 +642,7 @@ var ref;
630
642
  var names = /* @__PURE__ */ new WeakMap();
631
643
  function initWeaverContext() {
632
644
  return {
645
+ id: initWeaverContext.increasingID++,
633
646
  loomObjectMap: /* @__PURE__ */ new Map(),
634
647
  loomUnionMap: /* @__PURE__ */ new Map(),
635
648
  inputMap: /* @__PURE__ */ new Map(),
@@ -649,7 +662,7 @@ function initWeaverContext() {
649
662
  namedTypes: /* @__PURE__ */ new Map(),
650
663
  memoNamedType(gqlTypeValue) {
651
664
  const gqlType = gqlTypeValue;
652
- if ((0, import_graphql2.isObjectType)(gqlType) || (0, import_graphql2.isUnionType)(gqlType) || (0, import_graphql2.isEnumType)(gqlType)) {
665
+ if ((0, import_graphql2.isObjectType)(gqlType) || (0, import_graphql2.isUnionType)(gqlType) || (0, import_graphql2.isEnumType)(gqlType) || (0, import_graphql2.isScalarType)(gqlType)) {
653
666
  this.namedTypes.set(gqlType.name, gqlType);
654
667
  }
655
668
  return gqlTypeValue;
@@ -659,7 +672,11 @@ function initWeaverContext() {
659
672
  }
660
673
  };
661
674
  }
675
+ initWeaverContext.increasingID = 1;
662
676
  var weaverContext = {
677
+ get id() {
678
+ return ref?.id;
679
+ },
663
680
  get loomObjectMap() {
664
681
  return ref?.loomObjectMap;
665
682
  },
@@ -719,6 +736,10 @@ function provideWeaverContext(func, value) {
719
736
  ref = lastRef;
720
737
  }
721
738
  }
739
+ provideWeaverContext.inherit = (func) => {
740
+ const weaverContextRef = weaverContext.value;
741
+ return () => provideWeaverContext(func, weaverContextRef);
742
+ };
722
743
  function collectNames(...namesList) {
723
744
  const namesRecord = {};
724
745
  for (const namesItem of namesList) {
@@ -729,6 +750,10 @@ function collectNames(...namesList) {
729
750
  }
730
751
  return namesRecord;
731
752
  }
753
+ function collectName(name, schema) {
754
+ names.set(schema, name);
755
+ return schema;
756
+ }
732
757
 
733
758
  // src/schema/input.ts
734
759
  var import_graphql3 = require("graphql");
@@ -789,7 +814,9 @@ function ensureInputObjectType(object) {
789
814
  const input = new import_graphql3.GraphQLInputObjectType({
790
815
  ...config,
791
816
  name: getInputObjectName(object.name),
792
- fields: mapValue(fields, (it) => toInputFieldConfig(it))
817
+ fields: provideWeaverContext.inherit(
818
+ () => mapValue(fields, (it) => toInputFieldConfig(it))
819
+ )
793
820
  });
794
821
  weaverContext.inputMap?.set(object, input);
795
822
  return input;
@@ -805,6 +832,7 @@ function toInputFieldConfig({
805
832
  // src/schema/object.ts
806
833
  var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
807
834
  extraFields = /* @__PURE__ */ new Map();
835
+ hiddenFields = /* @__PURE__ */ new Set();
808
836
  weaverContext;
809
837
  resolverOptions;
810
838
  constructor(objectOrGetter, options = {}) {
@@ -822,6 +850,9 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
822
850
  this.resolverOptions = options.resolverOptions;
823
851
  this.weaverContext = options.weaverContext ?? initWeaverContext();
824
852
  }
853
+ hideField(name) {
854
+ this.hiddenFields.add(name);
855
+ }
825
856
  addField(name, resolver) {
826
857
  const existing = this.extraFields.get(name);
827
858
  if (existing && existing !== resolver) {
@@ -832,23 +863,27 @@ var LoomObjectType = class extends import_graphql4.GraphQLObjectType {
832
863
  mergeExtensions(extensions) {
833
864
  this.extensions = deepMerge(this.extensions, extensions);
834
865
  }
835
- extraField;
866
+ extraFieldMap;
836
867
  getFields() {
837
- const fields = super.getFields();
838
- Object.values(fields).forEach(
868
+ const fieldsBySuper = super.getFields();
869
+ Object.values(fieldsBySuper).forEach(
839
870
  (field) => field.type = this.getCacheType(field.type)
840
871
  );
841
- const extraField = provideWeaverContext(
872
+ const extraFields = provideWeaverContext(
842
873
  () => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
843
874
  this.weaverContext
844
875
  );
845
- if (Object.keys(this.extraField ?? {}).join() !== Object.keys(extraField).join()) {
846
- this.extraField = extraField;
876
+ if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) {
877
+ this.extraFieldMap = extraFields;
847
878
  }
848
- return {
849
- ...fields,
850
- ...this.extraField
879
+ const answer = {
880
+ ...fieldsBySuper,
881
+ ...this.extraFieldMap
851
882
  };
883
+ for (const fieldName of this.hiddenFields) {
884
+ delete answer[fieldName];
885
+ }
886
+ return answer;
852
887
  }
853
888
  mapToFieldConfig(map) {
854
889
  const record = {};
@@ -1067,7 +1102,10 @@ var SchemaWeaver = class _SchemaWeaver {
1067
1102
  if (resolverOptions?.extensions && parentObject)
1068
1103
  parentObject.mergeExtensions(resolverOptions.extensions);
1069
1104
  Object.entries(resolver).forEach(([name, operation]) => {
1070
- if (operation.type === "field") {
1105
+ if (operation === FIELD_HIDDEN) {
1106
+ if (parentObject == null) return;
1107
+ parentObject.hideField(name);
1108
+ } else if (operation.type === "field") {
1071
1109
  if (parentObject == null) return;
1072
1110
  parentObject.addField(name, operation);
1073
1111
  } else {
@@ -1170,11 +1208,6 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1170
1208
  weaverContext.interfaceMap?.set(key, interfaceType);
1171
1209
  return interfaceType;
1172
1210
  }
1173
-
1174
- // src/schema/extensions.ts
1175
- function mergeExtensions(...extensionsList) {
1176
- return deepMerge(...extensionsList);
1177
- }
1178
1211
  // Annotate the CommonJS export names for ESM import in node:
1179
1212
  0 && (module.exports = {
1180
1213
  ContextMemoization,
@@ -1184,16 +1217,17 @@ function mergeExtensions(...extensionsList) {
1184
1217
  SchemaWeaver,
1185
1218
  applyMiddlewares,
1186
1219
  baseResolver,
1220
+ collectName,
1187
1221
  collectNames,
1188
1222
  compose,
1189
- createFieldBobbin,
1223
+ createFieldFactory,
1190
1224
  createInputParser,
1191
1225
  createLoom,
1192
1226
  createMemoization,
1193
- createMutationBobbin,
1194
- createQueryBobbin,
1195
- createResolverBobbin,
1196
- createSubscriptionBobbin,
1227
+ createMutationFactory,
1228
+ createQueryFactory,
1229
+ createResolverFactory,
1230
+ createSubscriptionFactory,
1197
1231
  deepMerge,
1198
1232
  defaultSubscriptionResolve,
1199
1233
  ensureInputObjectType,
@@ -1213,7 +1247,6 @@ function mergeExtensions(...extensionsList) {
1213
1247
  mapValue,
1214
1248
  markErrorLocation,
1215
1249
  markLocation,
1216
- mergeExtensions,
1217
1250
  nonNullSilk,
1218
1251
  notNullish,
1219
1252
  nullableSilk,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { GraphQLOutputType, GraphQLObjectTypeConfig, GraphQLFieldConfig, GraphQLResolveInfo, GraphQLScalarType, GraphQLObjectType, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLSchemaConfig, GraphQLFieldMap, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig, GraphQLFieldExtensions, GraphQLObjectTypeExtensions } from 'graphql';
1
+ import { GraphQLOutputType, GraphQLObjectTypeConfig, GraphQLFieldConfig, GraphQLResolveInfo, GraphQLScalarType, GraphQLObjectType, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLSchemaConfig, GraphQLFieldMap, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig } from 'graphql';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  type MayPromise<T> = T | Promise<T>;
@@ -79,14 +79,19 @@ declare const RESOLVER_OPTIONS_KEY: unique symbol;
79
79
  * The symbol to assign a WeakMap to an object
80
80
  */
81
81
  declare const CONTEXT_MEMORY_MAP_KEY: unique symbol;
82
+ /**
83
+ * The symbol to set fields to be hidden
84
+ */
85
+ declare const FIELD_HIDDEN: unique symbol;
82
86
 
83
87
  declare const symbols_CONTEXT_MEMORY_MAP_KEY: typeof CONTEXT_MEMORY_MAP_KEY;
88
+ declare const symbols_FIELD_HIDDEN: typeof FIELD_HIDDEN;
84
89
  declare const symbols_GET_GRAPHQL_TYPE: typeof GET_GRAPHQL_TYPE;
85
90
  declare const symbols_PARSE: typeof PARSE;
86
91
  declare const symbols_RESOLVER_OPTIONS_KEY: typeof RESOLVER_OPTIONS_KEY;
87
92
  declare const symbols_WEAVER_CONFIG: typeof WEAVER_CONFIG;
88
93
  declare namespace symbols {
89
- export { symbols_CONTEXT_MEMORY_MAP_KEY as CONTEXT_MEMORY_MAP_KEY, symbols_GET_GRAPHQL_TYPE as GET_GRAPHQL_TYPE, symbols_PARSE as PARSE, symbols_RESOLVER_OPTIONS_KEY as RESOLVER_OPTIONS_KEY, symbols_WEAVER_CONFIG as WEAVER_CONFIG };
94
+ export { symbols_CONTEXT_MEMORY_MAP_KEY as CONTEXT_MEMORY_MAP_KEY, symbols_FIELD_HIDDEN as FIELD_HIDDEN, symbols_GET_GRAPHQL_TYPE as GET_GRAPHQL_TYPE, symbols_PARSE as PARSE, symbols_RESOLVER_OPTIONS_KEY as RESOLVER_OPTIONS_KEY, symbols_WEAVER_CONFIG as WEAVER_CONFIG };
90
95
  }
91
96
 
92
97
  interface GraphQLSilk<TOutput = any, TInput = any> {
@@ -159,10 +164,16 @@ interface QueryMutationOptions<TSchemaIO extends AbstractSchemaIO, TOutput exten
159
164
  resolve: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>;
160
165
  }
161
166
  /**
162
- * Function to create a GraphQL query or mutation.
167
+ * Function to create a GraphQL query.
168
+ */
169
+ interface QueryFactory<TSchemaIO extends AbstractSchemaIO> {
170
+ <TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: (() => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | QueryMutationOptions<TSchemaIO, TOutput, TInput>): FieldOrOperation<undefined, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "query">;
171
+ }
172
+ /**
173
+ * Function to create a GraphQL mutation.
163
174
  */
164
- interface QueryMutationBobbin<TSchemaIO extends AbstractSchemaIO> {
165
- <TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: (() => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | QueryMutationOptions<TSchemaIO, TOutput, TInput>): FieldOrOperation<undefined, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "query" | "mutation">;
175
+ interface MutationFactory<TSchemaIO extends AbstractSchemaIO> {
176
+ <TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: (() => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | QueryMutationOptions<TSchemaIO, TOutput, TInput>): FieldOrOperation<undefined, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "mutation">;
166
177
  }
167
178
  /**
168
179
  * Options for External Filed of existing GraphQL Object.
@@ -174,9 +185,13 @@ interface FieldOptions<TSchemaIO extends AbstractSchemaIO, TParent extends TSche
174
185
  /**
175
186
  * Function to create a GraphQL Field.
176
187
  */
177
- interface FieldBobbin<TSchemaIO extends AbstractSchemaIO> {
188
+ interface FieldFactory<TSchemaIO extends AbstractSchemaIO> {
178
189
  <TParent extends TSchemaIO[0], TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: ((parent: InferSchemaO<TParent, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | FieldOptions<TSchemaIO, TParent, TOutput, TInput>): FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "field">;
179
190
  }
191
+ interface FieldFactoryWithUtils<TSchemaIO extends AbstractSchemaIO> extends FieldFactory<TSchemaIO> {
192
+ /** Set fields to be hidden in GraphQL Schema */
193
+ hidden: typeof FIELD_HIDDEN;
194
+ }
180
195
  /**
181
196
  * Options for creating a GraphQL Subscription.
182
197
  */
@@ -192,13 +207,14 @@ interface Subscription<TOutput extends GraphQLSilk, TInput extends InputSchema<G
192
207
  /**
193
208
  * Function to create a GraphQL subscription.
194
209
  */
195
- interface SubscriptionBobbin<TSchemaIO extends AbstractSchemaIO> {
210
+ interface SubscriptionFactory<TSchemaIO extends AbstractSchemaIO> {
196
211
  <TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined, TValue = InferSchemaO<TOutput, TSchemaIO>>(output: TOutput, subscribeOrOptions: (() => MayPromise<AsyncIterator<InferSchemaO<TOutput, TSchemaIO>>>) | SubscriptionOptions<TSchemaIO, TOutput, TInput, TValue>): Subscription<SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, TValue>;
197
212
  }
198
- interface ResolverBobbin<TSchemaIO extends AbstractSchemaIO> {
199
- of<TParent extends TSchemaIO[0], TOperations extends Record<string, FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, any, any> | FieldOrOperation<undefined, any, any, OperationType>>>(parent: TParent, operationOrFields: TOperations, options?: ResolverOptionsWithExtensions<ValueOf<TOperations>>): TOperations;
213
+ interface ResolverFactory<TSchemaIO extends AbstractSchemaIO> {
214
+ of<TParent extends TSchemaIO[0], TOperations extends Record<string, FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, any, any> | FieldOrOperation<undefined, any, any, OperationType> | typeof FIELD_HIDDEN>>(parent: TParent, operationOrFields: TOperations, options?: ResolverOptionsWithExtensions<OmitInUnion<ValueOf<TOperations>, typeof FIELD_HIDDEN>>): TOperations;
200
215
  <TOperations extends Record<string, FieldOrOperation<undefined, any, any, OperationType>>>(operations: TOperations, options?: ResolverOptions<ValueOf<TOperations>>): TOperations;
201
216
  }
217
+ type OmitInUnion<TUnion, TOmit> = TUnion extends infer T ? T extends TOmit ? never : T : never;
202
218
 
203
219
  declare function getOperationOptions<T extends FieldOrOperationType = OperationType>(resolveOrOptions: T extends "field" ? ((parent: any) => any) | FieldOptions<any, any, any, any> : (() => any) | QueryMutationOptions<any, any, any>): T extends "field" ? FieldOptions<any, any, any, any> : QueryMutationOptions<any, any, any>;
204
220
  declare function getSubscriptionOptions(subscribeOrOptions: (() => any) | SubscriptionOptions<any, any, any, any>): SubscriptionOptions<any, any, any, any>;
@@ -359,11 +375,11 @@ declare function markLocation(message: string, ...locations: string[]): string;
359
375
  /**
360
376
  * Create a Silk from Scalar.
361
377
  */
362
- declare function silk<TScalar extends GraphQLScalarType>(type: TScalar, parse?: (input: InferScalarExternal<TScalar>) => MayPromise<InferScalarInternal<TScalar>>): GraphQLSilk<InferScalarInternal<TScalar> | undefined, InferScalarInternal<TScalar> | undefined>;
378
+ declare function silk<TScalar extends GraphQLScalarType>(type: TScalar | (() => TScalar), parse?: (input: InferScalarExternal<TScalar>) => MayPromise<InferScalarInternal<TScalar>>): GraphQLSilk<InferScalarInternal<TScalar> | undefined, InferScalarInternal<TScalar> | undefined>;
363
379
  /**
364
380
  * Create a GraphQLSilk Object.
365
381
  */
366
- declare function silk<TOutput, TInput = TOutput>(type: GraphQLOutputType, parse?: (input: TInput) => MayPromise<TOutput>): GraphQLSilk<TOutput, TInput>;
382
+ declare function silk<TOutput, TInput = TOutput>(type: GraphQLOutputType | (() => GraphQLOutputType), parse?: (input: TInput) => MayPromise<TOutput>): GraphQLSilk<TOutput, TInput>;
367
383
  declare namespace silk {
368
384
  var parse: typeof parseSilk;
369
385
  var getType: typeof getGraphQLType;
@@ -404,36 +420,37 @@ type InferScalarInternal<T extends GraphQLScalarType> = T extends GraphQLScalarT
404
420
  type InferScalarExternal<T extends GraphQLScalarType> = T extends GraphQLScalarType<any, infer TExternal> ? TExternal : never;
405
421
  type EnsureArray<T> = T extends Array<infer U> ? U[] : T[];
406
422
 
407
- declare const silkQuery: QueryMutationBobbin<GraphQLSilkIO>;
408
- declare const silkMutation: QueryMutationBobbin<GraphQLSilkIO>;
409
- declare const silkField: FieldBobbin<GraphQLSilkIO>;
423
+ declare const silkQuery: QueryFactory<GraphQLSilkIO>;
424
+ declare const silkMutation: MutationFactory<GraphQLSilkIO>;
425
+ declare const silkField: FieldFactoryWithUtils<GraphQLSilkIO>;
410
426
  declare const defaultSubscriptionResolve: (source: any) => any;
411
- declare const silkSubscription: SubscriptionBobbin<GraphQLSilkIO>;
427
+ declare const silkSubscription: SubscriptionFactory<GraphQLSilkIO>;
412
428
  declare const ResolverOptionsMap: WeakMap<object, ResolverOptionsWithParent<GenericFieldOrOperation>>;
413
429
  declare function baseResolver(operations: Record<string, FieldOrOperation<any, any, any>>, options: ResolverOptionsWithParent | undefined): Record<string, FieldOrOperation<any, any, any, FieldOrOperationType>>;
414
- declare const silkResolver: ResolverBobbin<GraphQLSilkIO>;
430
+ declare const silkResolver: ResolverFactory<GraphQLSilkIO>;
415
431
  declare const loom: {
416
- query: QueryMutationBobbin<GraphQLSilkIO>;
417
- resolver: ResolverBobbin<GraphQLSilkIO>;
418
- field: FieldBobbin<GraphQLSilkIO>;
419
- subscription: SubscriptionBobbin<GraphQLSilkIO>;
420
- mutation: QueryMutationBobbin<GraphQLSilkIO>;
432
+ query: QueryFactory<GraphQLSilkIO>;
433
+ resolver: ResolverFactory<GraphQLSilkIO>;
434
+ field: FieldFactoryWithUtils<GraphQLSilkIO>;
435
+ subscription: SubscriptionFactory<GraphQLSilkIO>;
436
+ mutation: MutationFactory<GraphQLSilkIO>;
421
437
  };
422
438
 
423
- declare function createResolverBobbin<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk): ResolverBobbin<TSchemaIO>;
424
- declare function createFieldBobbin<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): FieldBobbin<TSchemaIO>;
425
- declare function createQueryBobbin<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): QueryMutationBobbin<TSchemaIO>;
426
- declare function createMutationBobbin<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): QueryMutationBobbin<TSchemaIO>;
427
- declare function createSubscriptionBobbin<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): SubscriptionBobbin<TSchemaIO>;
439
+ declare function createResolverFactory<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk): ResolverFactory<TSchemaIO>;
440
+ declare function createFieldFactory<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): FieldFactoryWithUtils<TSchemaIO>;
441
+ declare function createQueryFactory<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): QueryFactory<TSchemaIO>;
442
+ declare function createMutationFactory<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): MutationFactory<TSchemaIO>;
443
+ declare function createSubscriptionFactory<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): SubscriptionFactory<TSchemaIO>;
428
444
  declare function createLoom<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk, isSchema: (schema: InputSchema<TSchemaIO[0]>) => boolean): {
429
- query: QueryMutationBobbin<TSchemaIO>;
430
- mutation: QueryMutationBobbin<TSchemaIO>;
431
- field: FieldBobbin<TSchemaIO>;
432
- resolver: ResolverBobbin<TSchemaIO>;
433
- subscription: SubscriptionBobbin<TSchemaIO>;
445
+ query: QueryFactory<TSchemaIO>;
446
+ mutation: MutationFactory<TSchemaIO>;
447
+ field: FieldFactoryWithUtils<TSchemaIO>;
448
+ resolver: ResolverFactory<TSchemaIO>;
449
+ subscription: SubscriptionFactory<TSchemaIO>;
434
450
  };
435
451
 
436
452
  interface WeaverContext {
453
+ id: number;
437
454
  loomObjectMap: Map<GraphQLObjectType, LoomObjectType>;
438
455
  loomUnionMap: Map<GraphQLUnionType, GraphQLUnionType>;
439
456
  inputMap: Map<GraphQLObjectType | GraphQLInterfaceType, GraphQLInputObjectType>;
@@ -451,6 +468,9 @@ interface WeaverConfig {
451
468
  [WEAVER_CONFIG]: string | symbol;
452
469
  }
453
470
  declare function initWeaverContext(): WeaverContext;
471
+ declare namespace initWeaverContext {
472
+ var increasingID: number;
473
+ }
454
474
  type GlobalContextRequiredKeys = "names" | "getConfig" | "setConfig" | "getNamedType" | "memoNamedType";
455
475
  interface GlobalWeaverContext extends Partial<Omit<WeaverContext, GlobalContextRequiredKeys>>, Pick<WeaverContext, GlobalContextRequiredKeys> {
456
476
  value?: WeaverContext;
@@ -461,19 +481,29 @@ interface GlobalWeaverContext extends Partial<Omit<WeaverContext, GlobalContextR
461
481
  }
462
482
  declare const weaverContext: GlobalWeaverContext;
463
483
  declare function provideWeaverContext<T>(func: () => T, value: WeaverContext | undefined): T;
484
+ declare namespace provideWeaverContext {
485
+ var inherit: <T>(func: () => T) => () => T;
486
+ }
464
487
  /**
465
488
  * collect names for schemas
466
489
  * @param namesList - names to collect
467
490
  * @returns namesRecord
468
491
  */
469
492
  declare function collectNames<TRecords extends Record<string, object>[]>(...namesList: TRecords): UnionToIntersection<TRecords[number]>;
493
+ /**
494
+ * collect name for schema
495
+ * @param name - name for
496
+ * @param schema - schema to be named
497
+ * @returns schema
498
+ */
499
+ declare function collectName<TSchema extends object>(name: string, schema: TSchema): TSchema;
470
500
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
471
501
 
472
502
  type SilkFieldOrOperation = FieldOrOperation<any, any, any, any>;
473
503
  interface FieldConvertOptions {
474
504
  optionsForResolving?: ResolvingOptions;
475
505
  }
476
- type SilkResolver = Record<string, FieldOrOperation<any, any, any, any>>;
506
+ type SilkResolver = Record<string, FieldOrOperation<any, any, any, any> | typeof FIELD_HIDDEN>;
477
507
  interface CoreSchemaWeaverConfigOptions extends GraphQLSchemaConfig {
478
508
  getInputObjectName?: (name: string) => string;
479
509
  weaverContext?: WeaverContext;
@@ -483,16 +513,18 @@ interface CoreSchemaWeaverConfig extends WeaverConfig, CoreSchemaWeaverConfigOpt
483
513
  }
484
514
 
485
515
  declare class LoomObjectType extends GraphQLObjectType {
486
- extraFields: Map<string, SilkFieldOrOperation>;
487
- weaverContext: WeaverContext;
488
- resolverOptions?: ResolvingOptions;
516
+ protected extraFields: Map<string, SilkFieldOrOperation>;
517
+ protected hiddenFields: Set<string>;
518
+ protected weaverContext: WeaverContext;
519
+ protected resolverOptions?: ResolvingOptions;
489
520
  constructor(objectOrGetter: string | GraphQLObjectType | GraphQLObjectTypeConfig<any, any> | (() => GraphQLObjectType | GraphQLObjectTypeConfig<any, any>), options?: {
490
521
  weaverContext?: WeaverContext;
491
522
  resolverOptions?: ResolvingOptions;
492
523
  });
524
+ hideField(name: string): void;
493
525
  addField(name: string, resolver: SilkFieldOrOperation): void;
494
526
  mergeExtensions(extensions: GraphQLObjectTypeConfig<any, any>["extensions"]): void;
495
- private extraField?;
527
+ private extraFieldMap?;
496
528
  getFields(): GraphQLFieldMap<any, any>;
497
529
  protected mapToFieldConfig(map: Map<string, SilkFieldOrOperation>): Record<string, GraphQLFieldConfig<any, any>>;
498
530
  toFieldConfig(field: SilkFieldOrOperation): GraphQLFieldConfig<any, any>;
@@ -576,6 +608,5 @@ type DirectiveRecord = Record<string, Record<string, any>>;
576
608
  interface GQLoomExtensionAttribute {
577
609
  directives?: string[];
578
610
  }
579
- declare function mergeExtensions(...extensionsList: (Readonly<GraphQLFieldExtensions<any, any, any> | GraphQLObjectTypeExtensions | GQLoomExtensions> | null | undefined)[]): GraphQLFieldExtensions<any, any, any>;
580
611
 
581
- export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldBobbin, type FieldConvertOptions, 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 InferSilkI, type InferSilkO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewarePayload, type NonNullSilk, type NullableSilk, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryMutationBobbin, type QueryMutationOptions, type ResolverBobbin, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, type Subscription, type SubscriptionBobbin, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectNames, compose, createFieldBobbin, createInputParser, createLoom, createMemoization, createMutationBobbin, createQueryBobbin, createResolverBobbin, createSubscriptionBobbin, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mergeExtensions, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, resolverPayloadStorage, silk, silkField, silkMutation, silkQuery, silkResolver, silkSubscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
612
+ export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, 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 InferSilkI, type InferSilkO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewarePayload, 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, SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, 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, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, provideWeaverContext, resolverPayloadStorage, silk, silkField, silkMutation, silkQuery, silkResolver, silkSubscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };