-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Use Relay #462
Comments
You can't add more transpilation steps without ejecting, so right now I think the answer is no. It would be nice if you could use Relay without ejecting, somehow, though. |
Ok thanks for information. Do you know how to add such configuration to ejected project? Do you have some link to tutorial/guide how to do it? |
We could detect if you have |
@gaearon that would be great! |
In the meantime does anyone know how to configure webpack after ejecting to work with Relay? |
I think the solution @gaearon would make a lot of sense! @jagi in the meanwhile you can Let me know if you need any help setting it up. |
@gaearon thinking about writing a pull request for your idea above "detect if you have Question though. The babelRelayPlugin needs a reference to a More explanation is found here https://facebook.github.io/relay/docs/guides-babel-plugin.html#content. We could configure babelRelayPlugin to look for Additionally we could provide an Does this sound reasonable? Other ideas? |
@saintsjd I think it makes a lot of sense in order to simplify this process further. What do you think of a workflow like proposed here: https://github.com/graphcool/graphql-config |
@schickling Nice suggestion! I will try it. |
cc @josephsavona, I expect the setup will be different in Relay 2? |
The setup in Relay2 will be basically the same - a single babel plugin that requires access to the schema. So it seems like implementing support would involve:
So overall, I'm inclined to say that we should change |
@josephsavona This sounds like a good plan for Since we can look up the |
@fson Good points - I hadn't considered the plugin versioning aspect. Ideally the plugin would rarely have to change. Instead, the plugin can have a peer dependency on a separate module - the Relay2 compiler - that it delegates to. Then the developer can be in charge of updating the Relay and the compiler versions together (and Relay can have a peer dependency on the compiler to enforce compatible versions), and |
I was studying the source for See https://github.com/facebook/relay/blob/master/scripts/babel-relay-plugin/src/getBabelRelayPlugin.js#L35 and https://github.com/facebook/relay/blob/master/scripts/babel-relay-plugin/src/getBabelRelayPlugin.js#L245-L247 Perhaps we don't need to change
Then enable the plugin if the user wants relay (
I haven't tried this yet. |
@saintsjd yeah, that's roughly how it would be implemented, I think. The plugin changes are more due to the need to make release coordination easier. |
I am working on a pull request for this. But, instructions in CONTRIBUTING.md in the section Here is what I am doing...
This gives an error
|
I think I found a workaround.
|
Oops, sorry, I broke this. |
Thanks a ton @gaearon! Confirmed. The fix works great on my end. |
I'm helping @saintsjd with this pull request. We have the schema being generated successfully like this:
and we also have the babelRelayPlugin enabled with, I think, the right settings. But for some reason we are getting a failure to compile with webpack. The specific error is:
When we feed the babelRelayPlugin a string of Relay.QL it works fine but something in the build process is keeping babelRelayPlugin from receiving the Relay.QL fragments... any ideas why this might be? |
@maxwell-oroark Hmm, that error isn't very helpful in narrowing down the problem. I don't recall (and can't find with github search) a "missing path" assertion in the plugin code, so it looks like maybe the error is coming from somewhere else. Does the error occur simply by enabling the plugin, or does enabling the plugin work so long as there are no |
@josephsavona The error goes away when |
@maxwell-oroark strange. Unfortunately the error doesn't give enough info that I can give much advice. If you can possibly run the code with a debugger that would be ideal, otherwise this may require digging in and adding manual console.log statements in order to narrow things down. Maybe start with some log statements in the Relay plugin just to see if it is initialized and at least called. |
@maxwell-oroark and I have made progress. We have a working version of create-react-app that enables relay support when you have We don't have error messages or nice instructions in the readme yet. We are working on those before making the pull request. If you want to take a look you can see progress here: https://github.com/maxwell-oroark/create-react-app/tree/relay-support |
Merged with master. We now have eject support, nicer errors, and a great README. Note the environment variable is changed to REACT_APP_ GRAPHQL_URL |
I talked with @schickling and we would like come up with a standard approach for specifying the GraphQL schema/endpoint that can also be adopted by create-react-app. I think one potential issue with the current @josephsavona do you have some ideas about this from Relay point of view? I think it would be fantastic, if we can come up with a GraphQL configuration approach for that can be adopted in CRA, but also in the underlying tools like babel-relay-plugin eventually. I commented in the pull request about some difficulties in fetching the schema in a Babel plugin – is that something that you could see changing with Relay 2 though? |
since create-react-app does not yet support the babel relay plugin we need to eject !!! ... although this might be coming to a repo near you soon facebook/create-react-app#462 but for now we have to eject, install babel-relay-plugin, babel-plugin-react-relay, and "babel-preset-stage-0 (for some reason) manually ... then for some other reason I cannot get the babelrc to run from the package.json so I needed to add the .babelrc file and override that so now .babelrc should call babelRelayPlugin so we can compile the queries etc in the transpile ... note this needs the schema so you need to update the schema.json and schema.graphql files using the getSchema.js util (maybe I should move all these into config? .. I kinda want to keep the eject clean though) btw the webkit-dev-server will only reload the schema if npm is restarted so if you want to change the schema on the server side you need to restart npm and call node ./getSchema.js in between to update relay also while I was ejecting I did some small tweaks to their scripts that shit me to tears ... like clearing the screen on each build (I like console output dam it) and starting the browser all the time
To expand on @vdanchenkov comment, consider using a timestamp to only expire the cache when the
|
@dphaener Can you elaborate on your solutions, maybe paste a fuller example? |
Should we use relay-fullstack (https://github.com/lvarayut/relay-fullstack) instead if we want to use React with Relay? Lots of posts in this thread but I am still not sure how to use Relay with create-react-app. (I wish github had a tag for marking the correct answer similar to Stack Overflow.) |
@nikhilag It is as simple as ejecting after install and editing your package.json. Of course you need to install the necessary Relay packages as you would usually do.
|
@ivosabev @nikhilag Sorry for the delay here. I've actually modified how I am doing this, so here's a more complete example. Instead of relying on the timestamp of the 'schema.json', which would require that you manually update that file and restart the server, I'm using nodemon to run the Here's my {
"restartable": "rs",
"verbose": true,
"execMap": {
"rb": "ruby"
},
"watch": [
"../app/graphql/**/*"
],
"events": {
"restart": "touch .schema_stamp && osascript -e 'display notification \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\"'"
},
"env": {
"NODE_ENV": "development"
},
"ext": "rb"
} I'm using an osascript to send a notification in my Mac, but it's not necessary. The important thing there is that we are touching the Here is the relevant part of my webpack config: loaders: [
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: {
cacheDirectory: true,
cacheIdentifier: fs.statSync('.schema_stamp').mtime
}
},
] You'll notice here that I am now watching the timestamp of the I'm also using babel-plugin-react-relay here, so configuring where to get your Relay schema can be done in several ways, as outlined here: https://github.com/graphcool/graphql-config. In my case, it's in my "graphql": {
"request": {
"url": "http://localhost:7000/graphql",
"headers": {
"Authorization": "Bearer <my_special_introspection_token>"
}
}
} That's pretty much all I had to do to get Relay going with Create React App. Now when I start my server, I just use P.S. This was all done after ejecting the app, BTW. |
If you want to stay unejected, you can also use https://github.com/Valentin-Seehausen/create-react-app. It is basically a wrapper for the Relay Support PR #662, that was canceled. Feedback welcome, would be cool, if this made things easier. |
Closing as we don't plan this to work out of the box, but I'm glad that there's a fork supporting it! |
@gaearon why the change of heart? |
This is quite unfortunate for Relay, that even FB's own tools don't support them, since it is just a matter of letting the user extend the Babel configuration. |
I'm pretty sure that with the new version of Relay the tooling will become a lot more flexible. This should make this possible again without needing to fork CRA. |
There are a bunch of people at Facebook interested in making create-react-app work more smoothly with Relay. The tricky thing right now is that there are a ton of improvements on Relay coming, and we're not sure whether/how that will change the getting-started experience. So I think we should wait for the next big Relay release and then take another hard look at this and see how we can make the Relay <-> React experience better. |
We may come back to this, but now is not a good time, especially with all the ES modules churn (we're in the process of switching to Webpack 2, it has bugs, etc). We want to retain full control over Babel configuration to allow a guaranteed stable experience for all users. We may explore making Babel configurable once the dust settles a little bit. |
@gaearon how about reopening this and leaving it at the proposal state and documenting that this will not be considered until Relay 2 lands, so that we won't have another issue opened? |
I think a simple solution is needed here which works seamlessly with create-react-app without requiring to eject or get react-scripts from somewhere else. Given that create-react-app has gained so much popularity, I think people won't use Relay just because it is not straightforward to use it with create-react-app. I had to switch to Apollo (which is an excellent client as well) because I was running into issues with setting up Relay and I really didn't want to eject. |
As mentioned above, Relay itself is changing significantly (Relay Classic => Relay Modern), and now is not a very good time to invest into a solution like this. I don’t think it makes sense to reopen because the churn is still there. Happy to reopen in half a year or so, but another issue might work better at that point. |
Agree with @gaearon - let's reevaluate this once Relay Modern is officially open source. It would be great to either support Relay Modern officially within create-react-app, or to make it very easy for projects to build upon create-react-app (so that we could build a |
@gaearon @josephsavona Now that Relay Modern is out, would love to see Create React App add support without ejecting; looks like there is an open issue for this: #2001. |
@trevordmiller The idea of That said, it would be great to come up with some solution to make it easier for people using CRA to try out Relay Modern or any other framework that required an extra Babel plugin. @gaearon, do you have any thoughts on this? |
@josephsavona Thanks for your response. I understand and agree with the premise. But I'm wondering if a conditional feature could be added as has been done with yarn (when you have a yarn.lock it uses yarn instead of npm), flow (when you have a .flowconfig), Jest, etc. I've found great value in not ejecting so that I get all of the underlying I did try out Relay Modern and am enjoying it. Thanks for the great work. |
It's such a shame since I really want to try Relay Modern. Setting up Apollo in create-react-app was painless for me. |
Hi, is it possible to use
Relay
withcreate-react-app
without ejecting project and messing with webpack configuration?I get the following error in the console:
I was looking for solution and it seems to be problem with lack of Relay.QL transpiler in the Babel configuration. But all these projects were not created with
create-react-app
cli. From what I know it's not possible to mess with webpack configuration until I eject a project.The text was updated successfully, but these errors were encountered: