-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port Relay Babel plugin to SWC #30805
Comments
|
Something to bare in mind is that because the transforms generate an import declaration, any such plugin would need to be able to read a project's Relay configuration to determine where the |
In JS-world > require('relay-config').loadConfig().artifactDirectory
'src/queries/__generated__'` |
The next stable release of relay v13 will be in rust (their checklist, compiler/)
Can relay being in rust benefit this effort in any way? |
As far as I'm aware the answer is no because the compiler would already be run next to having the transform. |
fyi: |
🤸♂️ What's the status on this? waiting for it to finally move to |
## Feature Implements feature requested in #30805. A few people including myself have been looking to use Relay with Next.JS and want to use the new Rust Compiler. This is my stab at an implementation. ### How it works? Finds all `graphql` tagged template experssions and replaces them with `require`s to the file generated by Relay. ### Where I need help - I've only worked with Rust a handful of times so I would appreciate any feedback on my use of language features. - Is there any performance overhead to many duplicate usages of `require`? I imagine there's a cache in place but I want to be sure. - I've added some unit tests & integration tests but I might be missing some use cases. Feel free to comment some use cases I'm not thinking about. - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Documentation added - I haven't added any docs since this is an experimental API. ## Documentation / Examples You're expected to be running the Relay Compiler along side Next.JS when you're developing. This is pretty standard. I wouldn't expect people to have any problem with this. ### Usage In your `next.config.js` ```js module.exports = { experimental: { relay: { language: 'typescript', // or 'javascript` artifactDirectory: 'path/to/you/artifact/directory' // you can leave this undefined if you did not specify one in the `relay.json` } } } ``` Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
## Feature Implements feature requested in vercel#30805. A few people including myself have been looking to use Relay with Next.JS and want to use the new Rust Compiler. This is my stab at an implementation. ### How it works? Finds all `graphql` tagged template experssions and replaces them with `require`s to the file generated by Relay. ### Where I need help - I've only worked with Rust a handful of times so I would appreciate any feedback on my use of language features. - Is there any performance overhead to many duplicate usages of `require`? I imagine there's a cache in place but I want to be sure. - I've added some unit tests & integration tests but I might be missing some use cases. Feel free to comment some use cases I'm not thinking about. - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Documentation added - I haven't added any docs since this is an experimental API. ## Documentation / Examples You're expected to be running the Relay Compiler along side Next.JS when you're developing. This is pretty standard. I wouldn't expect people to have any problem with this. ### Usage In your `next.config.js` ```js module.exports = { experimental: { relay: { language: 'typescript', // or 'javascript` artifactDirectory: 'path/to/you/artifact/directory' // you can leave this undefined if you did not specify one in the `relay.json` } } } ``` Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
@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:After
babel-plugin-relay
runs: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
The text was updated successfully, but these errors were encountered: