Skip to content

Commit

Permalink
integrate into example
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Sep 7, 2022
1 parent 74678f8 commit 7bc8b1a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 25 deletions.
5 changes: 4 additions & 1 deletion examples/graphiql-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
"start": "cross-env NODE_ENV=development webpack-dev-server"
},
"dependencies": {
"@graphiql/plugin-code-exporter": "^0.0.1",
"@graphiql/plugin-explorer": "^0.1.3",
"@graphiql/toolkit": "^0.7.3",
"graphiql": "^2.0.6",
"graphql": "^16.4.0",
"graphql-ws": "^5.5.5",
"react": "^17.0.2"
"react": "^17.0.2",
"regenerator-runtime": "^0.13.9"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.8.3",
Expand Down
65 changes: 43 additions & 22 deletions examples/graphiql-webpack/src/index.jsx
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'));
2 changes: 1 addition & 1 deletion packages/graphiql-plugin-code-exporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphiql/plugin-code-exporter",
"version": "0.0.0",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/graphql/graphiql",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-plugin-code-exporter/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function ExporterPlugin(props: GraphiQLCodeExporterProps) {
return <GraphiQLCodeExporter {...props} />;
}

export function useExplorerPlugin(props: GraphiQLCodeExporterProps) {
export function useExporterPlugin(props: GraphiQLCodeExporterProps) {
const propsRef = useRef(props);
propsRef.current = props;
return useMemo<GraphiQLPlugin>(
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15551,6 +15551,11 @@ regenerator-runtime@^0.13.4:
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==

regenerator-runtime@^0.13.9:
version "0.13.9"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==

regenerator-transform@^0.14.2:
version "0.14.5"
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.5.tgz#c98da154683671c9c4dcb16ece736517e1b7feb4"
Expand Down

0 comments on commit 7bc8b1a

Please sign in to comment.