`babel-plugin-relay` bug: `eagerEsModules: true` only works with single-project Relay configs.
Summary of the bug
When "eagerEsModules": true is set in a multi-project Relay config, babel-plugin-relay transforms graphql tagged templates into require calls, like this:
var _MeQuery;
var MeQuery =
_MeQuery !== void 0
? _MeQuery
: ((_MeQuery = require("./__generated__/MeQuery.graphql")),
_MeQuery.hash &&
_MeQuery.hash !== "bce9f1cc4614c3f306814d78c53b009b" &&
console.error(
"The definition of 'MeQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."
),
_MeQuery);
Expected behavior
Just like it does with a single-project Relay config, babel-plugin-relay should transform graphql tagged templates into import declarations when "eagerEsModules": true is set, like this:
import _MeQuery from "../__generated__/MeQuery.graphql";
var MeQuery =
(_MeQuery.hash &&
_MeQuery.hash !== "bce9f1cc4614c3f306814d78c53b009b" &&
console.error(
"The definition of 'MeQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."
),
_MeQuery);
Reproducing the bug
I created a reduced test case to demonstrate this behavior. If you want to reproduce the bug yourself, you can clone the repo, run the build commands, and compare the output. The repo also includes the dist files (one each for single and multi-project configs), so if you want to take my word for It, you can just compare the outputs on GitHub. More detail in the README.
Thanks for catching this! Do you want to work on PR to fix?
I mean, yeah. It will take me a minute, though, since I'm enough of a beginner to have lots of stupid questions still. But I've been working on it, and I can open a PR once I figure it out.
I think I got it. I opened #4934.
I'm looking forward to this feature