question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Reactions:35
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
tbezmancommented, Jan 13, 2022

@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?

12reactions
aalisescommented, Jan 3, 2022

🤸‍♂️ What’s the status on this? waiting for it to finally move to SWC.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installation and Setup - Relay
The below configuration of babel-plugin-relay and relay-compiler can be applied using a single configuration file by using the relay-config ...
Read more >
Advanced Features: Next.js Compiler
js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for individual...
Read more >
Migrating from Babel - SWC
This table outlines the differences between SWC and Babel. babel package name, swc. babel-plugin-external-helpers, ✔️. babel-plugin-proposal- ...
Read more >
@swc/plugin-relay - NPM Package Overview - Socket
SWC plugin for relay. Version: 1.5.33 was published by kdy1. Start using Socket to analyze @swc/plugin-relay and its 0 dependencies to ...
Read more >
Tim on Twitter: "@wongmjane @padmaia @kdy1dev You'll still be ...
Super excited about these initial results enabling next-swc. next-swc is SWC ... E.g. we'll likely have to port some commonly used Babel plugins...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found