Skip to content

Commit

Permalink
feat: add support for @graphiql/plugin-explorer (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mammadataei authored Dec 17, 2022
1 parent da8a164 commit eabdf8f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@graphiql/plugin-explorer": "^0.1.12",
"@graphiql/toolkit": "^0.8.0",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
Expand Down
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/client/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { GraphiQL } from 'graphiql'
import { useEffect, useMemo, useState } from 'react'
import { createGraphiQLFetcher } from '@graphiql/toolkit'
import { useExplorerPlugin } from '@graphiql/plugin-explorer'
import { fetchClientConfig } from './utils/fetchClientConfig'
import type { ClientOptions } from '../types'

import 'graphiql/graphiql.css'
import '@graphiql/plugin-explorer/dist/style.css'

const DEFAULT_QUERY = ''

export default function App() {
const [config, setConfig] = useState<ClientOptions | null>(null)
const [query, setQuery] = useState(DEFAULT_QUERY)

const explorerPlugin = useExplorerPlugin({ query, onEdit: setQuery })

useEffect(() => {
fetchClientConfig().then((config) => {
Expand All @@ -26,5 +34,12 @@ export default function App() {
return null
}

return <GraphiQL fetcher={fetcher} />
return (
<GraphiQL
fetcher={fetcher}
query={query}
onEditQuery={setQuery}
plugins={[explorerPlugin]}
/>
)
}

0 comments on commit eabdf8f

Please sign in to comment.