Skip to content
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

Idea: Babel plugin should take a schema path from .babelrc? #819

Closed
ianstormtaylor opened this issue Feb 10, 2016 · 8 comments
Closed

Idea: Babel plugin should take a schema path from .babelrc? #819

ianstormtaylor opened this issue Feb 10, 2016 · 8 comments

Comments

@ianstormtaylor
Copy link

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 #732 .)

@ianstormtaylor ianstormtaylor changed the title Idea: Babel plugin should take a schema path from .babelrc? Idea: Babel plugin should take a schema path from .babelrc? Feb 10, 2016
@BerndWessels
Copy link

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

@schickling
Copy link
Contributor

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?

@josephsavona
Copy link
Contributor

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?

@schickling
Copy link
Contributor

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 :-)

@schickling
Copy link
Contributor

schickling commented Apr 20, 2016

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 👍

@Vanuan
Copy link

Vanuan commented May 25, 2016

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

@yutin1987
Copy link
Contributor

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

@wincent
Copy link
Contributor

wincent commented May 27, 2017

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!

@wincent wincent closed this as completed May 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants