type-graphql

  • Version 2.0.0-rc.1
  • Published
  • 326 kB
  • 6 dependencies
  • MIT license

Install

npm i type-graphql
yarn add type-graphql
pnpm add type-graphql

Overview

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Variables

variable defaultPrintSchemaOptions

const defaultPrintSchemaOptions: PrintSchemaOptions;

    variable Float

    const Float: any;

      variable graphQLPeerDependencyVersion

      const graphQLPeerDependencyVersion: string;

        variable ID

        const ID: any;

          variable Int

          const Int: any;

            Functions

            function Arg

            Arg: {
            (name: string, options?: ArgOptions): ParameterDecorator;
            (
            name: string,
            returnTypeFunc: ReturnTypeFunc,
            options?: ArgOptions
            ): ParameterDecorator;
            };

              function Args

              Args: {
              (): ParameterDecorator;
              (options: ValidateOptions): ParameterDecorator;
              (
              paramTypeFunction: ReturnTypeFunc,
              options?: ValidateOptions
              ): ParameterDecorator;
              };

                function ArgsType

                ArgsType: () => ClassDecorator;

                  function Authorized

                  Authorized: {
                  (): MethodAndPropDecorator;
                  <RoleType = string>(roles: readonly RoleType[]): MethodAndPropDecorator;
                  <RoleType = string>(...roles: readonly RoleType[]): MethodAndPropDecorator;
                  };

                    function buildSchema

                    buildSchema: (options: BuildSchemaOptions) => Promise<GraphQLSchema>;

                      function buildSchemaSync

                      buildSchemaSync: (options: BuildSchemaOptions) => GraphQLSchema;

                        function buildTypeDefsAndResolvers

                        buildTypeDefsAndResolvers: (
                        options: BuildSchemaOptions
                        ) => Promise<{ typeDefs: string; resolvers: import('..').ResolversMap }>;

                          function buildTypeDefsAndResolversSync

                          buildTypeDefsAndResolversSync: (options: BuildSchemaOptions) => {
                          typeDefs: string;
                          resolvers: import('..').ResolversMap;
                          };

                            function createMethodDecorator

                            createMethodDecorator: <TContextType extends object = object>(
                            resolver: MiddlewareFn<TContextType>
                            ) => MethodDecorator;

                              function createParamDecorator

                              createParamDecorator: <TContextType extends object = object>(
                              resolver: (resolverData: ResolverData<TContextType>) => any
                              ) => ParameterDecorator;

                                function createResolversMap

                                createResolversMap: (schema: GraphQLSchema) => ResolversMap;

                                  function createUnionType

                                  createUnionType: <T extends readonly ClassType<object, any[]>[]>(
                                  config: UnionTypeConfig<T>
                                  ) => UnionFromClasses<T>;

                                    function Ctx

                                    Ctx: (propertyName?: string) => ParameterDecorator;

                                      function Directive

                                      Directive: (
                                      sdl: string
                                      ) => MethodAndPropDecorator & ClassDecorator & ParameterDecorator;

                                        function emitSchemaDefinitionFile

                                        emitSchemaDefinitionFile: (
                                        schemaFilePath: string,
                                        schema: GraphQLSchema,
                                        options?: PrintSchemaOptions
                                        ) => Promise<void>;

                                          function emitSchemaDefinitionFileSync

                                          emitSchemaDefinitionFileSync: (
                                          schemaFilePath: string,
                                          schema: GraphQLSchema,
                                          options?: PrintSchemaOptions
                                          ) => void;

                                            function ensureInstalledCorrectGraphQLPackage

                                            ensureInstalledCorrectGraphQLPackage: () => void;

                                              function Extensions

                                              Extensions: (
                                              extensions: ExtensionsMetadata
                                              ) => MethodAndPropDecorator & ClassDecorator;

                                                function Field

                                                Field: {
                                                (): MethodAndPropDecorator;
                                                (options: FieldOptions): MethodAndPropDecorator;
                                                (
                                                returnTypeFunction?: ReturnTypeFunc,
                                                options?: FieldOptions
                                                ): MethodAndPropDecorator;
                                                };

                                                  function FieldResolver

                                                  FieldResolver: {
                                                  (): MethodDecorator;
                                                  (options: AdvancedOptions): MethodDecorator;
                                                  (
                                                  returnTypeFunction?: ReturnTypeFunc,
                                                  options?: AdvancedOptions
                                                  ): MethodDecorator;
                                                  };

                                                    function getMetadataStorage

                                                    getMetadataStorage: () => MetadataStorage;

                                                      function Info

                                                      Info: () => ParameterDecorator;

                                                        function InputType

                                                        InputType: {
                                                        (): ClassDecorator;
                                                        (options: DescriptionOptions): ClassDecorator;
                                                        (name: string, options?: DescriptionOptions): ClassDecorator;
                                                        };

                                                          function InterfaceType

                                                          InterfaceType: {
                                                          (): ClassDecorator;
                                                          (options: InterfaceTypeOptions): ClassDecorator;
                                                          (name: string, options?: InterfaceTypeOptions): ClassDecorator;
                                                          };

                                                            function Mutation

                                                            Mutation: {
                                                            (): MethodDecorator;
                                                            (options: AdvancedOptions): MethodDecorator;
                                                            (returnTypeFunc: ReturnTypeFunc, options?: AdvancedOptions): MethodDecorator;
                                                            };

                                                              function ObjectType

                                                              ObjectType: {
                                                              (): ClassDecorator;
                                                              (options: ObjectTypeOptions): ClassDecorator;
                                                              (name: string, options?: ObjectTypeOptions): ClassDecorator;
                                                              };

                                                                function Query

                                                                Query: {
                                                                (): MethodDecorator;
                                                                (options: AdvancedOptions): MethodDecorator;
                                                                (returnTypeFunc: ReturnTypeFunc, options?: AdvancedOptions): MethodDecorator;
                                                                };

                                                                  function registerEnumType

                                                                  registerEnumType: <TEnum extends object>(
                                                                  enumObj: TEnum,
                                                                  enumConfig: EnumConfig<TEnum>
                                                                  ) => void;

                                                                    function Resolver

                                                                    Resolver: {
                                                                    (): ClassDecorator;
                                                                    (typeFunc: ClassTypeResolver): ClassDecorator;
                                                                    (objectType: ClassType<object, any[]>): ClassDecorator;
                                                                    };

                                                                      function Root

                                                                      Root: (propertyName?: string) => ParameterDecorator;

                                                                        function Subscription

                                                                        Subscription: {
                                                                        (options: SubscriptionOptions): MethodDecorator;
                                                                        (returnTypeFunc: ReturnTypeFunc, options: SubscriptionOptions): MethodDecorator;
                                                                        };

                                                                          function UseMiddleware

                                                                          UseMiddleware: {
                                                                          (middlewares: Array<Middleware<any>>): MethodAndPropDecorator;
                                                                          (...middlewares: Middleware<any>[]): MethodAndPropDecorator;
                                                                          };

                                                                            Classes

                                                                            class ArgumentValidationError

                                                                            class ArgumentValidationError extends GraphQLError {}

                                                                              constructor

                                                                              constructor(validationErrors: ValidationError[]);

                                                                                property extensions

                                                                                readonly extensions: {
                                                                                [attributeName: string]: unknown;
                                                                                code: 'BAD_USER_INPUT';
                                                                                validationErrors: ValidationError[];
                                                                                };

                                                                                  class AuthenticationError

                                                                                  class AuthenticationError extends GraphQLError {}

                                                                                    constructor

                                                                                    constructor(message?: string);

                                                                                      property extensions

                                                                                      readonly extensions: {
                                                                                      [attributeName: string]: unknown;
                                                                                      code: 'UNAUTHENTICATED';
                                                                                      };

                                                                                        class AuthorizationError

                                                                                        class AuthorizationError extends GraphQLError {}

                                                                                          constructor

                                                                                          constructor(message?: string);

                                                                                            property extensions

                                                                                            readonly extensions: { [attributeName: string]: unknown; code: 'UNAUTHORIZED' };

                                                                                              class CannotDetermineGraphQLTypeError

                                                                                              class CannotDetermineGraphQLTypeError extends Error {}

                                                                                                constructor

                                                                                                constructor(
                                                                                                typeKind: 'input' | 'output',
                                                                                                typeName: string,
                                                                                                propertyKey: string,
                                                                                                parameterIndex?: number,
                                                                                                argName?: string
                                                                                                );

                                                                                                  class ConflictingDefaultValuesError

                                                                                                  class ConflictingDefaultValuesError extends Error {}

                                                                                                    constructor

                                                                                                    constructor(
                                                                                                    typeName: string,
                                                                                                    fieldName: string,
                                                                                                    defaultValueFromDecorator: {},
                                                                                                    defaultValueFromInitializer: {}
                                                                                                    );

                                                                                                      class GeneratingSchemaError

                                                                                                      class GeneratingSchemaError extends Error {}

                                                                                                        constructor

                                                                                                        constructor(details: readonly GraphQLError[]);

                                                                                                          property details

                                                                                                          details: readonly GraphQLError[];

                                                                                                            class InterfaceResolveTypeError

                                                                                                            class InterfaceResolveTypeError extends Error {}

                                                                                                              constructor

                                                                                                              constructor(interfaceMetadata: ClassMetadata);

                                                                                                                class InvalidDirectiveError

                                                                                                                class InvalidDirectiveError extends Error {}

                                                                                                                  constructor

                                                                                                                  constructor(msg: string);

                                                                                                                    class MissingPubSubError

                                                                                                                    class MissingPubSubError extends Error {}

                                                                                                                      constructor

                                                                                                                      constructor();

                                                                                                                        class MissingSubscriptionTopicsError

                                                                                                                        class MissingSubscriptionTopicsError extends Error {}

                                                                                                                          constructor

                                                                                                                          constructor(target: Function, methodName: string);

                                                                                                                            class NoExplicitTypeError

                                                                                                                            class NoExplicitTypeError extends Error {}

                                                                                                                              constructor

                                                                                                                              constructor(
                                                                                                                              typeName: string,
                                                                                                                              propertyKey: string,
                                                                                                                              parameterIndex?: number,
                                                                                                                              argName?: string
                                                                                                                              );

                                                                                                                                class ReflectMetadataMissingError

                                                                                                                                class ReflectMetadataMissingError extends Error {}

                                                                                                                                  constructor

                                                                                                                                  constructor();

                                                                                                                                    class SymbolKeysNotSupportedError

                                                                                                                                    class SymbolKeysNotSupportedError extends Error {}

                                                                                                                                      constructor

                                                                                                                                      constructor();

                                                                                                                                        class UnionResolveTypeError

                                                                                                                                        class UnionResolveTypeError extends Error {}

                                                                                                                                          constructor

                                                                                                                                          constructor(unionMetadata: UnionMetadata);

                                                                                                                                            class UnmetGraphQLPeerDependencyError

                                                                                                                                            class UnmetGraphQLPeerDependencyError extends Error {}

                                                                                                                                              constructor

                                                                                                                                              constructor(graphQLVersion: string, graphQLPeerDependencyVersion: string);

                                                                                                                                                class WrongNullableListOptionError

                                                                                                                                                class WrongNullableListOptionError extends Error {}

                                                                                                                                                  constructor

                                                                                                                                                  constructor(
                                                                                                                                                  targetName: string,
                                                                                                                                                  propertyName: string,
                                                                                                                                                  nullable: boolean | NullableListOptions
                                                                                                                                                  );

                                                                                                                                                    Interfaces

                                                                                                                                                    interface AuthCheckerInterface

                                                                                                                                                    interface AuthCheckerInterface<
                                                                                                                                                    TContextType extends object = object,
                                                                                                                                                    TRoleType = string
                                                                                                                                                    > {}

                                                                                                                                                      method check

                                                                                                                                                      check: (
                                                                                                                                                      resolverData: ResolverData<TContextType>,
                                                                                                                                                      roles: TRoleType[]
                                                                                                                                                      ) => boolean | Promise<boolean>;

                                                                                                                                                        interface ContainerType

                                                                                                                                                        interface ContainerType {}

                                                                                                                                                          method get

                                                                                                                                                          get: (someClass: any, resolverData: ResolverData<any>) => any | Promise<any>;

                                                                                                                                                            interface MiddlewareInterface

                                                                                                                                                            interface MiddlewareInterface<TContext extends object = object> {}

                                                                                                                                                              property use

                                                                                                                                                              use: MiddlewareFn<TContext>;

                                                                                                                                                                interface PrintSchemaOptions

                                                                                                                                                                interface PrintSchemaOptions {}

                                                                                                                                                                  property sortedSchema

                                                                                                                                                                  sortedSchema: boolean;

                                                                                                                                                                    interface PubSub

                                                                                                                                                                    interface PubSub {}

                                                                                                                                                                      method publish

                                                                                                                                                                      publish: (routingKey: string, ...args: unknown[]) => void;
                                                                                                                                                                      • Publish a value for a given topic.

                                                                                                                                                                      method subscribe

                                                                                                                                                                      subscribe: (routingKey: string, dynamicId?: unknown) => AsyncIterable<unknown>;
                                                                                                                                                                      • Subscribe to a topic.

                                                                                                                                                                      interface ResolverData

                                                                                                                                                                      interface ResolverData<TContextType extends object = object> {}

                                                                                                                                                                        property args

                                                                                                                                                                        args: ArgsDictionary;

                                                                                                                                                                          property context

                                                                                                                                                                          context: TContextType;

                                                                                                                                                                            property info

                                                                                                                                                                            info: GraphQLResolveInfo;

                                                                                                                                                                              property root

                                                                                                                                                                              root: any;

                                                                                                                                                                                interface ResolverOptions

                                                                                                                                                                                interface ResolverOptions<TSource = any, TContext = any> {}

                                                                                                                                                                                  property fragment

                                                                                                                                                                                  fragment?: string;

                                                                                                                                                                                    property resolve

                                                                                                                                                                                    resolve?: GraphQLFieldResolver<TSource, TContext>;

                                                                                                                                                                                      property subscribe

                                                                                                                                                                                      subscribe?: GraphQLFieldResolver<TSource, TContext>;

                                                                                                                                                                                        interface SubscribeResolverData

                                                                                                                                                                                        interface SubscribeResolverData<
                                                                                                                                                                                        TSource = any,
                                                                                                                                                                                        TArgs = ArgsDictionary,
                                                                                                                                                                                        TContext = {}
                                                                                                                                                                                        > {}

                                                                                                                                                                                          property args

                                                                                                                                                                                          args: TArgs;

                                                                                                                                                                                            property context

                                                                                                                                                                                            context: TContext;

                                                                                                                                                                                              property info

                                                                                                                                                                                              info: GraphQLResolveInfo;

                                                                                                                                                                                                property source

                                                                                                                                                                                                source: TSource;

                                                                                                                                                                                                  interface SubscriptionHandlerData

                                                                                                                                                                                                  interface SubscriptionHandlerData<
                                                                                                                                                                                                  TPayload = any,
                                                                                                                                                                                                  TArgs = ArgsDictionary,
                                                                                                                                                                                                  TContext = {}
                                                                                                                                                                                                  > {}

                                                                                                                                                                                                    property args

                                                                                                                                                                                                    args: TArgs;

                                                                                                                                                                                                      property context

                                                                                                                                                                                                      context: TContext;

                                                                                                                                                                                                        property info

                                                                                                                                                                                                        info: GraphQLResolveInfo;

                                                                                                                                                                                                          property payload

                                                                                                                                                                                                          payload: TPayload;

                                                                                                                                                                                                            Type Aliases

                                                                                                                                                                                                            type ArgOptions

                                                                                                                                                                                                            type ArgOptions = DecoratorTypeOptions &
                                                                                                                                                                                                            DescriptionOptions &
                                                                                                                                                                                                            ValidateOptions &
                                                                                                                                                                                                            DeprecationOptions;

                                                                                                                                                                                                              type ArgsDictionary

                                                                                                                                                                                                              type ArgsDictionary = Record<string, any>;

                                                                                                                                                                                                                type AuthChecker

                                                                                                                                                                                                                type AuthChecker<TContextType extends object = object, TRoleType = string> =
                                                                                                                                                                                                                | AuthCheckerFn<TContextType, TRoleType>
                                                                                                                                                                                                                | ClassType<AuthCheckerInterface<TContextType, TRoleType>>;

                                                                                                                                                                                                                  type AuthCheckerFn

                                                                                                                                                                                                                  type AuthCheckerFn<TContextType extends object = object, TRoleType = string> = (
                                                                                                                                                                                                                  resolverData: ResolverData<TContextType>,
                                                                                                                                                                                                                  roles: TRoleType[]
                                                                                                                                                                                                                  ) => boolean | Promise<boolean>;

                                                                                                                                                                                                                    type AuthMode

                                                                                                                                                                                                                    type AuthMode = 'error' | 'null';

                                                                                                                                                                                                                      type BuildSchemaOptions

                                                                                                                                                                                                                      type BuildSchemaOptions = {
                                                                                                                                                                                                                      /** Array of resolvers classes to resolver files */
                                                                                                                                                                                                                      resolvers: NonEmptyArray<Function>;
                                                                                                                                                                                                                      /**
                                                                                                                                                                                                                      * Path to the file to where emit the schema
                                                                                                                                                                                                                      * or config object with print schema options
                                                                                                                                                                                                                      * or `true` for the default `./schema.graphql` one
                                                                                                                                                                                                                      */
                                                                                                                                                                                                                      emitSchemaFile?: string | boolean | EmitSchemaFileOptions;
                                                                                                                                                                                                                      } & Omit<SchemaGeneratorOptions, 'resolvers'>;

                                                                                                                                                                                                                        type ClassType

                                                                                                                                                                                                                        type ClassType<
                                                                                                                                                                                                                        T extends object = object,
                                                                                                                                                                                                                        Arguments extends unknown[] = any[]
                                                                                                                                                                                                                        > = Constructor<T, Arguments> & {
                                                                                                                                                                                                                        prototype: T;
                                                                                                                                                                                                                        };
                                                                                                                                                                                                                        • Matches a [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).

                                                                                                                                                                                                                        type Complexity

                                                                                                                                                                                                                        type Complexity = ComplexityEstimator | number;

                                                                                                                                                                                                                          type Constructor

                                                                                                                                                                                                                          type Constructor<T extends object, Arguments extends unknown[] = any[]> = new (
                                                                                                                                                                                                                          ...arguments_: Arguments
                                                                                                                                                                                                                          ) => T;
                                                                                                                                                                                                                          • Matches a [class constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).

                                                                                                                                                                                                                          type ContainerGetter

                                                                                                                                                                                                                          type ContainerGetter<TContext extends object> = (
                                                                                                                                                                                                                          resolverData: ResolverData<TContext>
                                                                                                                                                                                                                          ) => ContainerType;

                                                                                                                                                                                                                            type EnumResolver

                                                                                                                                                                                                                            type EnumResolver = Record<string, string | number>;

                                                                                                                                                                                                                              type Except

                                                                                                                                                                                                                              type Except<
                                                                                                                                                                                                                              ObjectType,
                                                                                                                                                                                                                              KeysType extends keyof ObjectType,
                                                                                                                                                                                                                              Options extends ExceptOptions = {
                                                                                                                                                                                                                              requireExactProps: false;
                                                                                                                                                                                                                              }
                                                                                                                                                                                                                              > = {
                                                                                                                                                                                                                              [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
                                                                                                                                                                                                                              } & (Options['requireExactProps'] extends true
                                                                                                                                                                                                                              ? Partial<Record<KeysType, never>>
                                                                                                                                                                                                                              : {});
                                                                                                                                                                                                                              • Create a type from an object type without certain keys.

                                                                                                                                                                                                                                We recommend setting the requireExactProps option to true.

                                                                                                                                                                                                                                This type is a stricter version of [Omit](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The Omit type does not restrict the omitted keys to be keys present on the given type, while Except does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.

                                                                                                                                                                                                                                This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).

                                                                                                                                                                                                                                Example 1

                                                                                                                                                                                                                                import {Except} from 'type-fest';
                                                                                                                                                                                                                                type Foo = {
                                                                                                                                                                                                                                a: number;
                                                                                                                                                                                                                                b: string;
                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                type FooWithoutA = Except<Foo, 'a'>;
                                                                                                                                                                                                                                //=> {b: string}
                                                                                                                                                                                                                                const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
                                                                                                                                                                                                                                //=> errors: 'a' does not exist in type '{ b: string; }'
                                                                                                                                                                                                                                type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
                                                                                                                                                                                                                                //=> {a: number} & Partial<Record<"b", never>>
                                                                                                                                                                                                                                const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
                                                                                                                                                                                                                                //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.

                                                                                                                                                                                                                              type FieldOptions

                                                                                                                                                                                                                              type FieldOptions = AdvancedOptions & {
                                                                                                                                                                                                                              /** Set to `true` to disable auth and all middlewares stack for this field resolver */
                                                                                                                                                                                                                              simple?: boolean;
                                                                                                                                                                                                                              };

                                                                                                                                                                                                                                type InputTypeOptions

                                                                                                                                                                                                                                type InputTypeOptions = DescriptionOptions;

                                                                                                                                                                                                                                  type InterfaceTypeOptions

                                                                                                                                                                                                                                  type InterfaceTypeOptions = DescriptionOptions &
                                                                                                                                                                                                                                  ResolveTypeOptions &
                                                                                                                                                                                                                                  ImplementsClassOptions & {
                                                                                                                                                                                                                                  /**
                                                                                                                                                                                                                                  * Set to false to prevent emitting in schema all object types
                                                                                                                                                                                                                                  * that implements this interface type.
                                                                                                                                                                                                                                  */
                                                                                                                                                                                                                                  autoRegisterImplementations?: boolean;
                                                                                                                                                                                                                                  };

                                                                                                                                                                                                                                    type IsEqual

                                                                                                                                                                                                                                    type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B
                                                                                                                                                                                                                                    ? 1
                                                                                                                                                                                                                                    : 2
                                                                                                                                                                                                                                    ? true
                                                                                                                                                                                                                                    : false;

                                                                                                                                                                                                                                    type Maybe

                                                                                                                                                                                                                                    type Maybe<T> = T | null | undefined;

                                                                                                                                                                                                                                      type MaybePromise

                                                                                                                                                                                                                                      type MaybePromise<T> = Promise<T> | T;

                                                                                                                                                                                                                                        type MergeExclusive

                                                                                                                                                                                                                                        type MergeExclusive<FirstType, SecondType> = FirstType | SecondType extends object
                                                                                                                                                                                                                                        ?
                                                                                                                                                                                                                                        | (Without<FirstType, SecondType> & SecondType)
                                                                                                                                                                                                                                        | (Without<SecondType, FirstType> & FirstType)
                                                                                                                                                                                                                                        : FirstType | SecondType;
                                                                                                                                                                                                                                        • Create a type that has mutually exclusive keys.

                                                                                                                                                                                                                                          This type was inspired by [this comment](https://github.com/Microsoft/TypeScript/issues/14094#issuecomment-373782604).

                                                                                                                                                                                                                                          This type works with a helper type, called Without. Without<FirstType, SecondType> produces a type that has only keys from FirstType which are not present on SecondType and sets the value type for these keys to never. This helper type is then used in MergeExclusive to remove keys from either FirstType or SecondType.

                                                                                                                                                                                                                                          Example 1

                                                                                                                                                                                                                                          import {MergeExclusive} from 'type-fest';
                                                                                                                                                                                                                                          interface ExclusiveVariation1 {
                                                                                                                                                                                                                                          exclusive1: boolean;
                                                                                                                                                                                                                                          }
                                                                                                                                                                                                                                          interface ExclusiveVariation2 {
                                                                                                                                                                                                                                          exclusive2: string;
                                                                                                                                                                                                                                          }
                                                                                                                                                                                                                                          type ExclusiveOptions = MergeExclusive<ExclusiveVariation1, ExclusiveVariation2>;
                                                                                                                                                                                                                                          let exclusiveOptions: ExclusiveOptions;
                                                                                                                                                                                                                                          exclusiveOptions = {exclusive1: true};
                                                                                                                                                                                                                                          //=> Works
                                                                                                                                                                                                                                          exclusiveOptions = {exclusive2: 'hi'};
                                                                                                                                                                                                                                          //=> Works
                                                                                                                                                                                                                                          exclusiveOptions = {exclusive1: true, exclusive2: 'hi'};
                                                                                                                                                                                                                                          //=> Error

                                                                                                                                                                                                                                        type MiddlewareFn

                                                                                                                                                                                                                                        type MiddlewareFn<TContext extends object = object> = (
                                                                                                                                                                                                                                        action: ResolverData<TContext>,
                                                                                                                                                                                                                                        next: NextFn
                                                                                                                                                                                                                                        ) => Promise<any>;

                                                                                                                                                                                                                                          type NextFn

                                                                                                                                                                                                                                          type NextFn = () => Promise<any>;

                                                                                                                                                                                                                                            type NonEmptyArray

                                                                                                                                                                                                                                            type NonEmptyArray<T> = readonly [T, ...T[]] | [T, ...T[]];

                                                                                                                                                                                                                                              type ObjectTypeOptions

                                                                                                                                                                                                                                              type ObjectTypeOptions = DescriptionOptions &
                                                                                                                                                                                                                                              ImplementsClassOptions & {
                                                                                                                                                                                                                                              /** Set to `true` to disable auth and all middlewares stack for all this Object Type fields resolvers */
                                                                                                                                                                                                                                              simpleResolvers?: boolean;
                                                                                                                                                                                                                                              };

                                                                                                                                                                                                                                                type ParameterDecorator

                                                                                                                                                                                                                                                type ParameterDecorator = (
                                                                                                                                                                                                                                                target: Object,
                                                                                                                                                                                                                                                propertyKey: string | symbol, // Removed 'undefined' from TS 5.0
                                                                                                                                                                                                                                                parameterIndex: number
                                                                                                                                                                                                                                                ) => void;

                                                                                                                                                                                                                                                  type ResolverInterface

                                                                                                                                                                                                                                                  type ResolverInterface<T extends object> = {
                                                                                                                                                                                                                                                  [P in keyof T]?: (root: T, ...args: any[]) => T[P] | Promise<T[P]>;
                                                                                                                                                                                                                                                  };
                                                                                                                                                                                                                                                  • Resolver classes can implement this type to provide a proper resolver method signatures for fields of T.

                                                                                                                                                                                                                                                  type ResolverObject

                                                                                                                                                                                                                                                  type ResolverObject<TSource = any, TContext = any> = Record<
                                                                                                                                                                                                                                                  string,
                                                                                                                                                                                                                                                  ResolverOptions<TSource, TContext> | GraphQLFieldResolver<TSource, TContext>
                                                                                                                                                                                                                                                  >;

                                                                                                                                                                                                                                                    type ResolversMap

                                                                                                                                                                                                                                                    type ResolversMap<TSource = any, TContext = any> = Record<
                                                                                                                                                                                                                                                    string,
                                                                                                                                                                                                                                                    | ResolverObject<TSource, TContext>
                                                                                                                                                                                                                                                    | ResolverOptions<TSource, TContext>
                                                                                                                                                                                                                                                    | GraphQLScalarType
                                                                                                                                                                                                                                                    | EnumResolver
                                                                                                                                                                                                                                                    >;

                                                                                                                                                                                                                                                      type SetRequired

                                                                                                                                                                                                                                                      type SetRequired<BaseType, Keys extends keyof BaseType> = Simplify<
                                                                                                                                                                                                                                                      Except<BaseType, Keys> & Required<Pick<BaseType, Keys>>
                                                                                                                                                                                                                                                      >;
                                                                                                                                                                                                                                                      • Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the SetOptional type.

                                                                                                                                                                                                                                                        Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.

                                                                                                                                                                                                                                                        Example 1

                                                                                                                                                                                                                                                        import {SetRequired} from 'type-fest';
                                                                                                                                                                                                                                                        type Foo = {
                                                                                                                                                                                                                                                        a?: number;
                                                                                                                                                                                                                                                        b: string;
                                                                                                                                                                                                                                                        c?: boolean;
                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                        type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
                                                                                                                                                                                                                                                        // type SomeRequired = {
                                                                                                                                                                                                                                                        // a?: number;
                                                                                                                                                                                                                                                        // b: string; // Was already required and still is.
                                                                                                                                                                                                                                                        // c: boolean; // Is now required.
                                                                                                                                                                                                                                                        // }

                                                                                                                                                                                                                                                      type Simplify

                                                                                                                                                                                                                                                      type Simplify<T> = {
                                                                                                                                                                                                                                                      [KeyType in keyof T]: T[KeyType];
                                                                                                                                                                                                                                                      } & {};
                                                                                                                                                                                                                                                      • Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.

                                                                                                                                                                                                                                                        Example 1

                                                                                                                                                                                                                                                        import {Simplify} from 'type-fest';
                                                                                                                                                                                                                                                        type PositionProps = {
                                                                                                                                                                                                                                                        top: number;
                                                                                                                                                                                                                                                        left: number;
                                                                                                                                                                                                                                                        };
                                                                                                                                                                                                                                                        type SizeProps = {
                                                                                                                                                                                                                                                        width: number;
                                                                                                                                                                                                                                                        height: number;
                                                                                                                                                                                                                                                        };
                                                                                                                                                                                                                                                        // In your editor, hovering over `Props` will show a flattened object with all the properties.
                                                                                                                                                                                                                                                        type Props = Simplify<PositionProps & SizeProps>;

                                                                                                                                                                                                                                                        Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the value's type definition was defined as an interface. In the following example, fn requires an argument of type Record<string, unknown>. If the value is defined as a literal, then it is assignable. And if the value is defined as type using the Simplify utility the value is assignable. But if the value is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.

                                                                                                                                                                                                                                                        If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the value can be defined as const value: Simplify<SomeInterface> = .... Then value will be assignable to the fn argument. Or the value can be cast as Simplify<SomeInterface> if you can't re-declare the value.

                                                                                                                                                                                                                                                        Example 2

                                                                                                                                                                                                                                                        import {Simplify} from 'type-fest';
                                                                                                                                                                                                                                                        interface SomeInterface {
                                                                                                                                                                                                                                                        foo: number;
                                                                                                                                                                                                                                                        bar?: string;
                                                                                                                                                                                                                                                        baz: number | undefined;
                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                        type SomeType = {
                                                                                                                                                                                                                                                        foo: number;
                                                                                                                                                                                                                                                        bar?: string;
                                                                                                                                                                                                                                                        baz: number | undefined;
                                                                                                                                                                                                                                                        };
                                                                                                                                                                                                                                                        const literal = {foo: 123, bar: 'hello', baz: 456};
                                                                                                                                                                                                                                                        const someType: SomeType = literal;
                                                                                                                                                                                                                                                        const someInterface: SomeInterface = literal;
                                                                                                                                                                                                                                                        function fn(object: Record<string, unknown>): void {}
                                                                                                                                                                                                                                                        fn(literal); // Good: literal object type is sealed
                                                                                                                                                                                                                                                        fn(someType); // Good: type is sealed
                                                                                                                                                                                                                                                        fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
                                                                                                                                                                                                                                                        fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`

                                                                                                                                                                                                                                                        https://github.com/microsoft/TypeScript/issues/15300

                                                                                                                                                                                                                                                      type SubscriptionOptions

                                                                                                                                                                                                                                                      type SubscriptionOptions = AdvancedOptions &
                                                                                                                                                                                                                                                      MergeExclusive<PubSubOptions, SubscribeOptions>;

                                                                                                                                                                                                                                                        type TypeResolver

                                                                                                                                                                                                                                                        type TypeResolver<TSource, TContext> = (
                                                                                                                                                                                                                                                        ...args: Parameters<GraphQLTypeResolver<TSource, TContext>>
                                                                                                                                                                                                                                                        ) => MaybePromise<Maybe<string | ClassType>>;

                                                                                                                                                                                                                                                          type ValidatorFn

                                                                                                                                                                                                                                                          type ValidatorFn<TContext extends object = object> = (
                                                                                                                                                                                                                                                          /**
                                                                                                                                                                                                                                                          * The value of the argument.
                                                                                                                                                                                                                                                          * It can by of any type, which means:
                                                                                                                                                                                                                                                          * - undefined or null (if the argument is nullable)
                                                                                                                                                                                                                                                          * - primitive type (string, number, boolean)
                                                                                                                                                                                                                                                          * - underlying scalar type (Date, Buffer, etc.)
                                                                                                                                                                                                                                                          * - object type (arg type class instance)
                                                                                                                                                                                                                                                          * - array type (array of any of the above)
                                                                                                                                                                                                                                                          */
                                                                                                                                                                                                                                                          argValue: any | undefined,
                                                                                                                                                                                                                                                          argType: TypeValue,
                                                                                                                                                                                                                                                          resolverData: ResolverData<TContext>
                                                                                                                                                                                                                                                          ) => void | Promise<void>;

                                                                                                                                                                                                                                                            Package Files (70)

                                                                                                                                                                                                                                                            Dependencies (6)

                                                                                                                                                                                                                                                            Dev Dependencies (69)

                                                                                                                                                                                                                                                            Peer Dependencies (3)

                                                                                                                                                                                                                                                            Badge

                                                                                                                                                                                                                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/type-graphql.

                                                                                                                                                                                                                                                            • Markdown
                                                                                                                                                                                                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/type-graphql)
                                                                                                                                                                                                                                                            • HTML
                                                                                                                                                                                                                                                              <a href="https://www.jsdocs.io/package/type-graphql"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>