This plugin generates Flow types based on your GraphQLSchema
and your GraphQL operations and fragments.
It generates types for your GraphQL documents: Query, Mutation, Subscription and Fragment.
This plugin requires you to use @graphql-codegen/flow
as well, because it depends on it's types.
:::shell Using yarn
$ yarn add -D @graphql-codegen/flow-operations
:::
type: boolean
default: true
Generates Flow types as Exact types.
generates:
path/to/file.ts:
plugins:
- flow
config:
useFlowExactObjects: false
type: boolean
default: false
Generates read-only Flow types
generates:
path/to/file.ts:
plugins:
- flow
config:
useFlowReadOnlyTypes: true
type: boolean
default: false
Flatten fragment spread and inline fragments into a simple selection set before generating.
generates:
path/to/file.ts:
plugins:
- typescript
- typescript-operations
config:
flattenGeneratedTypes: true
type: boolean
default: false
Avoid using Pick
and resolve the actual primitive type of all selection set.
plugins
config:
preResolveTypes: true
type: boolean
default: false
Avoid adding __typename
for root types. This is ignored when a selection explictly specifies __typename
.
plugins
config:
skipTypeNameForRoot: true
type: boolean
default: false
Puts all generated code under global
namespace. Useful for Stencil integration.
plugins
config:
globalNamespace: true
type: string
default: ``
Adds a suffix to generated operation result type names
type: boolean
default: false
Set this configuration to true
if you wish to make sure to remove duplicate operation name suffix.
type: boolean
default: false
Set this configuration to true
if you wish to disable auto add suffix of operation name, like Query
, Mutation
, Subscription
, Fragment
.
type: boolean
default: false
If set to true, it will export the sub-types created in order to make it easier to access fields declared under fragment spread.
type: boolean
Adds _
to generated Args
types in order to avoid duplicate identifiers.
config:
addUnderscoreToArgsType: true
type: EnumValuesMap
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
.
config:
enumValues:
MyEnum:
A: 'foo'
config:
enumValues:
MyEnum: ./my-file#MyCustomEnum
config:
enumValues: ./my-file
type: DeclarationKindConfig | string (values: abstract class, class, interface, type)
Overrides the default output for various GraphQL elements.
config:
declarationKind: 'interface'
config:
declarationKind:
type: 'interface'
input: 'interface'
type: boolean
default: true
Allow you to disable prefixing for generated enums, works in combination with typesPrefix
.
config:
typesPrefix: I
enumPrefix: false
type: string
default: T
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.
generates:
path/to/file.ts:
plugins:
- typescript
config:
wrapFieldDefinitions: true
fieldWrapperValue: T | Promise<T>
type: boolean
default: false
Set the to true
in order to wrap field definitions with FieldWrapper
.
This is useful to allow return types such as Promises and functions.
generates:
path/to/file.ts:
plugins:
- typescript
config:
wrapFieldDefinitions: true
type: boolean
default: false
This will cause the generator to emit types for operations only (basically only enums and scalars)
generates:
path/to/file.ts:
plugins:
- typescript
config:
onlyOperationTypes: true
type: ScalarsMap
Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
config:
scalars:
DateTime: Date
JSON: "{ [key: string]: any }"
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.
config:
namingConvention: lower-case#lowerCase
config:
namingConvention:
typeNames: pascal-case#pascalCase
enumValues: upper-case#upperCase
config:
namingConvention: keep
config:
namingConvention:
typeNames: pascal-case#pascalCase
transformUnderscore: true
type: string
default: ``
Prefixes all the generated types.
config:
typesPrefix: I
type: boolean
default: false
Does not add __typename to the generated types, unless it was specified in the selection set.
config:
skipTypename: true
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
config:
nonOptionalTypename: true