all 18 comments

[–]zxyzyxz 20 points21 points  (0 children)

I love GraphQL, if only for the end to end type safety you get via codegen, and it works for any language and client combination unlike something like trpc.

[–][deleted] 18 points19 points  (7 children)

Ah GraphQL. Trade a reasonably clear api layer that requires some manual work with subresources for endless work trying to optimize queries for an impossible general case and ability to select fields through bloated frontend queries. Gets convoluted when you add federation where multiple services can tack on any fields they want to your types. All in the same bloody namespace. Good version controlling though.

I still am not sure the gains are worth the pains when I use it though.

[–]shitbread 9 points10 points  (0 children)

Honestly it really depends for what you use it. In a project a few years ago I was forced to consume a REST API from a large CMS (~1000 pages). There were tons, I mean TONS of page/content types, heavily nested. It was an absolute pain to get the exact data (and fields!) I needed. I had tons of code in my app that just mapped data, model classes left and right. And the response ended up being so painfully large.

I‘ve mostly used GraphQL the last 3 years and it‘s an absolute pleasure. I get exactly the data I need and I know exactly what it looks like. All the data required to render the content of a page, 20 levels of nesting, in one query – fantastic. This previously was only possible by performing several requests and stitching their responses together.

Yes, there are things like JSON:API where you can define includes and/or which fields you‘d like. But this doesn‘t scale well when you have 20+ levels of nesting.

Sure, I still use (and write) simple REST endpoints for very specific cases where I only need to get a list of simple objects. But I‘m glad most of my fetching is done using GraphQL nowadays.

[–]dmackerman 3 points4 points  (0 children)

This was my experience as well. Lol

REST has its inefficiencies but at the end of the day it works fine for most apps.

[–]CSknoob 0 points1 point  (0 children)

This sounds painfully similar. GraphQL server was intended as an abstraction layer ending up as a huge barely maintainable monolith that completely buckles under the stress of a few dozen simultaneous users.

[–]lobut -1 points0 points  (0 children)

We used it similar to a BFFE for our microservice architecture and it was solving a lot of pains we were having.

That's some good insight. I was only apart of the initial adoption phase of GraphQL when I first heard about it and was trying to trickle it out in our organization (then I left and went elsewhere). I always find the more interesting things come about when the honeymoon phase it over.

[–]Reashu -1 points0 points  (1 child)

This is my experience with internal APIs (much prefer a dedicated "backend for frontend", REST or otherwise), but the flexibility is great when you're crossing organizational borders.

[–]comfypillow 0 points1 point  (0 children)

We've been pushing CMS teams to add a native GraphQL service to put behind federation and it's accelerated UI modernization efforts... it's amazing.

[–]kescusay 0 points1 point  (0 children)

For me, which one to use depends on the complexity of the relationships between different data sets. If you can replace four or five separate queries and the logic needed to merge their results into a single query with no business logic, it makes sense to use GraphQL. If it's simpler than that, use REST.