website/src/pages/plugins/flow/flow-resolvers.mdx
import { Callout } from '@theguild/components' import { PluginApiDocs, PluginHeader } from '@/components/plugin' import { pluginGetStaticProps } from '@/lib/plugin-get-static-props' export const getStaticProps = pluginGetStaticProps(__filename)
<PluginHeader /> <Callout> **Quick Start with `flow-resolvers`**You can find a blog post we wrote about using and customizing this plugin here, it refers to typescript-resolvers but everything there is relevant to flow-resolvers as well.
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.
With the following schema:
type Query {
favoriteColor: Color!
}
enum Color {
RED
BLUE
}
schema: schema.graphql
generates:
./resolvers-types.js:
config:
enumValues:
Color: ./enums#ColorsCode
plugins:
- flow
- flow-resolvers
export enum ColorsCode {
MY_RED = '#FF0000',
MY_BLUE = '#0000FF'
}
import type { Resolvers } from './resolvers-types'
import { ColorsCode } from './enums'
const resolvers: Resolvers = {
Color: {
RED: ColorsCode.MY_RED,
BLUE: ColorsCode.MY_BLUE
},
Query: {
favoriteColor: () => ColorsCode.MY_RED // Now you cn return this, and it will be mapped to your actual GraphQL enum
}
}
You can also define the same with explicit enum values:
schema: schema.graphql
generates:
./resolvers-types.js:
config:
enumValues:
Color:
RED: '#FF0000'
BLUE: '#0000FF'
plugins:
- flow
- flow-resolvers
Or, with mappers:
schema: schema.graphql
generates:
./resolvers-types.js:
config:
mappers:
Color: ./enums#ColorsCode
plugins:
- flow
- flow-resolvers