@gqloom/core 0.2.2 → 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
@@ -9,7 +9,7 @@ The design of GQLoom is inspired by [tRPC](https://trpc.io/), [TypeGraphQL](http
9
9
  ## Features
10
10
 
11
11
  - 🚀 GraphQL: flexible and efficient, reducing redundant data transfers;
12
- - 🔒 Robust type safety: enjoy smart hints during development and spot potential problems during editing;
12
+ - 🔒 Robust type safety: enjoy intelligent hints at development time to detect potential problems at compile time;
13
13
  - 🔋 Ready to go: middleware, contexts, subscriptions, federated graphs are ready to go;
14
14
  - 🔮 No extra magic: no decorators, no metadata and reflection, no code generation, you just need JavaScript/TypeScript;
15
15
  - 🧩 Familiar schema libraries: use the schema libraries you already know (Zod, Yup, Valibot) to build GraphQL Schema and validate inputs;
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 };
package/dist/index.d.ts 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 };
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  var symbols_exports = {};
15
15
  __export(symbols_exports, {
16
16
  CONTEXT_MEMORY_MAP_KEY: () => CONTEXT_MEMORY_MAP_KEY,
17
+ FIELD_HIDDEN: () => FIELD_HIDDEN,
17
18
  GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
18
19
  PARSE: () => PARSE,
19
20
  RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
@@ -24,6 +25,7 @@ var PARSE = Symbol.for("gqloom.parse");
24
25
  var WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
25
26
  var RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
26
27
  var CONTEXT_MEMORY_MAP_KEY = Symbol.for("gqloom.context-memory");
28
+ var FIELD_HIDDEN = Symbol.for("gqloom.field-hidden");
27
29
 
28
30
  // src/resolver/silk.ts
29
31
  function silk(type, parse) {
@@ -381,7 +383,7 @@ var silkMutation = (output, resolveOrOptions) => {
381
383
  type
382
384
  };
383
385
  };
384
- var silkField = (output, resolveOrOptions) => {
386
+ var baseSilkField = (output, resolveOrOptions) => {
385
387
  const options = getOperationOptions(resolveOrOptions);
386
388
  const type = "field";
387
389
  return {
@@ -399,6 +401,12 @@ var silkField = (output, resolveOrOptions) => {
399
401
  type
400
402
  };
401
403
  };
404
+ var silkField = Object.assign(
405
+ baseSilkField,
406
+ {
407
+ hidden: FIELD_HIDDEN
408
+ }
409
+ );
402
410
  var defaultSubscriptionResolve = (source) => source;
403
411
  var silkSubscription = (output, subscribeOrOptions) => {
404
412
  const options = getSubscriptionOptions(subscribeOrOptions);
@@ -433,6 +441,7 @@ function baseResolver(operations, options) {
433
441
  }
434
442
  function extraOperationOptions(operation, options) {
435
443
  const composeMiddlewares = (extraOptions) => compose(extraOptions?.middlewares, options?.middlewares);
444
+ if (typeof operation === "symbol") return operation;
436
445
  switch (operation.type) {
437
446
  case "field":
438
447
  return {
@@ -491,7 +500,7 @@ function toSilkInput(schema, toSilk, isSchema) {
491
500
  }
492
501
  return record;
493
502
  }
494
- function createResolverBobbin(toSilk) {
503
+ function createResolverFactory(toSilk) {
495
504
  return Object.assign(baseResolver, {
496
505
  of: (parent, operations, options) => baseResolver(
497
506
  operations,
@@ -499,8 +508,8 @@ function createResolverBobbin(toSilk) {
499
508
  )
500
509
  });
501
510
  }
502
- function createFieldBobbin(toSilk, isSchema) {
503
- return (output, resolveOrOptions) => {
511
+ function createFieldFactory(toSilk, isSchema) {
512
+ const baseFieldFunc = (output, resolveOrOptions) => {
504
513
  const options = getOperationOptions(
505
514
  resolveOrOptions
506
515
  );
@@ -509,8 +518,11 @@ function createFieldBobbin(toSilk, isSchema) {
509
518
  input: toSilkInput(options.input, toSilk, isSchema)
510
519
  });
511
520
  };
521
+ return Object.assign(baseFieldFunc, {
522
+ hidden: FIELD_HIDDEN
523
+ });
512
524
  }
513
- function createQueryBobbin(toSilk, isSchema) {
525
+ function createQueryFactory(toSilk, isSchema) {
514
526
  return (output, resolveOrOptions) => {
515
527
  const options = getOperationOptions(resolveOrOptions);
516
528
  return silkQuery(toSilk(output), {
@@ -519,7 +531,7 @@ function createQueryBobbin(toSilk, isSchema) {
519
531
  });
520
532
  };
521
533
  }
522
- function createMutationBobbin(toSilk, isSchema) {
534
+ function createMutationFactory(toSilk, isSchema) {
523
535
  return (output, resolveOrOptions) => {
524
536
  const options = getOperationOptions(resolveOrOptions);
525
537
  return silkMutation(toSilk(output), {
@@ -528,7 +540,7 @@ function createMutationBobbin(toSilk, isSchema) {
528
540
  });
529
541
  };
530
542
  }
531
- function createSubscriptionBobbin(toSilk, isSchema) {
543
+ function createSubscriptionFactory(toSilk, isSchema) {
532
544
  return (output, resolveOrOptions) => {
533
545
  const options = getSubscriptionOptions(resolveOrOptions);
534
546
  return silkSubscription(toSilk(output), {
@@ -539,11 +551,11 @@ function createSubscriptionBobbin(toSilk, isSchema) {
539
551
  }
540
552
  function createLoom(toSilk, isSchema) {
541
553
  return {
542
- query: createQueryBobbin(toSilk, isSchema),
543
- mutation: createMutationBobbin(toSilk, isSchema),
544
- field: createFieldBobbin(toSilk, isSchema),
545
- resolver: createResolverBobbin(toSilk),
546
- subscription: createSubscriptionBobbin(toSilk, isSchema)
554
+ query: createQueryFactory(toSilk, isSchema),
555
+ mutation: createMutationFactory(toSilk, isSchema),
556
+ field: createFieldFactory(toSilk, isSchema),
557
+ resolver: createResolverFactory(toSilk),
558
+ subscription: createSubscriptionFactory(toSilk, isSchema)
547
559
  };
548
560
  }
549
561
 
@@ -565,12 +577,14 @@ import {
565
577
  import {
566
578
  isEnumType,
567
579
  isObjectType,
568
- isUnionType
580
+ isUnionType,
581
+ isScalarType
569
582
  } from "graphql";
570
583
  var ref;
571
584
  var names = /* @__PURE__ */ new WeakMap();
572
585
  function initWeaverContext() {
573
586
  return {
587
+ id: initWeaverContext.increasingID++,
574
588
  loomObjectMap: /* @__PURE__ */ new Map(),
575
589
  loomUnionMap: /* @__PURE__ */ new Map(),
576
590
  inputMap: /* @__PURE__ */ new Map(),
@@ -590,7 +604,7 @@ function initWeaverContext() {
590
604
  namedTypes: /* @__PURE__ */ new Map(),
591
605
  memoNamedType(gqlTypeValue) {
592
606
  const gqlType = gqlTypeValue;
593
- if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType)) {
607
+ if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType) || isScalarType(gqlType)) {
594
608
  this.namedTypes.set(gqlType.name, gqlType);
595
609
  }
596
610
  return gqlTypeValue;
@@ -600,7 +614,11 @@ function initWeaverContext() {
600
614
  }
601
615
  };
602
616
  }
617
+ initWeaverContext.increasingID = 1;
603
618
  var weaverContext = {
619
+ get id() {
620
+ return ref?.id;
621
+ },
604
622
  get loomObjectMap() {
605
623
  return ref?.loomObjectMap;
606
624
  },
@@ -660,6 +678,10 @@ function provideWeaverContext(func, value) {
660
678
  ref = lastRef;
661
679
  }
662
680
  }
681
+ provideWeaverContext.inherit = (func) => {
682
+ const weaverContextRef = weaverContext.value;
683
+ return () => provideWeaverContext(func, weaverContextRef);
684
+ };
663
685
  function collectNames(...namesList) {
664
686
  const namesRecord = {};
665
687
  for (const namesItem of namesList) {
@@ -670,6 +692,10 @@ function collectNames(...namesList) {
670
692
  }
671
693
  return namesRecord;
672
694
  }
695
+ function collectName(name, schema) {
696
+ names.set(schema, name);
697
+ return schema;
698
+ }
673
699
 
674
700
  // src/schema/input.ts
675
701
  import {
@@ -740,7 +766,9 @@ function ensureInputObjectType(object) {
740
766
  const input = new GraphQLInputObjectType({
741
767
  ...config,
742
768
  name: getInputObjectName(object.name),
743
- fields: mapValue(fields, (it) => toInputFieldConfig(it))
769
+ fields: provideWeaverContext.inherit(
770
+ () => mapValue(fields, (it) => toInputFieldConfig(it))
771
+ )
744
772
  });
745
773
  weaverContext.inputMap?.set(object, input);
746
774
  return input;
@@ -756,6 +784,7 @@ function toInputFieldConfig({
756
784
  // src/schema/object.ts
757
785
  var LoomObjectType = class extends GraphQLObjectType {
758
786
  extraFields = /* @__PURE__ */ new Map();
787
+ hiddenFields = /* @__PURE__ */ new Set();
759
788
  weaverContext;
760
789
  resolverOptions;
761
790
  constructor(objectOrGetter, options = {}) {
@@ -773,6 +802,9 @@ var LoomObjectType = class extends GraphQLObjectType {
773
802
  this.resolverOptions = options.resolverOptions;
774
803
  this.weaverContext = options.weaverContext ?? initWeaverContext();
775
804
  }
805
+ hideField(name) {
806
+ this.hiddenFields.add(name);
807
+ }
776
808
  addField(name, resolver) {
777
809
  const existing = this.extraFields.get(name);
778
810
  if (existing && existing !== resolver) {
@@ -783,23 +815,27 @@ var LoomObjectType = class extends GraphQLObjectType {
783
815
  mergeExtensions(extensions) {
784
816
  this.extensions = deepMerge(this.extensions, extensions);
785
817
  }
786
- extraField;
818
+ extraFieldMap;
787
819
  getFields() {
788
- const fields = super.getFields();
789
- Object.values(fields).forEach(
820
+ const fieldsBySuper = super.getFields();
821
+ Object.values(fieldsBySuper).forEach(
790
822
  (field) => field.type = this.getCacheType(field.type)
791
823
  );
792
- const extraField = provideWeaverContext(
824
+ const extraFields = provideWeaverContext(
793
825
  () => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
794
826
  this.weaverContext
795
827
  );
796
- if (Object.keys(this.extraField ?? {}).join() !== Object.keys(extraField).join()) {
797
- this.extraField = extraField;
828
+ if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) {
829
+ this.extraFieldMap = extraFields;
798
830
  }
799
- return {
800
- ...fields,
801
- ...this.extraField
831
+ const answer = {
832
+ ...fieldsBySuper,
833
+ ...this.extraFieldMap
802
834
  };
835
+ for (const fieldName of this.hiddenFields) {
836
+ delete answer[fieldName];
837
+ }
838
+ return answer;
803
839
  }
804
840
  mapToFieldConfig(map) {
805
841
  const record = {};
@@ -1024,7 +1060,10 @@ var SchemaWeaver = class _SchemaWeaver {
1024
1060
  if (resolverOptions?.extensions && parentObject)
1025
1061
  parentObject.mergeExtensions(resolverOptions.extensions);
1026
1062
  Object.entries(resolver).forEach(([name, operation]) => {
1027
- if (operation.type === "field") {
1063
+ if (operation === FIELD_HIDDEN) {
1064
+ if (parentObject == null) return;
1065
+ parentObject.hideField(name);
1066
+ } else if (operation.type === "field") {
1028
1067
  if (parentObject == null) return;
1029
1068
  parentObject.addField(name, operation);
1030
1069
  } else {
@@ -1131,11 +1170,6 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1131
1170
  weaverContext.interfaceMap?.set(key, interfaceType);
1132
1171
  return interfaceType;
1133
1172
  }
1134
-
1135
- // src/schema/extensions.ts
1136
- function mergeExtensions(...extensionsList) {
1137
- return deepMerge(...extensionsList);
1138
- }
1139
1173
  export {
1140
1174
  ContextMemoization,
1141
1175
  LoomObjectType,
@@ -1144,16 +1178,17 @@ export {
1144
1178
  SchemaWeaver,
1145
1179
  applyMiddlewares,
1146
1180
  baseResolver,
1181
+ collectName,
1147
1182
  collectNames,
1148
1183
  compose,
1149
- createFieldBobbin,
1184
+ createFieldFactory,
1150
1185
  createInputParser,
1151
1186
  createLoom,
1152
1187
  createMemoization,
1153
- createMutationBobbin,
1154
- createQueryBobbin,
1155
- createResolverBobbin,
1156
- createSubscriptionBobbin,
1188
+ createMutationFactory,
1189
+ createQueryFactory,
1190
+ createResolverFactory,
1191
+ createSubscriptionFactory,
1157
1192
  deepMerge,
1158
1193
  defaultSubscriptionResolve,
1159
1194
  ensureInputObjectType,
@@ -1173,7 +1208,6 @@ export {
1173
1208
  mapValue,
1174
1209
  markErrorLocation,
1175
1210
  markLocation,
1176
- mergeExtensions,
1177
1211
  nonNullSilk,
1178
1212
  notNullish,
1179
1213
  nullableSilk,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gqloom/core",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Create GraphQL schema and resolvers with TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,7 +18,8 @@
18
18
  }
19
19
  },
20
20
  "scripts": {
21
- "build": "tsup"
21
+ "build": "tsup",
22
+ "release": "commit-and-tag-version"
22
23
  },
23
24
  "files": [
24
25
  "dist"
@@ -37,6 +38,12 @@
37
38
  ],
38
39
  "author": "xcfox",
39
40
  "license": "MIT",
41
+ "homepage": "https://gqloom.dev/",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/modevol-com/gqloom.git",
45
+ "directory": "packages/core"
46
+ },
40
47
  "publishConfig": {
41
48
  "access": "public"
42
49
  }