Flow Resolvers
Flow plugin for GraphQL Code Generator. Generates Flow types for your GraphQL resolvers.
- Version
- 3.0.2
- Weekly downloads
- 3k
- License
- MIT
- Updated
- Mar 11, 2026
Installation
npm i -D @graphql-codegen/flow-resolvers
yarn add -D @graphql-codegen/flow-resolvers
pnpm add -D @graphql-codegen/flow-resolvers
bun add -D @graphql-codegen/flow-resolvers
Config API Reference
addUnderscoreToArgsType
type: boolean
Adds _ to generated Args types in order to avoid duplicate identifiers.
contextType
type: string
Use this configuration to set a custom type for your context, and it will
affect all the resolvers, without the need to override it using generics each time.
If you wish to use an external type and import it from another file, you can use add plugin
and add the required import statement, or you can use a module#type syntax.
fieldContextTypes
type: object
Use this to set a custom type for a specific field context.
It will only affect the targeted resolvers.
You can either use Field.Path#ContextTypeName or Field.Path#ExternalFileName#ContextTypeName
rootValueType
type: string
Use this configuration to set a custom type for the rootValue, and it will
affect resolvers of all root types (Query, Mutation and Subscription), without the need to override it using generics each time.
If you wish to use an external type and import it from another file, you can use add plugin
and add the required import statement, or you can use both module#type or module#namespace#type syntax.
directiveContextTypes
type: object
Use this to set a custom type for a specific field context decorated by a directive.
It will only affect the targeted resolvers.
You can either use Field.Path#ContextTypeName or Field.Path#ExternalFileName#ContextTypeName
ContextTypeName should by a generic Type that take the context or field context type as only type parameter.
mapperTypeSuffix
type: string
Adds a suffix to the imported names to prevent name clashes.
mappers
type: object
Replaces a GraphQL type usage with a custom type, allowing you to return custom object from
your resolvers.
You can use both module#type and module#namespace#type syntax.
defaultMapper
type: string
Allow you to set the default mapper when it’s not being override by mappers or generics.
You can specify a type name, or specify a string in module#type or module#namespace#type format.
The default value of mappers is the TypeScript type generated by typescript package.
avoidOptionals
type: object
This will cause the generator to avoid using optionals (?),
so all field resolvers must be implemented in order to avoid compilation errors.
Default value: “false”
showUnusedMappers
type: boolean
Warns about unused mappers. Default value: “true”
enumValues
type: object
Overrides the default value of enum values declared in your GraphQL schema, supported
in this plugin because of the need for integration with typescript package.
See documentation under typescript plugin for more information and examples.
resolverTypeWrapperSignature
type: string
Allow you to override resolverTypeWrapper definition.
Default value: “Promise
federation
type: boolean
Supports Apollo Federation Default value: “false”
customDirectives
type: object
Configures behavior for custom directives from various GraphQL libraries.
optionalResolveType
type: boolean
Sets the __resolveType field as optional field.
Default value: “false”
immutableTypes
type: boolean
Generates immutable types by adding readonly to properties and uses ReadonlyArray.
Default value: “false”
namespacedImportName
type: string
Prefixes all GraphQL related generated types with that value, as namespaces import. You can use this feature to allow separation of plugins to different files. Default value: ””“
resolverTypeSuffix
type: string
Suffix we add to each generated type resolver. Default value: “Resolvers”
allResolversTypeName
type: string
The type name to use when exporting all resolvers signature as unified type. Default value: “Resolvers”
internalResolversPrefix
type: string
Defines the prefix value used for __resolveType and __isTypeOf resolvers.
If you are using mercurius-js, please set this field to empty string for better compatibility.
Default value: ”’__‘“
resolversNonOptionalTypename
type: object
Makes __typename of resolver mappings non-optional without affecting the base types.
Default value: “false”
avoidCheckingAbstractTypesRecursively
type: boolean
If true, recursively goes through all object type’s fields, checks if they have abstract types and generates expected types correctly.
This may not work for cases where provided default mapper types are also nested e.g. defaultMapper: DeepPartial<{T}> or defaultMapper: Partial<{T}>.
Default value: “false”
addInterfaceFieldResolverTypes
type: boolean
If true, add field resolver types to Interfaces. By default, GraphQL Interfaces do not trigger any field resolvers, meaning every implementing type must implement the same resolver for the shared fields.
Some tools provide a way to change the default behaviour by making GraphQL Objects inherit missing resolvers from their Interface types. In these cases, it is fine to turn this option to true.
For example, if you are using @graphql-tools/schema#makeExecutableSchema with inheritResolversFromInterfaces: true,
you can make addInterfaceFieldResolverTypes: true as well
https://the-guild.dev/graphql/tools/docs/generate-schema#makeexecutableschema
Default value: “false”
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: “unknown”
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: ""
enumPrefix
type: boolean
Allow you to disable prefixing for generated enums, works in combination with typesPrefix.
Default value: “true”
enumSuffix
type: boolean
Allow you to disable suffixing for generated enums, works in combination with typesSuffix.
Default value: “true”
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”
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). “mask” transforms the types for use with fragment masking. Useful when masked types are needed when not using the “client” preset e.g. such as combining it with Apollo Client’s data masking feature. 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”
importExtension
type: object
Append this extension to all imports. Useful for ESM environments that require file extensions in import statements.
printFieldsOnNewLines
type: boolean
If you prefer to have each field in generated types printed on a new line, set this to true. This can be useful for improving readability of the resulting types, without resorting to running tools like Prettier on the output. Default value: “false”
includeExternalFragments
type: boolean
Whether to include external fragments in the generated code. External fragments are not defined in the same location as the operation definition. Default value: “false”
Enum Resolvers
Apollo-Server and schemas built with
graphql-tools supports creating resolvers for GraphQL enums.
This is helpful because you can have internal values that are different from the public enum values, and you can use the internal values in your resolvers.
Codegen allows you to specify either mappers or enumValues to map enums in your resolvers, and
if you are using it for enums, you’ll get a resolver signature for the enum resolvers as well.
Usage Example
With the following schema:
You can also define the same with explicit enum values:
Or, with mappers: