Back to Graphql Code Generator

relay-operation-optimizer

website/src/pages/plugins/typescript/relay-operation-optimizer.mdx

1.17.72.0 KB
Original Source

import { Callout } from '@theguild/components' import { PluginHeader } from '@/components/plugin' import { pluginGetStaticProps } from '@/lib/plugin-get-static-props' export const getStaticProps = pluginGetStaticProps(__filename)

<PluginHeader />

Built and maintained by n1ru4l.

A GraphQL Codegen feature for bringing the benefits of Relay Compiler to any GraphQL Client using Relay Operation Optimizer.

You can test how relay-compiler affects your queries over on the Relay Compiler REPL.

List of Features

Usage

Set up your project per the GraphQL Codegen Docs, and add flattenGeneratedTypes: true{:yaml} in your codegen.yml:

ts
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  overwrite: true,
  schema: 'schema.graphql',
  generates: {
    'src/generated-types.tsx': {
      documents: 'src/documents/**/*.graphql',
      config: {
        skipDocumentsValidation: true,
        flattenGeneratedTypes: true
      },
      plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo']
    }
  }
}
export default config

Please notice that you have to skip the document validation - but no worries, relay-compiler will validate your documents instead!

<Callout> [See Laurin Quast's blog post to learn how to use those directives in your operations](https://the-guild.dev/blog/graphql-codegen-relay-compiler) </Callout>