Skip to content

📝 docs(graphql-codegen-client-preset): monorepo paths - #692

Closed
Jakub Kopřiva (koprivajakub) wants to merge 1 commit into
swc-project:mainfrom
koprivajakub:docs/monorepo-artifact-directory-tmpl
Closed

Jakub Kopřiva (koprivajakub) wants to merge 1 commit into
swc-project:mainfrom
koprivajakub:docs/monorepo-artifact-directory-tmpl

Conversation

@koprivajakub

Copy link
Copy Markdown
Contributor

Supersedes #627, which edited the generated README.md instead of README.tmpl.md. This PR applies the same docs change to the template.

Problem Statement

In a Turborepo / pnpm workspace where the Next.js app lives below the workspace root, the README's Next.js example resolves artifactDirectory against the workspace root rather than the Next app directory. The build then fails with:

Module not found: Can't resolve './../../../../src/gql/graphql'

and the error message doesn't point to the artifact path as the cause.

Root cause: Turbopack passes its root directory (by default, the directory containing the lockfile) to SWC as the cwd. The plugin joins relative artifactDirectory values onto that cwd, so "./src/gql" lands at <workspace-root>/src/gql instead of <workspace-root>/apps/web/src/gql.

Reproduced with Next 16.2.6 + Turbopack + Yarn workspaces, plugin 0.24.0.

Solution

Add a callout under the Next.js section of README.tmpl.md explaining the workspace-root anchoring, plus a copy-pasteable monorepo example with artifactDirectory: "apps/web/src/gql". Docs only.

Compared to #627, this also addresses the review feedback there:

  • The callout applies only to Turbopack using the workspace root as cwd. Webpack builds, or setups that pin turbopack.root to the app directory, keep the app-relative path.
  • The example includes export default nextConfig; so it works when pasted as next.config.mjs.

Test Plan

Verified the config end-to-end in a Turborepo (Yarn 4 workspaces, Next 16.2.6 + Turbopack, plugin 0.24.0): with the workspace-root-relative artifactDirectory, the build succeeds and the resulting chunks no longer contain the GraphQL operation strings (tree-shaking works as the plugin advertises).

🤖 Generated with Claude Code

Document that Turbopack passes its workspace root to SWC as cwd, so
relative artifactDirectory values must be written from that root in
monorepos. Edits README.tmpl.md, which README.md is generated from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f878cb6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-25T21:26:28.122719Z
We couldn’t complete this review. Comment @codex review to try again.
f878cb6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@github-actions

Copy link
Copy Markdown
Contributor

This repository accepts pull requests from approved contributors, users with write access, and bot accounts. Your account is not currently on the approved contributor list, so this pull request is being closed automatically.

Thank you for your interest in contributing to SWC. This notice intentionally asks you to open an issue instead of contacting the maintainers. We do not add new accounts to the approved contributor list unless there are truly exceptional circumstances, so please do not leave comments or send messages that ask us to add your account. Also, our repository guidelines tell us not to use code from forks or fixes linked in comments, and reviewing such code takes a large amount of maintainer time. Because of this, links to forks or fixes do not help the project, so please do not post them in issues or pull requests. We appreciate your understanding.

Please open an issue describing the bug or proposed improvement instead of submitting a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant