An graphical interactive in-browser GraphQL IDE.
npm install 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.

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


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

- 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
- The latest stable version
- The current state of the main branch:
- An installable PWA with plugins (source)
- Using the minified bundles
- Using the development bundles (good
for inspecting, debugging, etc)
- Each pull request will also get its own preview deployment on Netlify, you'll
find a link in the GitHub checks
- CDN (ESM-based) - A single HTML file using JavaScript modules from http URLs and a tag
- Webpack - A starter for Webpack
- Create React App - An example
using Create React App
- Parcel - An example using
Parcel
- Migration guide to GraphiQL 2
- Migration guide to GraphiQL 4
- Migration guide to GraphiQL 5
#### ESM-based (recommended)
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.
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.
``sh`
npm install graphiql react react-dom graphql
The package exports a bunch of React components:
- The GraphiQLProvider components renders multiple context providers thatGraphiQLInterface
encapsulate all state management
- The component renders the UI that makes up GraphiQLGraphiQL
- The component is a combination of both the above components
There is a single prop that is required for the GraphiQL component calledPromise
fetcher. A fetcher is a function that performs a request to a GraphQL API. It
may return a for queries or mutations, but also an Observable or anAsyncIterable 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 implementFetcher
your own fetcher function, you can use the 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:
`jsx
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 supports customization in UI and behavior by accepting React props and
children.
For props documentation, see the
API Docs
Parts of the UI can be customized by passing children to the GraphiQL or theGraphiQLInterface component.
- : Replace the GraphiQL logo with your own.
- : Add a custom toolbar below the execution button. Pass
the empty if an empty toolbar is desired. Use the@graphiql/react
components provided by to create toolbar buttons with proper
styles.
- : Add a custom footer shown below the response editor.
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 whenicon
hovering over the sidebar icon)
- : A React component that renders an icon which will be included in thecontent
sidebar
- : 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 theplugins prop. You can also control the visibility state of plugins using thevisiblePlugin prop and react to changes of the plugin visibility state usingonTogglePluginVisibility
the prop.
Inside the component you pass to content you can interact with the GraphiQL@graphiql/react
state using the hooks provided by . For example, check out
how you can integrate the OneGraph Explorer in GraphiQL using the plugin API in
the plugin package in this repo.
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.
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.
`jsx`
// In your document head:
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.23.0/theme/solarized.css"
/>
`jsx`
// When rendering GraphiQL:
You can also create your own theme in CSS. As a reference, the default
graphiql theme definition can be found
here.
When multiple GraphiQL instances run on the same origin—such as in different apps or
environments—they can conflict by reading from and writing to the same localStorage keys. Tostorage
prevent this, you can provide a custom object that prefixes all keys with a unique
namespace, isolating each instance’s state and avoiding collisions.
`tsx
import type { FC } from 'react';
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
const fetcher = createGraphiQLFetcher({ url: 'https://my.backend/graphql' });
const NAMESPACE = 'my-namespace';
const storage: typeof localStorage = {
...localStorage,
getItem(key) {
return localStorage.getItem(${NAMESPACE}:${key});${NAMESPACE}:${key}
},
setItem(key, value) {
return localStorage.setItem(, value);${NAMESPACE}:${key}
},
removeItem(key) {
return localStorage.removeItem();
},
};
export const App: FC = () => {
return
};
``