TypeScript TypeGraphQL
Generate TypeScript types for use with TypeGraphQL. This plugin is similar to the basic TypeScript plugin. However, this package generates types that can be used by TypeGraphQL to generate a GraphQL schema. This is especially useful if you are building a service that is a gateway to multiple downstream GraphQL services, or otherwise combining GraphQL schemas. In this case, this plugin can be used to re-expose types defined in downstream GraphQL services without redefining them as TypeGraphQL objects. This plugin should be compatible with other client-side plugins, such as typescript-operations.
- Version
- 3.0.1
- Weekly downloads
- 7k
- License
- MIT
- Updated
- May 26, 2025
Installation
npm i -D @graphql-codegen/typescript-type-graphql
yarn add -D @graphql-codegen/typescript-type-graphql
pnpm add -D @graphql-codegen/typescript-type-graphql
bun add -D @graphql-codegen/typescript-type-graphql
Config API Reference
decoratorName
type: object
allow overriding of TypeGraphQL decorator types Default value: ”{ type: ‘ObjectType’, interface: ‘InterfaceType’, arguments: ‘ArgsType’, field: ‘Field’, input: ‘InputType’ }“
decorateTypes
type: string[]
Specifies the objects that will have TypeGraphQL decorators prepended to them, by name. Non-matching types will still be output, but without decorators. If not set, all types will be decorated.
avoidOptionals
type: object
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>.
Default value: “false”
constEnums
type: boolean
Will prefix every generated enum with const, you can read more about const enums here: https://www.typescriptlang.org/docs/handbook/enums.html.
Default value: “false”
enumsAsTypes
type: boolean
Generates enum as TypeScript string union type instead of an enum. Useful if you wish to generate .d.ts declaration file instead of .ts, or if you want to avoid using TypeScript enums due to bundle size concerns
Default value: “false”
numericEnums
type: boolean
Controls whether to preserve typescript enum values as numbers Default value: “false”
futureProofEnums
type: 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.
Default value: “false”
futureProofUnions
type: 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.
Default value: “false”
enumsAsConst
type: 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.
Default value: “false”
onlyEnums
type: boolean
This will cause the generator to emit types for enums only. Default value: “false”
onlyOperationTypes
type: boolean
This will cause the generator to emit types for operations only (basically only enums and scalars).
Interacts well with preResolveTypes: true
Default value: “false”
immutableTypes
type: boolean
Generates immutable types by adding readonly to properties and uses ReadonlyArray.
Default value: “false”
maybeValue
type: string
Allow to override the type value of Maybe.
Default value: “T | null”
inputMaybeValue
type: 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 its definition.
Default value: “Maybe
noExport
type: 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.
Default value: “false”
disableDescriptions
type: boolean
Set the value to true in order to disable all description generation.
Default value: “false”
useImplementingTypes
type: boolean
When a GraphQL interface is used for a field, this flag will use the implementing types, instead of the interface itself. Default value: “false”
wrapEntireFieldDefinitions
type: 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.
Default value: “false”
entireFieldWrapperValue
type: 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.
Default value: “T | Promise
allowEnumStringTypes
type: boolean
Allow using enum string values directly.
addUnderscoreToArgsType
type: boolean
Adds _ to generated Args types in order to avoid duplicate identifiers.
enumValues
type: object
Overrides the default value of enum values declared in your GraphQL schema.
You can also map the entire enum to an external type by providing a string that of module#type.
declarationKind
type: object
Overrides the default output for various GraphQL elements.
enumPrefix
type: boolean
Allow you to disable prefixing for generated enums, works in combination with typesPrefix.
Default value: “true”
fieldWrapperValue
type: string
Allow you to add wrapper for field type, use T as the generic value. Make sure to set wrapFieldDefinitions to true in order to make this flag work.
Default value: “T”
wrapFieldDefinitions
type: boolean
Set to true in order to wrap field definitions with FieldWrapper.
This is useful to allow return types such as Promises and functions.
Default value: “false”
ignoreEnumValuesFromSchema
type: boolean
This will cause the generator to ignore enum values defined in GraphQLSchema Default value: “false”
directiveArgumentAndInputFieldMappings
type: object
Replaces a GraphQL scalar with a custom type based on the applied directive on an argument or input field.
You can use both module#type and module#namespace#type syntax.
Will NOT work with introspected schemas since directives are not exported.
Only works with directives on ARGUMENT_DEFINITION or INPUT_FIELD_DEFINITION.
WARNING: Using this option does only change the type definitions.
For actually ensuring that a type is correct at runtime you will have to use schema transforms (e.g. with @graphql-tools/utils mapSchema) that apply those rules! Otherwise, you might end up with a runtime type mismatch which could cause unnoticed bugs or runtime errors.
Please use this configuration option with care!
directiveArgumentAndInputFieldMappingTypeSuffix
type: string
Adds a suffix to the imported names to prevent name clashes.
strictScalars
type: boolean
Makes scalars strict.
If scalars are found in the schema that are not defined in scalars
an error will be thrown during codegen.
Default value: “false”
defaultScalarType
type: string
Allows you to override the type that unknown scalars will have. Default value: “any”
scalars
type: object
Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
namingConvention
type: object
Allow you to override the naming convention of the output.
You can either override all namings, or specify an object with specific custom naming convention per output.
The format of the converter must be a valid module#method.
Allowed values for specific output are: typeNames, enumValues.
You can also use “keep” to keep all GraphQL names as-is.
Additionally, you can set transformUnderscore to true if you want to override the default behavior,
which is to preserve underscores.
Available case functions in change-case-all are camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase, lowerCase, localeLowerCase, lowerCaseFirst, spongeCase, titleCase, upperCase, localeUpperCase and upperCaseFirst
See more
Default value: “change-case-all#pascalCase”
typesPrefix
type: string
Prefixes all the generated types. Default value: ""
typesSuffix
type: string
Suffixes all the generated types. Default value: ""
skipTypename
type: boolean
Does not add __typename to the generated types, unless it was specified in the selection set.
Default value: “false”
nonOptionalTypename
type: boolean
Automatically adds __typename field to the generated types, even when they are not specified
in the selection set, and makes it non-optional
Default value: “false”
useTypeImports
type: boolean
Will use import type {} rather than import {} when importing only types. This gives
compatibility with TypeScript’s “importsNotUsedAsValues”: “error” option
Default value: “false”
dedupeFragments
type: boolean
Removes fragment duplicates for reducing data transfer. It is done by removing sub-fragments imports from fragment definition Instead - all of them are imported to the Operation node. Default value: “false”
inlineFragmentTypes
type: string
Whether fragment types should be inlined into other operations. “inline” is the default behavior and will perform deep inlining fragment types within operation type definitions. “combine” is the previous behavior that uses fragment type references without inlining the types (and might cause issues with deeply nested fragment that uses list types). Default value: “inline”
emitLegacyCommonJSImports
type: boolean
Emit legacy common js imports.
Default it will be true this way it ensure that generated code works with non-compliant bundlers.
Default value: “true”
This plugin is similar to the basic TypeScript plugin. However, this package generates types that can be used by TypeGraphQL to generate a GraphQL schema. This is especially useful if you are building a service that is a gateway to multiple downstream GraphQL services, or otherwise combining GraphQL schemas. In this case, this plugin can be used to re-expose types defined in downstream GraphQL services without redefining them as TypeGraphQL objects. This plugin should be compatible with other client-side plugins, such as typescript-operations.
Some differences with the types generated by the basic TypeScript plugin:
- classes are generated instead of interfaces
- TypeGraphQL decorators like
@ObjectTypeand@Fieldwill be added