graphql-codegen-client-preset: inline calls, the leftover tag import, and name-only matching keep the document map in bundles
Maintainer thường phản hồi trong vòng 1 ngày
@kdy1 đang làm issue này rồi.
Từ ngày 2/11/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the bug
@swc-contrib/plugin-graphql-codegen-client-preset rewrites const X = graphql(...) declarations. Three cases still leave the client-preset document map in the bundle, or produce imports that don't exist:
- Calls outside a variable initializer are not rewritten.
useMutation(graphql(...)),{ query: graphql(...) }, andapollo.query({ query: graphql(...) })keep calling thegql.tsfunction, sogql.tsand its map of every document stay in the bundle. Within a declaration, the first declarator that isn't a tag call returns early, soconst a = 1, b = graphql(...)is not rewritten either. - The tag import stays after every call is rewritten.
import { graphql } from './gql'keepsgql.tsin the module graph. Itsimport * as types from './graphql'then keeps every generated document, because a namespace import blocks export-level tree shaking. - The tag is matched by name only. A project that also compiles a package with its own client-preset output (for example an SDK with
import { graphql } from '../lib/gql-generated/gql') has those calls rewritten to imports from the application'sartifactDirectory, where the documents don't exist. The build fails, or the import resolves toundefined.
URL to minimal reproduction
A fix with tests is ready on a fork. It's the closed PR #686, commit f6d6cfb, branch graphql-codegen-import-sources. It was closed automatically by the contributor policy. Inline reproduction with artifactDirectory: "./src/gql" and gqlTagName: "graphql":
import { graphql } from './src/gql';
useMutation(graphql(`mutation SaveUser { id }`)); // not rewritten (case 1)
const a = 1, b = graphql(`query GetUser { id }`); // not rewritten (case 1)
const c = graphql(`query GetOrg { id }`); // rewritten, but the graphql import stays (case 2)
// packages/sdk/queries.ts, a separate client-preset output
import { graphql } from '../lib/gql-generated/gql';
const q = graphql(`query GetVendor { id }`); // rewritten to ./src/gql/graphql's GetVendorDocument, which doesn't exist (case 3)
Expected behavior
- Every tag call whose first argument is a template literal is rewritten, in any expression position. A document used twice is imported once.
- There is an opt-in way to limit rewriting to tags imported from the application's artifact directory. With that option set, the plugin removes the tag import once nothing references it, so bundlers can drop
gql.ts.
The fork adds a gqlImportSources option for this. It lists the module specifiers the tag is imported from, including aliased imports. When the option is unset, matching and imports behave as they do today. It includes 8 new tests; the 23 existing tests are unchanged and pass. cargo clippy is clean and the option is documented in README.tmpl.md.
Additional context
In a Next.js 16.4.2 (Turbopack) application with about 2,300 documents, these changes let Turbopack drop the document map and any document a route doesn't import. The application also splits its generated documents into one module per document. Client entry JS for one route went from 12.1 MB to 6.4 MB (2,266 KB to 1,922 KB gzip), without hoisting inline calls and without a workaround for an SDK package that has its own graphql().
cc @kdy1 (plugin maintainer) and @mischnic (Turbopack tree-shaking context). I'm happy to adjust the option's name or shape, or to split this into separate changes if you prefer.
- Ngôn ngữ chính
- Rust
- Star
- 387
- Fork
- 111
- Merge trung bình
- 3 giờ 40 phút
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của swc-project/plugins
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 57/100
swc-project/plugins#691 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`mut-cjs-exports` doesn't properly handle circular imports with barrel filesCó thể làm lại được @kdy1 đã nhận 253 ngày trước và không có pull request nào đang mở. Đang mở
swc-project/plugins#577 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature Request] Dead code elimination for assert statements in production buildsCó thể làm lại được @kdy1 đã nhận 319 ngày trước và không có pull request nào đang mở. Đang mởenhancement
swc-project/plugins#574 · 8 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
swc-project/plugins#214 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dependency DashboardĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 10/100
swc-project/plugins#147 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của swc-project/plugins
Issue tương tự
-
bug good first issue web
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
triage: not actionable
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
oxc-project/oxc#30518 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: panel
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
frandev94/shattered-islands#98 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày