Relay Operation Optimizer

Package nameWeekly DownloadsVersionLicenseUpdated
@graphql-codegen/relay-operation-optimizer (opens in a new tab)DownloadsVersionLicenseApr 5th, 2022


npm i -D @graphql-codegen/relay-operation-optimizer

Built and maintained by n1ru4l (opens in a new tab).

A GraphQL Codegen feature for bringing the benefits of Relay Compiler to any GraphQL Client using Relay Operation Optimizer (opens in a new tab).

You can test how relay-compiler affects your queries over on the Relay Compiler REPL (opens in a new tab).

List of Features


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

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!