Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

graphiql

graphql1.9mMIT5.0.3TypeScript support: included

An graphical interactive in-browser GraphQL IDE.

readme

GraphiQL

Security Notice: All versions of graphiql < 1.4.3 are vulnerable to an XSS attack in cases where the GraphQL server to which the GraphiQL web app connects is not trusted. Learn more in our security advisory.

NPM jsDelivr hits (npm) npm downloads Snyk Vulnerabilities for npm package npm bundle size (version) npm bundle size (version) License

/ˈɡrafək(ə)l/ A graphical interactive in-browser GraphQL IDE. Try the live demo.

Features

  • Full language support of the latest GraphQL Specification:
  • Syntax highlighting
  • Intelligent type ahead of fields, arguments, types, and more
  • Real-time error highlighting and reporting for queries and variables
  • Automatic query and variables completion
  • Automatic leaf node insertion for non-scalar fields
  • Documentation explorer with search and markdown support
  • Persisted state using localStorage
  • Simple API for adding custom plugins

Live Demos

Examples

Getting started

If you're looking to upgrade from `graphiql@1.xtographiql@2`, check out the migration guide!

CDN usage

Use the modern, ESM-based CDN approach. See the ESM-based example for setup details.

UMD (deprecated)

[!WARNING]

The UMD CDN build is deprecated and will be removed in a future major release of GraphiQL. Please migrate to the ESM-based example.

Usage

Using as package

The graphiql package can be installed using your favorite package manager. You also need to have react,react-dom and graphql installed which are peer dependencies of graphiql.

npm install graphiql react react-dom graphql

The package exports a bunch of React components:

  • The GraphiQLProvider components renders multiple context providers that encapsulate all state management
  • The GraphiQLInterface component renders the UI that makes up GraphiQL
  • The GraphiQL component is a combination of both the above components

There is a single prop that is required for the GraphiQL component called fetcher. A fetcher is a function that performs a request to a GraphQL API. It may return a Promise for queries or mutations, but also an Observable or an AsyncIterable in order to handle subscriptions or multipart responses.

An easy way to get create such a function is the createGraphiQLFetcher method exported from the @graphiql/toolkit package. If you want to implement your own fetcher function, you can use the Fetcher type from @graphiql/toolkit to make sure the signature matches what GraphiQL expects.

The following is everything you need to render GraphiQL in your React application:

import { createGraphiQLFetcher } from '@graphiql/toolkit';
import { GraphiQL } from 'graphiql';
import { createRoot } from 'react-dom/client';
import 'graphiql/style.css';

const fetcher = createGraphiQLFetcher({ url: 'https://my.backend/graphql' });

const root = createRoot(document.getElementById('root'));
root.render(<GraphiQL fetcher={fetcher} />);

Customize

GraphiQL supports customization in UI and behavior by accepting React props and children.

Props

For props documentation, see the API Docs

Children

Parts of the UI can be customized by passing children to the GraphiQL or the GraphiQLInterface component.

  • <GraphiQL.Logo>: Replace the GraphiQL logo with your own.

  • <GraphiQL.Toolbar>: Add a custom toolbar below the execution button. Pass the empty <GraphiQL.Toolbar /> if an empty toolbar is desired. Use the components provided by @graphiql/react to create toolbar buttons with proper styles.

  • <GraphiQL.Footer>: Add a custom footer shown below the response editor.

Plugins

Starting with graphiql@2 there exists a simple plugin API that allows you to build your own custom tools right into GraphiQL.

There are two built-in plugins that come with GraphiQL: The documentation explorer and the query history. Both can be toggled using icons in the sidebar on the left side of the screen. When opened, they appear next to the sidebar in a resizable portion of the screen.

To define your own plugin, all you need is a JavaScript object with three properties:

  • title: A unique title for the plugin (this will show up in a tooltip when hovering over the sidebar icon)
  • icon: A React component that renders an icon which will be included in the sidebar
  • content: A React component that renders the plugin contents which will be shown next to the sidebar when opening the plugin

You can pass a list of plugin objects to the GraphiQL component using the plugins prop. You can also control the visibility state of plugins using the visiblePlugin prop and react to changes of the plugin visibility state using the onTogglePluginVisibility prop.

Inside the component you pass to content you can interact with the GraphiQL state using the hooks provided by @graphiql/react. For example, check out how you can integrate the OneGraph Explorer in GraphiQL using the plugin API in the plugin package in this repo.

Theming

The GraphiQL interface uses CSS variables for theming, in particular for colors. Check out the root.css file for the available variables.

Overriding these variables is the only officially supported way of customizing the appearance of GraphiQL. Starting from version 2, class names are no longer be considered stable and might change between minor or patch version updates.

Editor Theme

The colors inside the editor can also be altered using CodeMirror editor themes. You can use the editorTheme prop to pass in the name of the theme. The CSS for the theme has to be loaded for the theme prop to work.

// In your document head:
<link
  rel="stylesheet"
  href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.23.0/theme/solarized.css"
/>
// When rendering GraphiQL:
<GraphiQL editorTheme="solarized light" />

You can also create your own theme in CSS. As a reference, the default graphiql theme definition can be found here.

