Socket
Book a DemoInstallSign in
Socket

@graphiql/plugin-code-exporter

Package Overview
Dependencies
Maintainers
5
Versions
267
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphiql/plugin-code-exporter

This package provides a plugin that integrates the [GraphiQL Code Exporter](https://github.com/OneGraph/graphiql-code-exporter) into the GraphiQL UI.

5.1.0-canary-be24c1cc.0
Source
npmnpm
Version published
Weekly downloads
1.2K
-49.34%
Maintainers
5
Weekly downloads
 
Created
Source

GraphiQL Code Exporter Plugin

This package provides a plugin that integrates the GraphiQL Code Exporter into the GraphiQL UI.

Installation

Install the plugin using your preferred package manager:

npm install @graphiql/plugin-code-exporter

Make sure to also install the required peer dependencies:

npm install react react-dom graphql

Usage

Refer to the GraphiQL Code Exporter README for full details on available props and how to create snippets.

Example integration:

import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
import { codeExporterPlugin } from '@graphiql/plugin-code-exporter';
import 'graphiql/style.css';
import '@graphiql/plugin-code-exporter/style.css';

const fetcher = createGraphiQLFetcher({
  url: 'https://countries.trevorblades.com',
});
function getQuery(arg, spaceCount = 2) {
  const spaces = ' '.repeat(spaceCount);
  const { query } = arg.operationDataList[0];
  return spaces + query.replaceAll('\n', '\n' + spaces);
}

const codeExporter = codeExporterPlugin({
  /**
   * Example code for snippets. See https://github.com/OneGraph/graphiql-code-exporter#snippets for details.
   */
  snippets: [
    {
      name: 'Example One',
      language: 'JavaScript',
      codeMirrorMode: 'jsx',
      options: [],
      generate: arg =>
        ['export const query = graphql`', getQuery(arg), '`'].join('\n'),
    },
    {
      name: 'Example Two',
      language: 'JavaScript',
      codeMirrorMode: 'jsx',
      options: [],
      generate: arg =>
        [
          "import { graphql } from 'graphql'",
          '',
          'export const query = graphql`',
          getQuery(arg),
          '`',
        ].join('\n'),
    },
  ],
});
function App() {
  return <GraphiQL fetcher={fetcher} plugins={[codeExporter]} />;
}

CDN bundles

You can also use this plugin via an ESM-based CDN like esm.sh.

See the CDN example for a working demo.

Keywords

react

FAQs

Package last updated on 17 Jul 2025

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.