Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions contrib/graphql-codegen-client-preset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ const nextConfig = {
};
```

> **Monorepos:** Next.js uses [Turbopack's workspace root](https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#root-directory) — the directory containing your lockfile (`yarn.lock`, `pnpm-lock.yaml`, etc.) — as the SWC `cwd`. If your Next app lives below that root, write `artifactDirectory` as a path from the workspace root down to the codegen output, not as a path relative to the Next app:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit monorepo path guidance to Turbopack

This callout is under the general Next.js section, but the behavior being linked is specifically Turbopack’s filesystem root and can also be changed with turbopack.root. For a monorepo app still building with webpack, or one that pins turbopack.root to the app directory, following this advice makes the plugin join apps/web/src/gql onto the app cwd and resolve apps/web/apps/web/src/gql, reintroducing missing imports. Please qualify the guidance as applying only to Turbopack with the workspace-root cwd, or include the app-relative variant for other Next.js builds.

Useful? React with 👍 / 👎.


```ts
// apps/web/next.config.mjs, in a Turborepo where yarn.lock sits at the repo root
const nextConfig = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Export the monorepo Next config example

Because this added example is labeled apps/web/next.config.mjs, copying it as-is leaves nextConfig as a local variable that Next never reads, so the SWC plugin options in the snippet are silently not applied. Add the ESM export default nextConfig line (or switch the example to CommonJS) so the documented monorepo fix actually takes effect when pasted into a new config file.

Useful? React with 👍 / 👎.

experimental: {
swcPlugins: [
[
"@swc-contrib/plugin-graphql-codegen-client-preset",
{ artifactDirectory: "apps/web/src/gql", gqlTagName: "graphql" },
],
],
},
};
```

#### `.swcrc`

```json5
Expand Down
Loading