News for hackers. Stuff that matters.
Re:New React docs pretend SPAs don't exist anymore by claytongulick on Monday March 20, 2023 @04:27PM (#35238151)
> is it just "we don't like GraphQL" or something?

Yes.

But not without reason.

GraphQL departs from web standards and semantics in order to solve a problem that doesn't really exist in most APIs.

You incur a cost in using it, some of which I've outlined but there are many others, such as working against the browser's native caching capabilities, e-tags, etc...

This cost would be worth paying if GraphQL brought new and valuable capabilities, but as I've discussed, it doesn't really do that.

With REST endpoints, you have to really reason about entities and URL structure to design it properly. It's not easy, but it shouldn't be - it's meant to be a long-lived API contract based on document location, so you should spend time reasoning about the design.

GraphQL, in my experience (much like SOAP/WSDL) encourages lazy API development with the GetWidgetsByColorForArthurOnSunday() type functions. It requires additional libraries and tooling and a whole additional layer of complexity. It works against long-standing native browser functionality, and in many cases is just a solution in search of a problem since for most popular API consumption there's a client-side library that abstracts away details like transport.

Also, I personally dislike it because I can't use my preferred data mutation strategy, JSON-PATCH [1].

[1] https://jsonpatch.com/

Re:New React docs pretend SPAs don't exist anymore by eurasiantiger on Tuesday March 21, 2023 @02:59AM (#35243248)
GraphQL enables entity-level caching. That is not possible in REST.
Re:New React docs pretend SPAs don't exist anymore by roflyear on Thursday March 23, 2023 @02:30PM (#35279220)
Oh, totally agree the best cases for GraphQL are like 10% or so of the usecases for APIs. I don't think you should use it everywhere.

I also think GraphQL should never be used for updating data, just that it is nice for a segment of problems related to querying data.