examples/graphiql-vite-react-router/README.md
ssr: trueWhen using GraphiQL with React Router’s SSR mode,
you need to mark the GraphiQL component as a client module
by adding .client to the file name.
// graphiql.client.tsx
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
const fetcher = createGraphiQLFetcher({ url: 'https://my.backend/graphql' });
export const graphiql = <GraphiQL fetcher={fetcher} />;
// route.ts
import type { FC } from 'react';
import type { LinksFunction, MetaFunction } from 'react-router';
import graphiqlStyles from 'graphiql/style.css?url';
import { graphiql } from './graphiql.client';
export const meta: MetaFunction = () => {
return [{ title: 'API Explorer' }];
};
export const links: LinksFunction = () => {
return [{ rel: 'stylesheet', href: graphiqlStyles }];
};
const Route: FC = () => {
return graphiql;
};
export default Route;
yarn dev to start Vite dev server.yarn build to build production ready transpiled files. Find the output in dist folder.