graphql-codegen-client-preset: inline calls, the leftover tag import, and name-only matching keep the document map in bundles
Los mantenedores suelen responder en 1 día
@kdy1 ya está trabajando en esto.
Desde el 2/11/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
- Lenguaje dominante
- Rust
- Estrellas
- 387
- Forks
- 111
- Merge medio
- 3 h 40 min
- PR fusionados (30 d)
- 18
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de swc-project/plugins
-
Dificultad 3/5 1-2 días Aptitud para principiantes 57/100
swc-project/plugins#691 ·
Los mantenedores suelen responder en 1 día
-
`mut-cjs-exports` doesn't properly handle circular imports with barrel filesQuizá libre de nuevo @kdy1 la tomó hace 253 días y no hay ningún pull request abierto. Abierto
swc-project/plugins#577 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Feature Request] Dead code elimination for assert statements in production buildsQuizá libre de nuevo @kdy1 la tomó hace 319 días y no hay ningún pull request abierto. Abiertoenhancement
swc-project/plugins#574 · 8 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
swc-project/plugins#214 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dependency DashboardAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 10/100
swc-project/plugins#147 ·
Los mantenedores suelen responder en 1 día
Todos los issues de swc-project/plugins
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Top-right curve point in Color Grading cannot be dragged on macOS (scrollbar intercepts click)Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
storytold/filmcraft#5386 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
enhancement in-progress
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100