-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,55 @@ | ||
import React from 'react'; | ||
import 'regenerator-runtime/runtime.js'; | ||
|
||
import * as React from 'react'; | ||
import { render } from 'react-dom'; | ||
import GraphiQL from 'graphiql'; | ||
import snippets from 'graphiql-code-exporter/lib/snippets'; | ||
import { useExplorerPlugin } from '@graphiql/plugin-explorer'; | ||
import { useExporterPlugin } from '@graphiql/plugin-code-exporter'; | ||
|
||
import 'graphiql/graphiql.css'; | ||
import '@graphiql/plugin-explorer/dist/style.css'; | ||
|
||
const Logo = () => <span>My Corp</span>; | ||
|
||
// See GraphiQL Readme - Advanced Usage section for more examples like this | ||
GraphiQL.Logo = Logo; | ||
|
||
const App = () => ( | ||
<GraphiQL | ||
style={{ height: '100vh' }} | ||
headerEditorEnabled | ||
fetcher={async (graphQLParams, options) => { | ||
const data = await fetch( | ||
'https://swapi-graphql.netlify.app/.netlify/functions/index', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
...options.headers, | ||
const App = () => { | ||
const [query, setQuery] = React.useState(''); | ||
const explorerPlugin = useExplorerPlugin({ | ||
query, | ||
onEdit: setQuery, | ||
}); | ||
const exporterPlugin = useExporterPlugin({ | ||
query, | ||
snippets, | ||
}); | ||
|
||
return ( | ||
<GraphiQL | ||
style={{ height: '100vh' }} | ||
query={query} | ||
onEditQuery={setQuery} | ||
plugins={[explorerPlugin, exporterPlugin]} | ||
fetcher={async (graphQLParams, options) => { | ||
const data = await fetch( | ||
'https://swapi-graphql.netlify.app/.netlify/functions/index', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
...options.headers, | ||
}, | ||
body: JSON.stringify(graphQLParams), | ||
credentials: 'same-origin', | ||
}, | ||
body: JSON.stringify(graphQLParams), | ||
credentials: 'same-origin', | ||
}, | ||
); | ||
return data.json().catch(() => data.text()); | ||
}} | ||
/> | ||
); | ||
); | ||
return data.json().catch(() => data.text()); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
render(<App />, document.getElementById('root')); |
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
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
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