Port Relay Babel plugin to SWC
See original GitHub issue@hanford has done a bunch of research into porting babel-plugin-relay. It comes down to this fairly simple transform: https://gist.github.com/hanford/10401629eb7d82d47b275f59356d86f5 so I think we can port it to SWC relatively easily without having to implement a GraphQL parser.
Message from @hanford:
All babel-plugin-relay
does, is look for `graphql``` tagged template literals, performs a regex to extract the name of the operation and then generates appends ImportDefaultSpecifier with that name.
-
Before
babel-plugin-relay
running:function MyQueryRenderer () { return ( <QueryRenderer query={graphql` query SearchUserQuery { findUser { name } } `} /> ) }
-
After
babel-plugin-relay
runs:import graphql__a6767a3b from "dazzle-types/SearchUserQuery.graphql"; function MyQueryRenderer () { return ( <QueryRenderer query={graphql__a6767a3b} /> ); }
In addition to the babel plugin I created, I also have a JSCodeshift that I’ve been running on our frontend to then allow me to begin playing around with SWC.
The source for the JSCodeshift is below:
https://gist.github.com/hanford/003f07533f7bfc8af7fc90a838f0e963
Issue Analytics
- State:
- Created 2 years ago
- Reactions:35
- Comments:9 (3 by maintainers)
Top GitHub Comments
@aalises and other folks in this thread. I tried adding support for Relay in https://github.com/vercel/next.js/pull/33240 . Can y’all check it out and give feedback?
🤸♂️ What’s the status on this? waiting for it to finally move to
SWC
.