Socket
Socket
Sign inDemoInstall

@graphiql/plugin-code-exporter

Package Overview
Dependencies
113
Maintainers
5
Versions
58
Alerts
File Explorer

Advanced tools

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.


Version published
Weekly downloads
1.1K
decreased by-28.45%
Maintainers
5
Install size
538 kB
Created
Weekly downloads
 

Changelog

Source

GraphQL Language Service Interface 2.0.0 - 11 Sep, 2018

Chores

  • BREAKING: upgrade internal dependencies - gls-parser, gls-types, and gls-utils to 2.0.0 - @lostplan
  • BREAKING: remove incompatible dependencies on graphql 0.11 and below - @lostplan

Readme

Source

GraphiQL Code Exporter Plugin

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

Install

Use your favorite package manager to install the package:

npm i -S @graphiql/plugin-code-exporter

The following packages are peer dependencies, so make sure you have them installed as well:

npm i -S react react-dom graphql

Usage

See GraphiQL Code Exporter README for all details on available props and how to create snippets.

import { codeExporterPlugin } from '@graphiql/plugin-code-exporter';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
import { GraphiQL } from 'graphiql';
import { useState } from 'react';

import 'graphiql/graphiql.css';
import '@graphiql/plugin-code-exporter/dist/style.css';

const fetcher = createGraphiQLFetcher({
  url: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
});

/*
Example code for snippets. See https://github.com/OneGraph/graphiql-code-exporter#snippets for details
*/

const removeQueryName = query =>
  query.replace(
    /^[^{(]+([{(])/,
    (_match, openingCurlyBracketsOrParenthesis) =>
      `query ${openingCurlyBracketsOrParenthesis}`,
  );

const getQuery = (arg, spaceCount) => {
  const { operationDataList } = arg;
  const { query } = operationDataList[0];
  const anonymousQuery = removeQueryName(query);
  return (
    ' '.repeat(spaceCount) +
    anonymousQuery.replaceAll('\n', '\n' + ' '.repeat(spaceCount))
  );
};

const exampleSnippetOne = {
  name: 'Example One',
  language: 'JavaScript',
  codeMirrorMode: 'jsx',
  options: [],
  generate: arg => `export const query = graphql\`
${getQuery(arg, 2)}
\`
`,
};

const exampleSnippetTwo = {
  name: 'Example Two',
  language: 'JavaScript',
  codeMirrorMode: 'jsx',
  options: [],
  generate: arg => `import { graphql } from 'graphql'

export const query = graphql\`
${getQuery(arg, 2)}
\`
`,
};

const snippets = [exampleSnippetOne, exampleSnippetTwo];

const exporter = codeExporterPlugin({
  snippets,
  codeMirrorTheme: 'graphiql',
});

function GraphiQLWithExplorer() {
  return (
    <GraphiQL fetcher={fetcher} defaultQuery={query} plugins={[exporter]} />
  );
}

CDN bundles

You can also use this plugin with unpkg, jsdelivr, and other CDNs.

See the example HTML file for this plugin

Keywords

FAQs

Last updated on 05 Apr 2024

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc