New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@graphox/babel-plugin

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphox/babel-plugin

Babel plugin for Graphox codesplitting

latest
Source
npmnpm
Version
0.5.2
Version published
Maintainers
1
Created
Source

@graphox/babel-plugin

Overview

Ensures GraphQL AST files are properly codesplit, preventing them from all ending up in the initial chunk.

Why Use This Plugin?

Codegen already generates AST files at compile time. The problem is bundler behavior:

Without plugin:

Initial chunk: ALL generated AST files (~50KB+)
Lazy chunks: empty or minimal

With plugin:

Initial chunk: ~1KB (just imports)
Lazy chunks: each operation in its chunk

Installation

pnpm add --save-dev @graphox/babel-plugin

Quick Start

1. Configure graphox

# graphox.yaml
output_dir: "__generated__"
projects:
  - schema: "schema.graphql"
    include: "src/**/*.{ts,tsx}"

2. Run Codegen

pnpm graphox codegen

3. Configure Babel

// babel.config.js
const path = require('path');

module.exports = {
  presets: ['@babel/preset-typescript'],
  plugins: [
    ['@graphox/babel-plugin', {
      manifestPath: path.resolve(__dirname, '__generated__/manifest.json'),
      outputDir: path.resolve(__dirname, '__generated__'),
      graphqlImportPaths: ['@/graphql']
    }]
  ]
};

Metro (React Native)

Metro uses Babel transformers under the hood. Configure in metro.config.js:

// metro.config.js
module.exports = {
  transformer: {
    babelTransformerPath: require.resolve('@graphox/babel-plugin'),
  },
};

For full compatibility, also configure in babel.config.js.

Codesplitting Impact

ConfigurationInitial ChunkPer-Lazy-Chunk
Without plugin~50KB+ (all AST)~1KB
With plugin~1KB~1KB

Configuration Options

OptionTypeRequiredDescription
manifestPathstringYes*Path to manifest.json generated by codegen
manifestDataobject[]Yes*Inline manifest data (alternative to manifestPath)
outputDirstringYesDirectory containing generated files
graphqlImportPathsstring[]NoExplicit import paths to treat as GraphQL entrypoints
emitExtensionsstringNoFile extension for generated imports: "none" (default), "ts", "js", "dts"

*Either manifestPath or manifestData is required.

emitExtensions

Controls the file extension appended to generated import paths. Should match the emit_extensions setting in your graphox.yaml:

ValueResult
"none" (default)import { X } from "./file.codegen"
"ts"import { X } from "./file.codegen.ts"
"js"import { X } from "./file.codegen.js"
"dts"import { X } from "./file.codegen.d.ts"

Fragment Documents

When generate_ast_for_fragments: true is enabled in your config, fragment documents are also included in the manifest and will be properly rewritten by the plugin.

When to Use

Build ToolRecommended Plugin
React Native (Metro)Babel
WebpackBabel
Create React AppBabel
StorybookBabel
rsbuildUse SWC plugin
Turbopack/Next.jsUse SWC plugin

See Also

  • SWC Plugin
  • graphox CLI
  • Configuration Guide

FAQs

Package last updated on 26 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts