Relay: Idea: Babel plugin should take a schema path from `.babelrc`?

Created on 11 Feb 2016  路  8Comments  路  Source: facebook/relay

One of the biggest blockers to me diving into Relay (and even getting a working example once I had started) was installing the babel plugin and getting the schema bit of it hooked up. It was really complicated, confusing, and a big blocker to actually experimenting with Relay itself.

I think it would be a lot easier if the babel plugin would allow being passed a path to the file containing the schema, instead of the schema itself (or both for convenience). This would allow it to be fully configured from the .babelrc file instead of needing to create a separate babel-plugin-relay.js file somewhere in the directory. Like so:

    {
      "presets": [
        ...
      ],
      "plugins": [
        ["relay", {
          "file": "./support/schema.json"
        }]
      ]
    }

Which would be way simpler. I think this would require it being renamed to babel-plugin-relay instead of babel-relay-plugin. Or you could use babel-plugin-react-relay if you wanted as well. (Actually looks like the rename is already ready here https://github.com/facebook/relay/pull/732 .)

Most helpful comment

Update: We've built babel-plugin-react-relay supporting different source types such as JSON files, JS schema definitions and even URL schema endpoints.

This is meant to provide a more convenient and powerful solution without the need for scripts like build/babelRelayPlugin.js.

@ianstormtaylor would love to hear your thoughts on the API 馃憤

All 8 comments

@ianstormtaylor Until then you can use the babel-relay-plugin-loader in your .babelrc

I totally agree with @ianstormtaylor's suggestion and think it would be a big win in terms of minimising first steps when getting started with Relay.

I just had a long conversation with the guys from Babel and learned that it's not really possible (or at least recommended) to wrap a babel plugin. The functionality should rather be included in the plugin itself.

I really like the syntax Ian has proposed and did some research: It is possible to access the provided options ("file": "./support/schema.json") in the babel plugin via FunctionDeclaration (see here).

@facebook-team: Is this something you would consider to implement?

We're happy to support this. Note that this proposal avoids the main complication of previous suggestions to simplify the plugin such as this one, because it passes the schema in JSON form (loading a JS schema directly won't work bc of conflicting GraphQL versions and that cause instanceof checks to fail).

Want to submit a PR for this?

Unfortunately I don't have to time right now to properly dive into Babel in order to implement it. But I'm glad that this is something you guys are happy with as well :-)

Update: We've built babel-plugin-react-relay supporting different source types such as JSON files, JS schema definitions and even URL schema endpoints.

This is meant to provide a more convenient and powerful solution without the need for scripts like build/babelRelayPlugin.js.

@ianstormtaylor would love to hear your thoughts on the API 馃憤

It would be great if Babel had some initialization stage, so that you could configure your plugins asynchronously.

I will show Note: The code generator has deoptimised the styling of "/Users/yutin/Develop/bunninn/client/mobile/node_modules/immutable/dist/immutable.js" as it exceeds the max of "100KB"

when setting babelRelayPlugin in .babelrc

Relay Modern is now out with a new plug-in and compiler architecture, so closing this because it is couched in terms of the old plug-in which is unlikely to be worked on further in the future. Please file any new issues against Relay Modern as separate issues. Thanks for the discussion!

Was this page helpful?
0 / 5 - 0 ratings