TypeScript 1.0 Compatibility

If you are migrating from <1.0, we created a new plugin called typescript-compatibility that generates backward compatibility for the typescript-operations and typescript-react-apollo plugins.

It generates types that are pointing to the new form of types. It supports most of the use-cases.

Installation

Using yarn
$ yarn add -D @graphql-codegen/typescript-compatibility

API Reference

noNamespaces

type: boolean default: false

Does not generate TypeScript namespaces and uses the operation name as prefix.

Usage Examples

generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
- typescript-compatibility
config:
noNamespaces: true

strict

type: boolean default: false

Make sure to generate code that compatible with TypeScript strict mode.

Usage Examples

generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
- typescript-compatibility
config:
strict: true

preResolveTypes

type: boolean default: false

Avoid using Pick in typescript-operations and make sure to optimize this package as well.

scalars

type: ScalarsMap

Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.

Usage Examples

config:
scalars:
DateTime: Date
JSON: "{ [key: string]: any }"

namingConvention

type: NamingConvention default: pascal-case#pascalCase

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 preserves underscores.

Usage Examples

Override All Names
config:
namingConvention: lower-case#lowerCase
Upper-case enum values
config:
namingConvention:
typeNames: pascal-case#pascalCase
enumValues: upper-case#upperCase
Keep names as is
config:
namingConvention: keep
Remove Underscores
config:
namingConvention:
typeNames: pascal-case#pascalCase
transformUnderscore: true

typesPrefix

type: string default: ``

Prefixes all the generated types.

Usage Examples

config:
typesPrefix: I

skipTypename

type: boolean default: false

Does not add __typename to the generated types, unless it was specified in the selection set.

Usage Examples

config:
skipTypename: true

nonOptionalTypename

type: boolean default: false

Automatically adds __typename field to the generated types, even when they are not specified in the selection set, and makes it non-optional

Usage Examples

config:
nonOptionalTypename: true