@graphql-codegen/typescript

  • Version 2.4.11
  • Published
  • 58 kB
  • 5 dependencies
  • MIT license

Install

npm i @graphql-codegen/typescript
yarn add @graphql-codegen/typescript
pnpm add @graphql-codegen/typescript

Overview

GraphQL Code Generator plugin for generating TypeScript types

Index

Variables

variable EXACT_SIGNATURE

const EXACT_SIGNATURE: string;

    variable MAKE_MAYBE_SIGNATURE

    const MAKE_MAYBE_SIGNATURE: string;

      variable MAKE_OPTIONAL_SIGNATURE

      const MAKE_OPTIONAL_SIGNATURE: string;

        variable plugin

        const plugin: PluginFunction<TypeScriptPluginConfig, Types.ComplexPluginOutput>;

          Functions

          function includeIntrospectionTypesDefinitions

          includeIntrospectionTypesDefinitions: (
          schema: GraphQLSchema,
          documents: Types.DocumentFile[],
          config: TypeScriptPluginConfig
          ) => string[];

            Classes

            class TsIntrospectionVisitor

            class TsIntrospectionVisitor extends TsVisitor {}

              constructor

              constructor(
              schema: GraphQLSchema,
              pluginConfig: TypeScriptPluginConfig,
              typesToInclude: GraphQLNamedType[]
              );

                method DirectiveDefinition

                DirectiveDefinition: () => any;

                  method EnumTypeDefinition

                  EnumTypeDefinition: (node: EnumTypeDefinitionNode) => string;

                    method ObjectTypeDefinition

                    ObjectTypeDefinition: (
                    node: ObjectTypeDefinitionNode,
                    key: string | number,
                    parent: any
                    ) => string;

                      class TsVisitor

                      class TsVisitor<
                      TRawConfig extends TypeScriptPluginConfig = TypeScriptPluginConfig,
                      TParsedConfig extends TypeScriptPluginParsedConfig = TypeScriptPluginParsedConfig
                      > extends BaseTypesVisitor<TRawConfig, TParsedConfig> {}

                        constructor

                        constructor(
                        schema: GraphQLSchema,
                        pluginConfig: TypeScriptPluginConfig,
                        additionalConfig?: Partial<TParsedConfig>
                        );

                          method clearOptional

                          protected clearOptional: (str: string) => string;

                            method EnumTypeDefinition

                            EnumTypeDefinition: (node: EnumTypeDefinitionNode) => string;

                              method FieldDefinition

                              FieldDefinition: (
                              node: FieldDefinitionNode,
                              key?: number | string,
                              parent?: any
                              ) => string;

                                method getExactDefinition

                                getExactDefinition: () => string;

                                  method getExportPrefix

                                  protected getExportPrefix: () => string;

                                    method getInputMaybeValue

                                    getInputMaybeValue: () => string;

                                      method getMakeMaybeDefinition

                                      getMakeMaybeDefinition: () => string;

                                        method getMakeOptionalDefinition

                                        getMakeOptionalDefinition: () => string;

                                          method getMaybeValue

                                          getMaybeValue: () => string;

                                            method getMaybeWrapper

                                            getMaybeWrapper: (ancestors: any) => string;

                                              method getPunctuation

                                              protected getPunctuation: (_declarationKind: DeclarationKind) => string;

                                                method getWrapperDefinitions

                                                getWrapperDefinitions: () => string[];

                                                  method InputValueDefinition

                                                  InputValueDefinition: (
                                                  node: InputValueDefinitionNode,
                                                  key?: number | string,
                                                  parent?: any
                                                  ) => string;

                                                    method ListType

                                                    ListType: (
                                                    node: ListTypeNode,
                                                    key: any,
                                                    parent: any,
                                                    path: any,
                                                    ancestors: any
                                                    ) => string;

                                                      method NamedType

                                                      NamedType: (
                                                      node: NamedTypeNode,
                                                      key: any,
                                                      parent: any,
                                                      path: any,
                                                      ancestors: any
                                                      ) => string;

                                                        method NonNullType

                                                        NonNullType: (node: NonNullTypeNode) => string;

                                                          method UnionTypeDefinition

                                                          UnionTypeDefinition: (
                                                          node: UnionTypeDefinitionNode,
                                                          key: string | number | undefined,
                                                          parent: any
                                                          ) => string;

                                                            method wrapWithListType

                                                            protected wrapWithListType: (str: string) => string;

                                                              class TypeScriptOperationVariablesToObject

                                                              class TypeScriptOperationVariablesToObject extends OperationVariablesToObject {}

                                                                constructor

                                                                constructor(
                                                                _scalars: NormalizedScalarsMap,
                                                                _convertName: ConvertNameFn,
                                                                _avoidOptionals: any,
                                                                _immutableTypes: boolean,
                                                                _namespacedImportName?: string,
                                                                _enumNames?: string[],
                                                                _enumPrefix?: boolean,
                                                                _enumValues?: ParsedEnumValuesMap,
                                                                _applyCoercion?: boolean,
                                                                _directiveArgumentAndInputFieldMappings?: ParsedDirectiveArgumentAndInputFieldMappings,
                                                                _maybeType?: string
                                                                );

                                                                  method formatFieldString

                                                                  protected formatFieldString: (
                                                                  fieldName: string,
                                                                  isNonNullType: boolean,
                                                                  hasDefaultValue: boolean
                                                                  ) => string;

                                                                    method formatTypeString

                                                                    protected formatTypeString: (
                                                                    fieldType: string,
                                                                    isNonNullType: boolean,
                                                                    hasDefaultValue: boolean
                                                                    ) => string;

                                                                      method getAvoidOption

                                                                      protected getAvoidOption: (
                                                                      isNonNullType: boolean,
                                                                      hasDefaultValue: boolean
                                                                      ) => boolean;

                                                                        method getPunctuation

                                                                        protected getPunctuation: () => string;

                                                                          method wrapAstTypeWithModifiers

                                                                          wrapAstTypeWithModifiers: (
                                                                          baseType: string,
                                                                          typeNode: TypeNode,
                                                                          applyCoercion?: boolean
                                                                          ) => string;

                                                                            method wrapMaybe

                                                                            protected wrapMaybe: (type?: string) => string;

                                                                              Interfaces

                                                                              interface TypeScriptPluginConfig

                                                                              interface TypeScriptPluginConfig extends RawTypesConfig {}
                                                                              • This plugin generates the base TypeScript types, based on your GraphQL schema.

                                                                                The types generated by this plugin are simple, and refers to the exact structure of your schema, and it's used as the base types for other plugins (such as typescript-operations / typescript-resolvers)

                                                                              property allowEnumStringTypes

                                                                              allowEnumStringTypes?: boolean;
                                                                              • Allow using enum string values directly.

                                                                                config:
                                                                                allowEnumStringTypes: true

                                                                              property avoidOptionals

                                                                              avoidOptionals?: boolean | AvoidOptionalsConfig;
                                                                              • This will cause the generator to avoid using TypeScript optionals (?) on types, so the following definition: type A { myField: String } will output myField: Maybe<string> instead of myField?: Maybe<string>. false

                                                                                ## Override all definition types

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                avoidOptionals: true

                                                                                ## Override only specific definition types

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                avoidOptionals:
                                                                                field: true
                                                                                inputValue: true
                                                                                object: true
                                                                                defaultValue: true

                                                                              property constEnums

                                                                              constEnums?: boolean;
                                                                              • Will prefix every generated enum with const, you can read more about const enums here: https://www.typescriptlang.org/docs/handbook/enums.html. false

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                constEnums: true

                                                                              property disableDescriptions

                                                                              disableDescriptions?: boolean;
                                                                              • Set the value to true in order to disable all description generation. false

                                                                                ## Disable description generation

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                disableDescriptions: true

                                                                              property entireFieldWrapperValue

                                                                              entireFieldWrapperValue?: string;
                                                                              • entireFieldWrapperValue string Allow to override the type value of EntireFieldWrapper. This wrapper applies outside of Array and Maybe unlike fieldWrapperValue, that will wrap the inner type. T | Promise | (() => T | Promise)

                                                                                Example 1

                                                                                Only allow values

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                entireFieldWrapperValue: T

                                                                              property enumsAsConst

                                                                              enumsAsConst?: boolean;
                                                                              • Generates enum as TypeScript const assertions instead of enum. This can even be used to enable enum-like patterns in plain JavaScript code if you choose not to use TypeScript’s enum construct. false

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                enumsAsConst: true

                                                                              property enumsAsTypes

                                                                              enumsAsTypes?: boolean;
                                                                              • Generates enum as TypeScript type instead of enum. Useful if you wish to generate .d.ts declaration file instead of .ts false

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                enumsAsTypes: true

                                                                              property futureProofEnums

                                                                              futureProofEnums?: boolean;
                                                                              • This option controls whether or not a catch-all entry is added to enum type definitions for values that may be added in the future. This is useful if you are using relay. false

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                enumsAsTypes: true
                                                                                futureProofEnums: true

                                                                              property futureProofUnions

                                                                              futureProofUnions?: boolean;
                                                                              • This option controls whether or not a catch-all entry is added to union type definitions for values that may be added in the future. This is useful if you are using relay. false

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                futureProofUnions: true

                                                                              property immutableTypes

                                                                              immutableTypes?: boolean;
                                                                              • Generates immutable types by adding readonly to properties and uses ReadonlyArray. false

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                immutableTypes: true

                                                                              property inputMaybeValue

                                                                              inputMaybeValue?: string;
                                                                              • Allow to override the type value of Maybe for input types and arguments. This is useful in case you want to differentiate between the wrapper of input and output types. By default, this type just refers to Maybe type, but you can override it's definition.

                                                                                Maybe

                                                                                ## Allow undefined

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                inputMaybeValue: T | null | undefined

                                                                                ## Allow null in resolvers:

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                - typescript-resolvers
                                                                                config:
                                                                                inputMaybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'

                                                                              property maybeValue

                                                                              maybeValue?: string;
                                                                              • Allow to override the type value of Maybe. T | null

                                                                                ## Allow undefined

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                maybeValue: T | null | undefined

                                                                                ## Allow null in resolvers:

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                - typescript-resolvers
                                                                                config:
                                                                                maybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'

                                                                              property noExport

                                                                              noExport?: boolean;
                                                                              • Set to true in order to generate output without export modifier. This is useful if you are generating .d.ts file and want it to be globally available. false

                                                                                ## Disable all export from a file

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                noExport: true

                                                                              property numericEnums

                                                                              numericEnums?: boolean;
                                                                              • Controls whether to preserve typescript enum values as numbers false

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                numericEnums: true

                                                                              property onlyEnums

                                                                              onlyEnums?: boolean;
                                                                              • This will cause the generator to emit types for enums only. false

                                                                                Override all definition types

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                onlyEnums: true

                                                                              property onlyOperationTypes

                                                                              onlyOperationTypes?: boolean;
                                                                              • This will cause the generator to emit types for operations only (basically only enums and scalars). Interacts well with preResolveTypes: true false

                                                                                Override all definition types

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                onlyOperationTypes: true

                                                                              property useImplementingTypes

                                                                              useImplementingTypes?: boolean;
                                                                              • When a GraphQL interface is used for a field, this flag will use the implementing types, instead of the interface itself. false

                                                                                ## Override all definition types

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                useImplementingTypes: true

                                                                              property wrapEntireFieldDefinitions

                                                                              wrapEntireFieldDefinitions?: boolean;
                                                                              • wrapEntireFieldDefinitions boolean Set to true in order to wrap field definitions with EntireFieldWrapper. This is useful to allow return types such as Promises and functions for fields. Differs from wrapFieldDefinitions in that this wraps the entire field definition if i.e. the field is an Array, while wrapFieldDefinitions will wrap every single value inside the array. false

                                                                                Example 1

                                                                                Enable wrapping entire fields

                                                                                generates:
                                                                                path/to/file.ts:
                                                                                plugins:
                                                                                - typescript
                                                                                config:
                                                                                wrapEntireFieldDefinitions: false

                                                                              interface TypeScriptPluginParsedConfig

                                                                              interface TypeScriptPluginParsedConfig extends ParsedTypesConfig {}

                                                                                property avoidOptionals

                                                                                avoidOptionals: AvoidOptionalsConfig;

                                                                                  property constEnums

                                                                                  constEnums: boolean;

                                                                                    property enumsAsConst

                                                                                    enumsAsConst: boolean;

                                                                                      property enumsAsTypes

                                                                                      enumsAsTypes: boolean;

                                                                                        property futureProofEnums

                                                                                        futureProofEnums: boolean;

                                                                                          property futureProofUnions

                                                                                          futureProofUnions: boolean;

                                                                                            property immutableTypes

                                                                                            immutableTypes: boolean;

                                                                                              property inputMaybeValue

                                                                                              inputMaybeValue: string;

                                                                                                property maybeValue

                                                                                                maybeValue: string;

                                                                                                  property noExport

                                                                                                  noExport: boolean;

                                                                                                    property numericEnums

                                                                                                    numericEnums: boolean;

                                                                                                      property onlyEnums

                                                                                                      onlyEnums: boolean;

                                                                                                        property onlyOperationTypes

                                                                                                        onlyOperationTypes: boolean;

                                                                                                          property useImplementingTypes

                                                                                                          useImplementingTypes: boolean;

                                                                                                            Package Files (5)

                                                                                                            Dependencies (5)

                                                                                                            Dev Dependencies (0)

                                                                                                            No dev dependencies.

                                                                                                            Peer Dependencies (1)

                                                                                                            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/@graphql-codegen/typescript.

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