# Fumadocs (Framework Mode, Waku): GraphQL
URL: /docs/waku/integrations/graphql
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/graphql/index.mdx

Generating docs for GraphQL schema.

Generate API reference pages from GraphQL schemas, with a playground for queries, mutations and subscriptions. See the [demo](/docs/graphql).

## Setup [#setup]

Install the required packages.

```npm
npm i @fumadocs/graphql graphql
```

### Generate Styles [#generate-styles]

Add the following line:

```css title="Tailwind CSS"
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';
/* [!code ++] */
@import '@fumadocs/graphql/css/preset.css';
```

### Configure Plugin [#configure-plugin]

Create the GraphQL server instance and the `<GraphQLPage />` component.

```ts tab="lib/graphql.ts"
import { createGraphQL } from '@fumadocs/graphql/server';

// note: this is a server-side API
export const graphql = createGraphQL({
  // the GraphQL schema, it accepts:
  // SDL files/URLs (including `extend type`), SDL text,
  // introspection results, and `GraphQLSchema` instances.
  input: ['./schema.graphql'],
});
```

```tsx tab="components/api-page.tsx"
'use client';
import { createGraphQLPage } from '@fumadocs/graphql/ui';

export const GraphQLPage = createGraphQLPage({
  playground: {
    // enable the interactive playground on operation pages (optional)
    url: 'https://api.example.com/graphql',
  },
});
```

See [`createGraphQL()`](/docs/waku/integrations/graphql/server) and [`createGraphQLPage()`](/docs/waku/integrations/graphql/api-page) for their options.

### Generate Pages [#generate-pages]

Pass `staticSource()` to your [`loader()`](/docs/headless/source-api/source). It generates pages without writing files.

```ts title="src/lib/source.ts"
import { loader } from 'fumadocs-core/source';
import { defineDocs } from 'fumadocs-mdx/macro';
import { graphql } from '@/lib/graphql'; // [!code ++]

const docs = defineDocs({
  dir: 'content/docs',
});

export const source = loader(
  // [!code ++:6]
  {
    docs: docs.toFumadocsSource(),
    graphql: await graphql.staticSource({
      baseDir: 'graphql',
    }),
  },
  {
    baseUrl: '/docs',
    // [!code ++:2] optional: adds a query/mutation/subscription badge to each page item in page tree
    plugins: [graphql.loaderPlugin()],
  },
);
```

`staticSource()` generates a page per operation, grouped into folders by kind (e.g. `queries/`). Pages of named types are [opt-in](/docs/waku/integrations/graphql/server#includeoperations--includetypes).

**Pages of `source` now have two types, `docs` and `graphql`.** Update every place that uses `source`.

Render GraphQL pages with `<GraphQLPage />` in your docs page:

```tsx title="src/pages/docs/[...slugs].tsx"
import { GraphQLPage } from '@/components/api-page'; // [!code ++]

export default function Page({ slugs }: PageProps<'/docs/[...slugs]'>) {
  const page = source.getPage(slugs);
  if (!page) unstable_notFound();

  // [!code ++:10]
  if (page.type === 'graphql') {
    return (
      <DocsPage full>
        <DocsTitle>{page.data.title}</DocsTitle>
        <DocsBody>
          <GraphQLPage {...page.data.getGraphQLPageProps()} />
        </DocsBody>
      </DocsPage>
    );
  }

  // ...
}
```

<Callout type="warn" title="Ensure the migration is complete!">
Run a type check before continuing:

```npm
npm run types:check
```
</Callout>