Skip to content

Instantly share code, notes, and snippets.

@dustinsmith1024
Created August 6, 2017 20:14
Show Gist options
  • Save dustinsmith1024/335c2ded7be298061103085e4e89f074 to your computer and use it in GitHub Desktop.
Save dustinsmith1024/335c2ded7be298061103085e4e89f074 to your computer and use it in GitHub Desktop.
Graphiql start
# run create-react-app
# npm install --save graphiql
# edit App.js to look like this...
# enable CORS on your GraphQl API (http://0.0.0.0:4000 below)
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import '../node_modules/graphiql/graphiql.css';
import ReactDOM from 'react-dom';
import GraphiQL from 'graphiql';
import fetch from 'isomorphic-fetch';
function graphQLFetcher(graphQLParams) {
return fetch('http://0.0.0.0:4000' + '/q', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(graphQLParams),
}).then(response => response.json());
}
class App extends Component {
render() {
return <GraphiQL fetcher={graphQLFetcher} />
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment