GraphiQL
/'graf@k(@)l/ An graphical interactive in-browser GraphQL IDE. Try the live demo.
Getting started
Using a node.js server? Just use express-graphql!
It can automatically present GraphiQL. Using another GraphQL service? GraphiQL is pretty easy to set up.
npm install --save graphiql
GraphiQL provides a React component responsible for rendering the UI, which should be provided with a function for fetching from GraphQL, we recommend using the fetch standard API.
import ReactDOM from 'react-dom';
import GraphiQL from 'graphiql';
import fetch from 'isomorphic-fetch';
function graphQLFetcher(graphQLParams) {
return fetch(window.location.origin + '/graphql', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(graphQLParams),
}).then(response => response.json());
}
ReactDOM.render(<GraphiQL fetcher={graphQLFetcher} />, document.body);
Build for the web with webpack or browserify, or use the pre-bundled graphiql.js file. See the example in the git repository to see how to use the pre-bundled file.
Don't forget to include the CSS file on the page! If you're using npm, you can
find it in node_modules/graphiql/graphiql.css, or you can download it from the
releases page.
For an example of setting up a GraphiQL, check out the example in this repository which also includes a few useful features highlighting GraphiQL's API.
Features
- Syntax highlighting
- Intelligent type ahead of fields, arguments, types, and more.
- Real-time error highlighting and reporting.
- Automatic query completion.
- Run and inspect query results.
Usage
GraphiQL exports a single React component which is intended to encompass the entire browser viewport. This React component renders the GraphiQL editor.
">import GraphiQL from 'graphiql';<GraphiQL />