@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/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.1",
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"
@@ -26,9 +27,23 @@
26
27
  "peerDependencies": {
27
28
  "graphql": ">= 16.8.0"
28
29
  },
29
- "keywords": [],
30
+ "keywords": [
31
+ "gqloom",
32
+ "graphql",
33
+ "schema",
34
+ "typescript",
35
+ "valibot",
36
+ "zod",
37
+ "yup"
38
+ ],
30
39
  "author": "xcfox",
31
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
+ },
32
47
  "publishConfig": {
33
48
  "access": "public"
34
49
  }