News for hackers. Stuff that matters.
Re:GraphQL is quickly moving to one of my least favorite tec... by obi1kenobi on Friday July 29, 2022 @12:06PM (#32278672)
There's an interesting tension here. On one hand, GraphQL is versatile and can simplify frontend data handling code. On the other, as schema and data sizes grow, query expressiveness is limited and performance can be quite difficult to maintain.

I've put GraphQL in front of TB-scale data sources with X00,000 tables, and it was clear that (a) GraphQL wasn't designed for anything that big, and (b) if we could get it there, it would be transformational.

This is why I built Trustfall[0]: a system that keeps the elegant GraphQL syntax, and tweaks the semantics to ensure great performance and better expressiveness: left joins / recursion / aggregations / arbitrary filters etc. Trustfall flips the proposition around: acknowledge we're wrapping a database around every data source (API server / database / filesystem / ML etc.) and make it the best possible database it could be.

I gave a talk on it titled "How to Query (Almost) Everything" at the HYTRADBOI'22 conference: https://www.hytradboi.com/2022/how-to-query-almost-everythin...

I also recently used it to build cargo-semver-checks[1], a semver linter for Rust crates where each semver rule is implemented as a query using Trustfall's GraphQL + custom directives syntax.

[0]: https://github.com/obi1kenobi/trustfall

[1]: https://crates.io/crates/cargo-semver-checks

Re:GraphQL is quickly moving to one of my least favorite tec... by nerdyadventurer on Sunday July 31, 2022 @03:34AM (#32293934)
Cannot performance be improved by using something like Hasura that transform GQL to efficient SQL?
Re:GraphQL is quickly moving to one of my least favorite tec... by ralusek on Friday July 29, 2022 @11:24AM (#32278149)
Since I first used GraphQL, my opinion has been: I like it for admin applications where the client can safely be trusted to tell me exactly what they want, and as long as I authenticate them, they can have it. For everything else, it's more of a headache than it's worth, and I'd take REST any day.
Re:GraphQL is quickly moving to one of my least favorite tec... by manv1 on Friday July 29, 2022 @01:58PM (#32279986)
Graphql slows you down and enforces types. Both can be good or bad.

I suspect that front-end people like it because it requires less thinking on their part. A GraphQL call can replace a bunch of REST calls, and they don't have to deal with error handling and networking which in the front-end can be really difficult. Pushing that to the back-end makes their lives easier.

I've found that on the back-end GraphQL is more work than REST, because there's a bunch of extra crap you have to do to essentially do the same thing as REST.

And there's a bunch of stuff that's deliberately undefined, like "what do you do if there's a partial failure of your calls?"

Re:GraphQL is quickly moving to one of my least favorite tec... by eurasiantiger on Friday July 29, 2022 @03:44PM (#32281011)
At the risk of sounding like an evangelist: if it’s slowing you down, you may be doing it wrong.

If you are hand-crafting interdependent query logic to resolve GraphQL queries from multiple sources and doing that at scale, you may want to look at db adapters and the federation pattern.

Also, GraphQL absolutely still requires error handling in the frontend, and many clients actually provide great facilities for error handling: retrying failed requests, refreshing auth tokens transparently on received auth errors, network state detection, offline functionalities, etc.

Re:GraphQL is quickly moving to one of my least favorite tec... by sudowing on Friday July 29, 2022 @11:25AM (#32278157)
"... rough edges ... complex"

I've put a couple GraphQL services into production and have similar thoughts.

What suprised me most were the range of views from colleagues when they needed to integrate into one of their products. Some people were happy to work with something new, while others didn't appreciate the tax involved with the learning curve.

That said, I published an app that auto-provisions a CRUD service in GraphQL. So while I may not use it for most apps, I use this for general data-access.

https://github.com/sudowing/service-engine-template

Re:GraphQL is quickly moving to one of my least favorite tec... by eurasiantiger on Friday July 29, 2022 @11:28AM (#32278201)
Interesting that GraphQL consumers would see it as excessively taxing. Did you mention that GraphQL APIs can be queried with plain HTTP requests without any specific GraphQL client?
Re:GraphQL is quickly moving to one of my least favorite tec... by mdaniel on Friday July 29, 2022 @12:24PM (#32278923)
Isn't that only true if the consumer is fluent in GraphQL syntax?

  curl https://example.com/some/endpoint?someq=yup
versus

  curl -d '{"query":"query Q { someMethod(someArg: \"someValue\") { ...ohgawd } }"}' https://example.com/graphql
even typing that out I had to carefully count back the closing braces

And, from the JS PoV, similar burden of the "interior" language

  fetch("https://example.com/graphql", {method: "POST", body: "query Q { #and the rest }"})
Re:GraphQL is quickly moving to one of my least favorite tec... by eurasiantiger on Friday July 29, 2022 @12:55PM (#32279286)
True, a query is needed, but that is pretty straightforward and crucially, there are schema-aware editors that just plug in to the endpoint. Boom, autocomplete for fields and queries, and syntax validation out of the box. Indispensable piece of any GraphQL backend stack.

Besides, any sane developer will build an abstraction on top of the fetch request.

The difference to any other JSON reply is minimal.

Re:GraphQL is quickly moving to one of my least favorite tec... by sudowing on Friday July 29, 2022 @11:39AM (#32278338)
Indeed. Thats actually how my team's FE engineers called our API.

But once other teams started integrating -- we heard all kinds of feedback.

My thoughts afterward were simply that people under the time pressure to push features daily had different appetites for any friction in their workflow.

We considered the feedback from the larger team and intentionally added support for both REST & GraphQL in our next app. We wanted to support anyone that wanted some exposure to it without forcing anyone. And that had much better feedback from consumers.

Re:GraphQL is quickly moving to one of my least favorite tec... by jdmg94 on Friday July 29, 2022 @11:36AM (#32278309)
yes, everything happens over regular http(s) you can literally just 'fetch' a graphQL API
Re:GraphQL is quickly moving to one of my least favorite tec... by ishjoh on Friday July 29, 2022 @12:13PM (#32278761)
I've been using graphql on the FE and BE for about 2 years now, and used REST for about 10 years before that. I really like the apollo client when using React, it's a great fit and let's me avoid the mental complexity of data stores like Redux etc.

On the BE it's not great, harder to reason about than REST and harder to manage. It's also harder to monitor than traditional REST, since REST makes use of a full range of http header codes (the graphql server we used only used http header 200 by default, we have modified this).

What I recently learned is that the apollo client has support for REST APIs, this is a path that seems interesting to me. We've also been looking at FE libraries for REST that have similar interfaces to the apollo client, if you have suggestions please let me know.

Re:GraphQL is quickly moving to one of my least favorite tec... by soulchild77 on Saturday July 30, 2022 @02:17AM (#32284710)
We're happy users of react-query[1]. Its stale-while-revalidate approach makes Redux and Co. unneccessary for most use-cases.

If you have an OpenAPI spec of your REST API you can auto-generate a react-query based frontend client with Orval[2]. Works pretty well, but probably takes a bit more time to set up.

[1] https://tanstack.com/query/v4/ [2] https://orval.dev/

Re:GraphQL is quickly moving to one of my least favorite tec... by ishjoh on Monday August 01, 2022 @11:04AM (#32306980)
Thank you, react-query is one of the solutions we were looking into, glad to hear there are happy users of it.

One thing I like about the apollo client is that it handles a lot of the cache invalidation for you, where as react-query it seems to be a bit more of a manual process, how are you and your team handling cache invalidation?

Re:GraphQL is quickly moving to one of my least favorite tec... by soulchild77 on Tuesday August 02, 2022 @09:16AM (#32318089)
react-query indeed doesn't automatically take care of this. We manually invalidate its caches (based on the query key, so you only ever invalidate what has changed) after a mutation happens. It's not as bad as it sounds because most of the time it's just one line of code.
Re:GraphQL is quickly moving to one of my least favorite tec... by datalopers on Friday July 29, 2022 @01:54PM (#32279935)
GraphQL solves the rough edges of REST that didn’t exist in RPC. Just go back to RPC. Still works great, and now we have modern frameworks like gRPC that make it a joy to use.
Re:GraphQL is quickly moving to one of my least favorite tec... by xpe on Friday July 29, 2022 @02:27PM (#32280257)
I find this to be an odd and not useful characterization.

Also, the idea that we can just 'go back' is silly.

> GraphQL solves the rough edges of REST that didn’t exist in RPC. Just go back to RPC. Still works great, and now we have modern frameworks like gRPC that make it a joy to use.

Re:GraphQL is quickly moving to one of my least favorite tec... by freenatec on Friday July 29, 2022 @02:19PM (#32280173)
I’ve found code generation tools extremely helpful for large-ish graphql backends and resolve many of the ‘complexity’ issues if employed correctly.

Of course, code generation has its own particular set of gotchas and problems (for example, you really don’t want to expose the full functionality of, say, the Prisma api to the world)

Re:GraphQL is quickly moving to one of my least favorite tec... by kwerk on Friday July 29, 2022 @12:28PM (#32278969)
Does Redwoodjs’ architecture solve most of this? Seems like most of the challenges are about over trusting the client and Redwood has some patterns to separate. I’ve got close to zero xp with Graphql and redwood fwiw
Re:GraphQL is quickly moving to one of my least favorite tec... by akmittal on Friday July 29, 2022 @01:06PM (#32279413)
Graphql is great when you are in node/react world. Other language support is not that great. Every language need apollo-server, Apollo-client like library
Re:GraphQL is quickly moving to one of my least favorite tec... by gavinray on Friday July 29, 2022 @02:23PM (#32280222)
There are some very solid libraries in most languages. I'm not a .NET dev, but I think that HotChocolate takes the cake.

Here's a non-exhaustive list:

- Kotlin: Netflix's "DGS" (https://github.com/Netflix/dgs-framework)

- Python: Strawberry (https://github.com/strawberry-graphql/strawberry)

- .NET: HotChocolate (https://github.com/ChilliCream/hotchocolate)

- Rust: async-graphql (https://github.com/async-graphql/async-graphql)

- Java: GraphQL-Java (https://github.com/graphql-java/graphql-java)

- Scala 2: Sangria (https://github.com/sangria-graphql/sangria)

- Scala 3: Caliban (https://github.com/ghostdogpr/caliban)

Re:GraphQL is quickly moving to one of my least favorite tec... by noworriesnate on Friday July 29, 2022 @01:17PM (#32279551)
The C# ecosystem has HotChocolate (server-side) and StrawberryShake (client-side). I've been using it for a year or so and it's been a pleasure to work with.
Re:GraphQL is quickly moving to one of my least favorite tec... by dbbk on Friday July 29, 2022 @02:04PM (#32280041)
I've actually been pleasantly surprised building a GraphQL API in PHP (which I just assumed would be a nightmare), Lighthouse is pretty strong for this.
Re:GraphQL is quickly moving to one of my least favorite tec... by cbdumas on Friday July 29, 2022 @12:25PM (#32278939)
IMO GraphQL shines when used more like an RPC framework. I've never found the "Graph" parts to be worth the complexity.
Re:GraphQL is quickly moving to one of my least favorite tec... by PainfullyNormal on Friday July 29, 2022 @01:51PM (#32279901)
What's the benefit of using GraphQL like an RPC framework over using REST like an RPC framework or using an actual RPC framework?
Re:GraphQL is quickly moving to one of my least favorite tec... by gavinray on Friday July 29, 2022 @02:26PM (#32280241)
Types and tooling

There's pitiful tooling for something like JSON-RPC and no equivalent of OpenAPI for it.

If you use gRPC, there's still less tooling than there is for GraphQL and the primary transport is Protobuf.

Being able to make JSON HTTP requests ("JSON-Transcoding") is a second-class citizen if even supported at all by your server library.

Re:GraphQL is quickly moving to one of my least favorite tec... by eurasiantiger on Friday July 29, 2022 @11:23AM (#32278131)
A lot of FUD around GraphQL these days.

Seems this particular twitterer made the mistake of trying to implement their own GraphQL server from the ground up. Never do that! There are ready-made servers with neat resolver patterns which allow you to respond to queries with well defined entities while fetching their fields from any source.

That said, never do that, either! There are ready-made GraphQL adapters available for pretty much any database, and there are some very promising ”GraphQL-native” databases out there too!

And then there is Prisma, which is a one-stop shop for all your app’s GraphQL needs, whatever the database.

Re:GraphQL is quickly moving to one of my least favorite tec... by justanorherhack on Friday July 29, 2022 @12:51PM (#32279241)
The ready made servers often don’t handle authorization well or at all. Prisma is just an orm. This reads like somebody who hasn’t built a lot of prod stuff.
Re:GraphQL is quickly moving to one of my least favorite tec... by eurasiantiger on Friday July 29, 2022 @03:15PM (#32280726)
As someone who has indeed built production GraphQL backends, creating your own @auth directive visitor is not that difficult of a task. :)
Re:GraphQL is quickly moving to one of my least favorite tec... by asplake on Friday July 29, 2022 @12:26PM (#32278941)
I don’t know, but maybe that particular twitterer – Armin Ronacher no less – had his reasons for trying?
Re:GraphQL is quickly moving to one of my least favorite tec... by eurasiantiger on Friday July 29, 2022 @03:23PM (#32280811)
I don’t doubt that at all! However, I do not consider domain experts authority figures, however omniscient or infallible they may present. On the contrary, given how easily expertise distorts perception of knowledge, I find it prudent to avoid putting expert opinions on a pedestal, and to provide complementary views where possible.
Re:GraphQL is quickly moving to one of my least favorite tec... by UncleEntity on Friday July 29, 2022 @12:54PM (#32279270)
How many ready-made servers are there that aren’t in JavaScript?

I’ve looked a couple times and didn’t find anything.

Re:GraphQL is quickly moving to one of my least favorite tec... by mdaniel on Friday July 29, 2022 @01:10PM (#32279459)
I guess that depends on one's definition of "ready-made"

DGS isn't a terrible place to start, if you're already in the Spring ecosystem https://github.com/Netflix/dgs-framework#readme

There's an "awesome" list in the graphql-java org, too: https://github.com/graphql-java/awesome-graphql-java#readme

Re:GraphQL is quickly moving to one of my least favorite tec... by eurasiantiger on Friday July 29, 2022 @03:29PM (#32280864)
Here’s a list neatly curated for compatibility with Apollo Federation, so you can be sure that your API is composable:

https://www.apollographql.com/docs/federation/supported-subg...

Re:GraphQL is quickly moving to one of my least favorite tec... by brap on Friday July 29, 2022 @12:23PM (#32278907)
Isn't Prisma just a SQL ORM that you use on the server?
Re:GraphQL is quickly moving to one of my least favorite tec... by the_mitsuhiko on Friday July 29, 2022 @01:19PM (#32279573)
Prisma is also an interesting case as it used to be queried via GraphQL but now they use their own query language. It’s still quite useful to build GraphQL based APIs though.