> The need to do multiple round trips to fetch data required by a view: With GraphQL, you can always fetch all the initial data required by a view with a single round-trip to the server. I'm not sure what's different. You can actually implement the same with plain old http api's, also.
You can but you have to write all the allowed query combinations. Graphql is more flexible. It's also declarative, so you can provide a widget with the schema it needs. Another benefit of graphql is that is a "lingua franka", you can use it internally, between microservices, etc.
REST in Peace. Long Live GraphQL
41–50 of 94 posts
Re: REST in Peace. Long Live GraphQL
#42I know that it might be said in fun - and is an easy way to get clicks, but it feeds into the narrative of new, shiny tech. As the article points out at the end, there are very real engineering tradeoffs with GraphQL - and the answer isn't as easy as REST is dead, anachronistic technology that no engineer should consider (the XML analogy felt particularly inflammatory).
Kelly and I were chatting about GraphQL, and his post might be a more thoughtful engineering post: http://kellysutton.com/2017/01/02/do-we-need-graphql.html (the title - Do we need GraphQL? - is at least the way I'd expect engineers to approach the problem, where he discusses the tradeoffs)
In my MongoDB series, I point out a past case where Free Code Camp fed the hype, by telling engineers that the reason everyone had to learn the MEAN stack was due to employability in the software industry: https://medium.freecodecamp.org/the-real-reason-to-learn-the...
(you had to dig into the article to realize that their argument was more nuanced, and that they taught SQL first before MongoDB)
A number of "engineering" posts are not written as a thoughtful engineer might, and are in many ways marketing for the products sold (like a training program or code camp).
Re: REST in Peace. Long Live GraphQL
#43GraphQL only solves half the problem, how do you update resources with GraphQL?
Re: REST in Peace. Long Live GraphQL
#44How do people solve performance problems with GraphQL? I can imagine that it can be quite slow internally with multiple joins/subqueries in the datastore.
My take on it https://subzero.cloud (GraphQL and REST api for your database), built on top of https://postgrest.com
Re: REST in Peace. Long Live GraphQL
#45> The need to do multiple round trips to fetch data required by a view: With GraphQL, you can always fetch all the initial data required by a view with a single round-trip to the server. I'm not sure what's different. You can actually implement the same with plain old http api's, also.
Right but then you have to build a custom http api for each and every new view. Oh, and now you altered the view a tiny bit and need some more fields? Add yet another api. Oh, you did a redesign and you only need a tiny bit of data now? Either add another api again, or deal with the fact that you're wasting bandwidth by sending a bunch of unnecessary data.
Re: REST in Peace. Long Live GraphQL
#46GraphQL only solves half the problem, how do you update resources with GraphQL?
mutation {
createUser(u: "user", p: "pass") {
u,
p
}
}Re: REST in Peace. Long Live GraphQL
#47I tried to build a GraphQL server, but found it impractical since I didn't want to use Relay or Apollo on the front end. Formatting the query strings just made a mess and was a lot of trouble considering the simple resources I needed. Dealing with authentication and authorization looked like it was going to be a headache as well. I ended up going back to REST. Should I give it another look? Was I too quick to dismiss…
Not sure if you're not going to use it with Apollo/Relay. These clients help you format queries in JS with Babel transforms. These transforms also are what help couple your front end to your back end by validating queries at front end compile time webpack bundling), which is a huge element of the charm imo.
Re: REST in Peace. Long Live GraphQL
#48In my experience, versioning a RESTful API is not hard (much has been written about the various approaches). The cases when versioning does get hard usually correspond to major system architecture changes (e.g., restructuring fundamental relationships between data models), and in those cases, I suspect GraphQL wouldn't help a whole lot. You may still need to build some kind of compatibility layer to support older versions.
Other than that, adding new fields (which account for 90%+ of the changes to APIs I work on) are just as easy to add to RESTful endpoints. If payload size really does become an issue (it's usually negligible), it's easy enough to add a parameter or two to control the extent of the response data.
As for reducing round trips, I do see the advantage of using GraphQL, though to be fair, well-designed RESTful APIs can avoid excessive round trips as well - they just require a bit more coordination between client and server development (which is a good thing!). RESTful APIs also have the advantage of mutation payloads that look like their corresponding response representations.
To address some of the potential concerns with GraphQL (such as resource exhaustion), I believe it would require more development time/resources for most of the projects I've worked on - even after factoring in any technical debt brought on by RESTful API limitations.
Re: REST in Peace. Long Live GraphQL
#49GraphQL only solves half the problem, how do you update resources with GraphQL?