changelog

Archived For up to date changelogs that are automatically generated by changesets, see CHANGELOG.md files in respective workspaces. For example, the graphiql changelog is located at packages/graphiql/CHANGELOG.md, and the language server changelog is located at packages/graphql-language-service-server/CHANGELOG.md

GraphiQL 0.14.2 - 11 Aug, 2019

Fixes

  • Fix SSR & use of window when introducing new extraKeys capability (#942)

GraphiQL 0.14.0 - 11 Aug, 2019

Features

  • Add defaultVariableEditorOpen prop (#744) - @acao

Fixes

  • Fix formatting of subscription errors - #636, #722 - @benjie
  • preserve ctrl-f key for macOS - #759 - @pd4d10
  • Fix earlier 'Mode graphql failed to advance stream' on Linux by eating an exotic whitespace character - #735 closed by #932 - @benjie
  • Fix: check this.editor exists before this.editor.off in QueryEditor

Codemirror GraphQL - 0.9 - 11 Aug, 2019

Chores

  • BREAKING: Update to gls-interface and gls-parser ^2.1
  • BREAKING: Deprecate support for GraphQL 0.11 and below
  • BREAKING: introduce MIT license
  • BREAKING: Support GraphQL 14

GraphQL Language Service Server 2.1.0 - 11 Aug, 2019

Features

  • Replace babylon with @babel/parser (#879) @ganemone
  • Add support for gql template tags (#883) @ganemone @Neitsch

Chores

  • BREAKING: remove incompatible dependencies on graphql 0.11 and below
  • BREAKING: add peer support for graphql 14.x
  • BREAKING: change copyright to MIT
  • update formatting for monorepo eslint/prettier rules
  • update readme, badges

GraphQL Language Service Parser 2.1.0 - 11 Aug, 2019

Fixes

  • Fix 'mode graphql failed to advance stream' error from shift-alt-space, etc - #932 - @benjie

GraphQL Language Service Interface 2.1.0 - 11 Aug, 2019

Features

  • add __typename field suggestion against object type - (#903) @yoshiakis
  • Update sortText logic, so that field sort is schema driven rather than alphabetically sorted - (#884) @ganemone

Chores

  • BREAKING: add peer support for graphql 14.x
  • MINOR BREAKING: Use MIT license
  • add test case for language service hover - @divyenduz @AGS-

GraphQL Language Service 2.1.0

  • BREAKING: add peer support for graphql 14.x
  • BREAKING: remove incompatible dependencies on graphql 0.11 and below (b/c of gls-utils 2.x)

GraphQL Language Service Utils 2.1.0 - 11 Aug, 2019

Chores

  • BREAKING: change copyright to MIT
  • update formatting for monorepo eslint/prettier rules
  • update readme, badges

GraphQL Language Service Types 1.3.0 - 11 Aug, 2019

Chores

  • BREAKING: change copyright to MIT
  • BREAKING: add peer support for graphql 14.x
  • update formatting for monorepo eslint/prettier rules
  • update readme, badges

GraphiQL 0.13.2 - 21 June, 2019

Features

  • Hint/popup/etc DOM nodes use container rather than creating children of<body> - #791 - @codestryke
  • Add readOnly prop and pass to QueryEditor and VariableEditor - #718 - @TheSharpieOne
  • Add operationName to introspection query - #664 - @jbblanchet
  • Image Preview Functionality - #789 - @dunnbobcat @asiandrummer

Fixes

  • Destroy image hover tooltip when it isn't needed - #874 - @acao
  • Copy non-formatted query to avoid stripping out comments - #832 - @jaebradley
  • Normalizes no-break spaces - #781 - @zouxuoz
  • Prevents crashing on Shift-Alt-Space - #781 - @zouxuoz
  • Fix UI state change after favorite a query - #747 - @benjie

Chores

  • BREAKING: Upgrade to codemirror-graphql 0.8.3 - #773 - @jonaskello
  • BREAKING: Change copyright to GraphQL Contributors, License to MIT
  • Netlify deployments per PR - @orta
  • Add unit test coverage
  • Switch to Jest

Codemirror Graphql Mode 0.8.4 - 11 Aug, 2018

You will now be importing async methods from gls-interface 2.0.0, thus your bundler will require regenerator runtime

Chores

  • BREAKING - Use GLS interface/parser 2.1.0 for graphql 14
  • BREAKING - This introduces async/await

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

GraphQL Language Service Utils 2.0.0 - 11 Sep, 2018

Chores

GraphQL Language Service Utils 1.2.2 - 11 Sep, 2018

Chores

  • add graphql-js 0.13 to peer deps of types package (graphql/graphql-language-service#241)

GraphQL Language Service Server 2.0.0 - 11 Sep, 2019

Chores

  • add graphql-js 0.13 to peer dependencies (graphql/graphql-language-service#241)
  • BREAKING: upgrade internal dependencies - gls-interface, gls-server and gls-utils to 2.0.0 @lostplan

GraphQL Language Service 2.0.0 - 11 Sep, 2018

Chores

  • BREAKING: upgrade internal dependencies - gls-interface, gls-server and gls-utils to 2.0.0 @Sol