@@ -203,3 +203,51 @@ has to be loaded for the theme prop to work.
203203You can also create your own theme in CSS. As a reference, the default
204204` graphiql ` theme definition can be found
205205[ here] ( ../graphiql-react/src/style/codemirror.css ) .
206+
207+ ### Usage with React Router and ` ssr: true `
208+
209+ When using GraphiQL with [ React Router’s SSR mode] ( https://reactrouter.com/api/framework-conventions/react-router.config.ts#ssr ) ,
210+ you need to mark the GraphiQL component as a [ client module] ( https://reactrouter.com/api/framework-conventions/client-modules )
211+ by adding ` .client ` to the file name.
212+
213+ ``` tsx
214+ // graphiql.client.tsx
215+ import type { FC } from ' react' ;
216+ import { GraphiQL } from ' graphiql' ;
217+ import { createGraphiQLFetcher } from ' @graphiql/toolkit' ;
218+
219+ const fetcher = createGraphiQLFetcher ({ url: ' https://my.backend/graphql' });
220+
221+ export const Route: FC = () => {
222+ return <GraphiQL fetcher = { fetcher } />;
223+ };
224+ ```
225+
226+ ``` tsx
227+ // route.tsx
228+ import type { FC } from ' react' ;
229+ import { useEffect , useState } from ' react' ;
230+ import type { LinksFunction , MetaFunction } from ' react-router' ;
231+ import graphiqlStyles from ' graphiql/style.css?url' ;
232+ import { Route as GraphiQL } from ' ./graphiql.client' ;
233+
234+ export const meta: MetaFunction = () => {
235+ return [{ title: ' API Explorer' }];
236+ };
237+
238+ export const links: LinksFunction = () => {
239+ return [{ rel: ' stylesheet' , href: graphiqlStyles }];
240+ };
241+
242+ const Route: FC = () => {
243+ const [mounted, setMounted] = useState (false );
244+
245+ useEffect (() => {
246+ setMounted (true );
247+ }, []);
248+
249+ return mounted ? <GraphiQL /> : ' Loading...' ;
250+ };
251+
252+ export default Route ;
253+ ```
0 commit comments