Created
August 6, 2017 20:14
-
-
Save dustinsmith1024/335c2ded7be298061103085e4e89f074 to your computer and use it in GitHub Desktop.
Graphiql start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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