Disclaimer: I'm a contributor to Apollo [0], an alternative client to Relay.
This is a great initiative! I remember struggling to learn Relay, I love it though, used it in some toy apps and will use it in some upcoming projects that I have. However I have a few issues with Relay: the main one is that it overall discourages people from starting with GraphQL. From creating a Relay-compliant GraphQL server to adding it to your app, Relay forces you to good conventions that, unfortunately, requires you to learn about its concepts and makes it super difficult to ramp up fast.
For anyone interested in working with Relay and GraphQL in general, I would advise you to start first with just learning GraphQL, without Relay and its constraints. You'll see that much of the issues you may have with GraphQL may come from actually trying to comply to Relay. Once you are okay with GraphQL, then, you can move to learning Relay.
Finally, I want to insist on the fact that GraphQL is just a specified language that can be consumed by any client you need/want. Relay is made by Facebook, for Facebook, which is a cool thing but may be a bit too much for your simple app or may not be adapted if you are migrating a legacy app to GraphQL (which was my case). That's why you should take a look to alternative clients as well (Apollo [0] for instance ;-) )!
Thanks Robin! I've love what you guys are doing at Apollo! I've just answered a similar question below, so I'll just copy the most important bits here as well:
One important thing to note here, is that Relay and Apollo are taking different approaches. Relay provides a great framework which works excellent for a lot of use cases and provides the most convenient and robust solution for that. In some cases you want to "break out" of that framework and be more in control how data is fetched or mutated. In that case Apollo is a fantastic choice as well. Especially in combination with Redux.
Fun fact: We're actually using both - Relay AND Apollo - in our dashboard at Graphcool. Feel free to take a look at the source here: https://github.com/graphcool/dashboard
On a side note: We're already working on a similar project but focussed on Apollo. If you're interested in getting involved, we're still looking for collaborators: https://github.com/learnapollo
We found it to be very difficult to get started with Relay. At Graphcool we are building the dashboard, a core component of our product with Relay, so we had to become experts. Now we have turned this into (what we hope to be) a compelling getting started tutorial.
We would love to get some feedback, and if you have any questions about Relay or GraphQL in general I'm happy to answer. :)
Looks like a really well made introduction. I have been considering Relay for a while now. Will try it out.
I especially like that I get a real GraphQL server to play around with. Thanks!
Thanks Jungberg!
One of the most common hurdles for frontend developers getting started with Relay (or GraphQL in general) is that you need to build a GraphQL backend first before you can do your first query and start building. That's why we've tried to make this as easy as possible by including a GraphQL server directly into the guide.
Have you also seen the integrated GraphiQL and data browser?
I'll read this when I get the chance. Perhaps I'll give Relay another chance.
I also found Relay a nightmare to understand. Everything is overcomplicated and messy, which is probably why they're talking about Relay 2.0 already. I was a bit frustrated when I found that this blog post was the most helpful piece of information I could find on Relay, and it tells you to just use FIELDS_CHANGE everywhere and ignore the rest of the mutation config features: http://blog.pathgather.com/blog/a-beginners-guide-to-relay-m... .
Some things that make Relay frustrating:
* Pointless restrictions on what you're allowed to do at the "root" require you to do everything under a "viewer" subnode instead.
* Relay "Routers" are completely pointless and should be removed.
* Mutation configs are totally confusing, and they're tightly coupled to the server-side implementation of the mutation. We have a compile step where the client inspects the schema that was generated by the server. Why can't we generate the mutation configs as well? I know there's probably not enough declarative information readily available, but there should be.
* Relay mutations are only allowed to have one input field and one output field in the GraphQL definition. This is a pointless incompatibility between Relay and non-Relay GraphQL endpoints.
Falcor also exists, and is much simpler, though it has its upsides and downsides:
* You're not allowed to pass any arguments other than the standard from/to pagination arguments. Want to implement faceted search? Too bad. It's "Not a querying language", for some reason.
* It has something called "calls" which are basically the same thing as Relay's mutations but you have a little less control over how cache invalidation is handled than you do with mutation configs. There's no RANGE_ADD, for example. To add/remove items in a list you have to invalidate the entire list. Maybe that's OK though? But it sure is annoying if you're trying to move an item from one list to another on the client side and don't need to wait for the server to catch up.
* No built-in support for optimistic updates yet.
One thing I see in common between React and Falcor is they are both rather complex ways to collaborate with yourself while ignoring events from the outside world. In other words, it's a lot of work to not have pubsub. I guess this is because pubsub doesn't scale? But in the mean time, I'm tempted to play around with Horizon instead.
Have you checked out Apollo Client? It's an alternative to Relay that works with all GraphQL servers and brings in a lot of the simplicity of Falcor: http://dev.apollodata.com/
It includes features like optimistic UI, easy ways to invalidate cache after mutations, arbitrary pagination models, and more.
Really good summary of some of the problems. There is a deeper issue which is that unless your developers understand React best practices really, really well Relay provides opportunities to screw up in a pretty big way. It goes against the 'developer experience' priorities that React was designed around. It's hard to understand and promotes some bad practices for complex applications e.g. binding domain concerns to each component rather than encouraging presentation components. Relay's constraints mean it's hard to control the way the application updates and responds to users. I'm not saying it can't be done but it requires way too much detailed knowledge of the quirks. From an agile perspective it also couples the front end and back end development too tightly.
We have since moved to Redux and are going to back out Relay from the application we used it in. With all of Redux's issues (ceremony, boilerplate, etc) it provides a standard model for us to reason about, and a decoupling of data retrieval from presentation.
All four points are valid criticism of Relay. Point 1 and 2 especially and the verbose structure of connections is why we decided to offer two endpoints to your project on graph.cool - one that supports all the relay conventions and one that feels much nicer to use.
We decided very early on to use Relay for our main frontend (a dashboard similar in complexity to Parse.) It's probably one of the largest open source projects using relay atm, so maybe having a look at that can be helpful https://github.com/graphcool/dashboard
In summary we have found that the benefits Relay offer makes up for the quirks and complexity Relay currently forces you to learn. Hopefully Learn Relay can help more people get up to speed faster.
Thanks for your feedback scottmf! We're mostly working with frontend developers and trying to simplify their workflows as much as possible. One of the first and most important steps are great learning resources. That's why we're focussing for now on frontend technologies such as Relay, Apollo, ...
We'd be more than happy to share some insights on what we've learned while building Graphcool. The best way going forward will be following our blog: https://blog.graph.cool/
[+] [-] robinricard|9 years ago|reply
This is a great initiative! I remember struggling to learn Relay, I love it though, used it in some toy apps and will use it in some upcoming projects that I have. However I have a few issues with Relay: the main one is that it overall discourages people from starting with GraphQL. From creating a Relay-compliant GraphQL server to adding it to your app, Relay forces you to good conventions that, unfortunately, requires you to learn about its concepts and makes it super difficult to ramp up fast.
For anyone interested in working with Relay and GraphQL in general, I would advise you to start first with just learning GraphQL, without Relay and its constraints. You'll see that much of the issues you may have with GraphQL may come from actually trying to comply to Relay. Once you are okay with GraphQL, then, you can move to learning Relay.
Finally, I want to insist on the fact that GraphQL is just a specified language that can be consumed by any client you need/want. Relay is made by Facebook, for Facebook, which is a cool thing but may be a bit too much for your simple app or may not be adapted if you are migrating a legacy app to GraphQL (which was my case). That's why you should take a look to alternative clients as well (Apollo [0] for instance ;-) )!
[0] http://dev.apollodata.com/
[+] [-] schickling|9 years ago|reply
One important thing to note here, is that Relay and Apollo are taking different approaches. Relay provides a great framework which works excellent for a lot of use cases and provides the most convenient and robust solution for that. In some cases you want to "break out" of that framework and be more in control how data is fetched or mutated. In that case Apollo is a fantastic choice as well. Especially in combination with Redux. Fun fact: We're actually using both - Relay AND Apollo - in our dashboard at Graphcool. Feel free to take a look at the source here: https://github.com/graphcool/dashboard
On a side note: We're already working on a similar project but focussed on Apollo. If you're interested in getting involved, we're still looking for collaborators: https://github.com/learnapollo
[+] [-] sorenbs|9 years ago|reply
We found it to be very difficult to get started with Relay. At Graphcool we are building the dashboard, a core component of our product with Relay, so we had to become experts. Now we have turned this into (what we hope to be) a compelling getting started tutorial.
We would love to get some feedback, and if you have any questions about Relay or GraphQL in general I'm happy to answer. :)
[+] [-] Jungberg|9 years ago|reply
[+] [-] morgante|9 years ago|reply
[0] http://dev.apollodata.com/react/
[+] [-] schickling|9 years ago|reply
Have you also seen the integrated GraphiQL and data browser?
[+] [-] welder|9 years ago|reply
https://youtu.be/EQcUmSEkr2Q?t=1m14s
[+] [-] tiglionabbit|9 years ago|reply
I also found Relay a nightmare to understand. Everything is overcomplicated and messy, which is probably why they're talking about Relay 2.0 already. I was a bit frustrated when I found that this blog post was the most helpful piece of information I could find on Relay, and it tells you to just use FIELDS_CHANGE everywhere and ignore the rest of the mutation config features: http://blog.pathgather.com/blog/a-beginners-guide-to-relay-m... .
Some things that make Relay frustrating:
* Pointless restrictions on what you're allowed to do at the "root" require you to do everything under a "viewer" subnode instead.
* Relay "Routers" are completely pointless and should be removed.
* Mutation configs are totally confusing, and they're tightly coupled to the server-side implementation of the mutation. We have a compile step where the client inspects the schema that was generated by the server. Why can't we generate the mutation configs as well? I know there's probably not enough declarative information readily available, but there should be.
* Relay mutations are only allowed to have one input field and one output field in the GraphQL definition. This is a pointless incompatibility between Relay and non-Relay GraphQL endpoints.
Falcor also exists, and is much simpler, though it has its upsides and downsides:
* You're not allowed to pass any arguments other than the standard from/to pagination arguments. Want to implement faceted search? Too bad. It's "Not a querying language", for some reason.
* It has something called "calls" which are basically the same thing as Relay's mutations but you have a little less control over how cache invalidation is handled than you do with mutation configs. There's no RANGE_ADD, for example. To add/remove items in a list you have to invalidate the entire list. Maybe that's OK though? But it sure is annoying if you're trying to move an item from one list to another on the client side and don't need to wait for the server to catch up.
* No built-in support for optimistic updates yet.
One thing I see in common between React and Falcor is they are both rather complex ways to collaborate with yourself while ignoring events from the outside world. In other words, it's a lot of work to not have pubsub. I guess this is because pubsub doesn't scale? But in the mean time, I'm tempted to play around with Horizon instead.
[+] [-] djmashko2|9 years ago|reply
It includes features like optimistic UI, easy ways to invalidate cache after mutations, arbitrary pagination models, and more.
(Disclaimer: I work on Apollo)
[+] [-] mamp|9 years ago|reply
We have since moved to Redux and are going to back out Relay from the application we used it in. With all of Redux's issues (ceremony, boilerplate, etc) it provides a standard model for us to reason about, and a decoupling of data retrieval from presentation.
[+] [-] sorenbs|9 years ago|reply
We decided very early on to use Relay for our main frontend (a dashboard similar in complexity to Parse.) It's probably one of the largest open source projects using relay atm, so maybe having a look at that can be helpful https://github.com/graphcool/dashboard
In summary we have found that the benefits Relay offer makes up for the quirks and complexity Relay currently forces you to learn. Hopefully Learn Relay can help more people get up to speed faster.
[+] [-] scottmf|9 years ago|reply
[+] [-] schickling|9 years ago|reply
We'd be more than happy to share some insights on what we've learned while building Graphcool. The best way going forward will be following our blog: https://blog.graph.cool/
Also, feel free to join our Slack in case you have any questions: https://slack.graph.cool/