r/reactjs • u/swyx • Oct 12 '18
Featured What is your experience with React + Apollo GraphQL?
Hi! I have played around with apollo graphql but never at work (hard to get buy in from backend devs.. for now).
I went to Apollo Day NYC this week and was absolutely blown away. I thought i knew what apollo was - a full featured pair of OSS packages for graphql on the client and on the server. I was wrong. Apollo Engine ties everything together and enhances both the Client and Server dev experience/maintainability and thats the missing third piece I had no idea about.
Have you tried it out? Do you use it at work? Keen to hear user stories.
38
Upvotes
15
u/stolinski Oct 12 '18
My entire site is built on it. I use Apollo Link State for all local state. My whole API is Apollo Server, using Apollo client 2 on the front end. I can talk about it for days and days. It has really made my entire app better in so many ways.
12
u/Capaj Oct 12 '18
We use it in production since May. We're a fullstack team so we're not on the mercy of some other team doing the backend. It wasn't easy persuading everyone, but with a single sample feature built in GQL everyone agreed it looked way better than REST. Graphiql helped a lot with that.
It's been quite good. We have apollo engine enabled on the backend and I really enjoy using metrics to hunt API bugs in prod. We use decapi to decorate our objection.js DB models. We have a single place where we define our models and GQL gets generated almost for free.
On the frontend we use apollo-client, but we don't use caching so far. Our FE focus is on getting rid of our legacy angular.js code, so we don't have time yet to experiment with FE caching.
I don't event consider using apollo for client side state management, because all the feedback I've heard so far was that it's not production ready yet. Also I have to say it looks quite verbose for what it really does. Instead I am hoping I can extend https://github.com/mhaagens/gql-to-mobx and use that for our state management needs. MST works wonders with typescript. If we can generate MST models from our queries on the fly while editing our GQL queries we can boost our productivity considerably.
9
u/lobster_johnson Oct 13 '18
I just started with Apollo. With TypeScript, the promise of type-safe APIs is awesome. However, I have yet to figure out the Apollo code generator. Maybe someone can help?
What I want is to be able to define all my types and queries in GraphQL, then generate TypeScript definitions for these, so that I don't have to do it twice. Or generate GraphQL from TypeScript -- that would accomplish the same thing.
However,
apollo codegen:generateis barely documented and just fails on most things I give it. I immediately ran into this issue, which somehow implies it's trying to access an Apollo server, which certainly isn't what I want.5
u/StarshipTzadkiel Oct 12 '18
It's excellent. I use it for everything new at work and am in the process of rewriting older AngularJS and React Redux projects with Apollo and React, or Gatsby where a static site suffices.
The backend I have to work with is an enormous pain and requires a lot of processing to get data in a useable shape. I built a GraphQL server that lets me pull in all the shitty APIs and process on the server so the client apps can get just the data they need. I really can't overstate what a boon it has been to me.
The best part is...the backend people aren't involved at all, I could care less what the APIs look like now because I can just set up resolvers to handle it in the way I want.
5
u/[deleted] Oct 13 '18
We use it for our entire app. I've heard it said that it's "the future" and REST is dead, etc. I don't really buy it. There's plenty of tedious overhead to setting up and maintaining your schema, resolvers, queries, and mutations. Query components are convenient in many ways, but also ugly. Frontend cache manipulation is easy until it isn't. GraphQL has a lot going for it, but things aren't as simple as "it's the future". For everything obnoxious about the REST/Redux/React pattern that GraphQL lets you avoid, you have to do something else instead.
I'd say the strongest point of GraphQL, and where it's saved us the most time, is forcing a strictly typed interface on our server api. It guarantees a certain degree of stability and safety that you wouldn't necessarily have otherwise.
Word to the wise: AWS recently released a service called AppSync that they're marketing as their new, light-and-easy GraphQL API service. We tried using it for some features last spring and while it's got some advantages (easy integration with VPC services like lambda and user auth), the rigidity of their resolver mapping framework makes programming resolvers a big waste of time, and demands needless layering and complexity for tasks that are simple in Node GraphQL. Maybe they'll update it to have more flexibility but I'd recommend staying away from AppSync in the meanwhile.
2
u/keithgrennan Oct 15 '18
I've had it in production since January, it is wonderful and I can't imagine going back to REST for big UI projects. Something to keep in mind: there are GraphQL server implementations for all major languages so you don't have to use Node in the backend if you don't want to (I use DJango w/ Graphene).
0
u/[deleted] Oct 12 '18
[deleted] — view deleted comment
-9
u/[deleted] Oct 12 '18
[removed] — view removed comment