Created
July 1, 2021 15:22
-
-
Save reconbot/76837769e4a12c5267c255286b66ddb2 to your computer and use it in GitHub Desktop.
How to get graphql playground to work on nextjs
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
import dynamic from 'next/dynamic' | |
import Head from 'next/head' | |
const WS_URL = process.env.NEXT_PUBLIC_WS_API_ENDPOINT | |
const API_URL = process.env.NEXT_PUBLIC_API_ENDPOINT | |
// You might ask yourself, what is this business? | |
// And I might ask why on earth does Playground require window on module load breaking any hope | |
// of ssr even if we don't render it but only import it | |
const Playground = dynamic<any>( | |
async () => { | |
const [{ store, Playground }, { Provider }] = await Promise.all([ | |
import('graphql-playground-react'), | |
import('react-redux'), | |
]) | |
return ({ ...args }) => { | |
return <Provider store={store}> | |
<Playground {...args} /> | |
</Provider> | |
} | |
}, | |
{ ssr: false }, | |
) | |
export default function PlaygroundPage () { | |
return <> | |
<Head> | |
{/* eslint-disable-next-line @next/next/no-page-custom-font */} | |
<link | |
href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Source+Code+Pro:400,700&display=swap" | |
rel="stylesheet" | |
/> | |
</Head> | |
<Playground | |
endpoint={API_URL} | |
subscriptionEndpoint={WS_URL} | |
/> | |
</> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment