How do I automatically get __generated__ files with Relay Modern?

#1

I am trying to use expo in a project with relay. I can generate files (eg. generated/SomeMutation.graphql.js) with “yarn relay”.

Are those files supposed to be committed? Since they are generated, probably not. How do I auto-generate these?

The FAQ in https://docs.expo.io/versions/latest/introduction/faq#can-i-use-expo-with-relay seems to imply that I could get that automatically without having to run “yarn relay” every time. It says to put “pathToYourBabelRelayPlugin”, but what would that be? I tried “./node_modules/babel-plugin-relay”, but that did nothing.

Am I misunderstanding how to use it or what it’s supposed to do?

Current .babelrc:

{
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": [
        "relay",
        "transform-react-jsx-source"
      ]
    }
  }
}

Thanks,
dB.

#2

That answer in our FAQ is a bit outdated now, since it only applies to Relay Classic. Relay Modern docs have these instructions for setting up Relay Modern that should also work with Expo: https://facebook.github.io/relay/docs/en/installation-and-setup.html
It also mentions you can run the Relay compiler with the --watch flag (requires installing watchman), and have it generate the files everytime you make changes to your source files.

Also note that in your .babelrc file the Relay plugin should go in the top level plugins array since it should be enabled for both development and production builds:

{
  "presets": ["babel-preset-expo"],
  "plugins": ["relay"],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source"
      ]
    }
  }
}
#3

So do I understand this correctly - there’s no way to automatically generate/watch files without running relay with watchman externally?

#4

Also, I am happy to try to PR a doc fix, is the right version 19? https://github.com/expo/expo-docs/blob/d7fb9a30f772d9f25152e4a6e1c21481752d5ffe/versions/v19.0.0/introduction/faq.md?

#5

@dblock you might try using npmjs.org/concurrently – it makes it very easy to run multiple tools in parallel with npm or yarn.

If you open a PR against the docs, please target the unversioned directory so that the changes will be available in future releases of the SDK as well.

#6

Is there a mechanism to do something like this in Expo? I’m curious whether it’s otherwise implementable.

closed #7

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.