Live data from Hacker News

GraphQL: The enterprise honeymoon is over

johnjames.blog

231–240 of 241 posts

Re: GraphQL: The enterprise honeymoon is over

#231

Earlier quoted context omitted.

You're misunderstanding. In GraphQL, the server prunes the response object. That is, the resolver method can return a "fat" object, but only the object pruned down to just the requested fields is returned over the wire. It is an important security benefit, because one common attack vector is to see if you can trick a server method into returning additional privileged data (like detailed error responses).

"Just the requested fields" as requested by the client? Because if so that is no security benefit at all, because I can just... request the fat fields.

I'll explain again, because this is not what I'm saying.

In many REST frameworks, while you define the return object type that is sent back over the wire, by default, if the actual object you return has additional fields on it (even if they are found nowhere in the return type spec), those fields will still get serialized back to the client. A common attack vector is to try to get an API endpoint to return an object with, for example, extra error data, which can be very helpful to the attacker (e.g. things like stack traces). I'd have to search for them, but some major breaches occurred this way. Yes, many REST frameworks allow you to specify things like validators (the original comment mentioned zod), but these validators are usually optional and not always directly tied to the tools used to define the return type schema in the first place.

So with GraphQL, I'm not talking about access controls on GraphQL-defined fields - that's another topic. But I'm saying that if your resolver method (accidentally or not) returns an object that either doesn't conform to the return type schema, or it has extra fields not defined in the schema (which is not uncommon), GraphQL guarantees those values won't be returned to the client.

Re: GraphQL: The enterprise honeymoon is over

#232
post #192

Earlier quoted context omitted.

> GraphQL is far better than REST in almost every way I hear this so often, but never do I hear more than one or one and a half ways that it is better. No one seems capable of explaining how it's "better in almost every way" without diverging to very specific examples with cutout problems.

You may be interested in checking out https://www.youtube.com/watch?v=lhVGdErZuN4 , where I talk about the benefits of Relay. This isn't (currently) possible without GraphQL, so it's a pretty compelling case for GraphQL. But yeah, IMO, GraphQL doesn't justify itself unless you're using a client like Relay, with data masking and fragment colocation.

That is an interesting talk, thank you!

Re: GraphQL: The enterprise honeymoon is over

#233

Earlier quoted context omitted.

If you generate TypeScript types from OpenAPI specs then you get contracts for both directions. There is no problem here for GraphQL to solve.

This is very much possible, and I have done it, and it works great once it's all wired up. But OpenAPI is verbose to the point of absurdity. You can't feasibly write it by hand. So you can't do schema first development. You need an open API compatible lib for authoring your API, you need some tooling to generate the schema from the code, then you need another tool to generate types from the schema. Each step tends to…

Agree with the other comments about writing OpenAPI by hand. It’s really not that bad at all, and most certainly not “verbose to the point of absurdity.”

Moreover, system boundaries are the best places to invest in being explicit. OpenAPI specs really don’t have that much overhead (especially if you make use of YAML anchors), and are (usually) suitably descriptive to describe the boundary.

In any case, starting with a declarative contract/IDL and doing something like codegen is a great way to go.

Re: GraphQL: The enterprise honeymoon is over

#234

> The main problem GraphQL tries to solve is overfetching. My issue with this article is that, as someone who is a GraphQL fan, that is far from what I see as its primary benefit, and so the rest of the article feels like a strawman to me. TBH I see the biggest benefits of GraphQL are that it (a) forces a much tighter contract around endpoint and object definition with its type system, and (b) schema evolution is muc…

But if you just want a nicely typed interface for your APIs, in my experience gRPC is much more useful, because of all of the other downsides the blog author mentioned.

Re: GraphQL: The enterprise honeymoon is over

#235

I'm probably about as qualified to talk about GraphQL as anyone on the internet: I started using it in late 2016, back when Apollo was just an alternate client-side state/store library. The internet at large seems to have a fundamental misunderstanding about what GraphQL is/is not. Put simply: GQL is an RPC spec that is essentially implemented as a Dict/Key-Value Map on the server, of the form: "Action(Args) -> Resul…

This is a great explanation of what the intent of GQL is. I'm curious though, as someone who has only a small amount of experience with it, what problem is that solving? From what I can tell, it's the same problem REST solves with a different interface. If it is the over-fetching problem, how big is that problem?

In my experience, it's better to fix a bad endpoint and keep all the browser/server side tooling around tracing requests than to replace all that with a singular graphql endpoint. But curious to hear someone else's opinion here

Re: GraphQL: The enterprise honeymoon is over

#236

Earlier quoted context omitted.

If you generate TypeScript types from OpenAPI specs then you get contracts for both directions. There is no problem here for GraphQL to solve.

This is very much possible, and I have done it, and it works great once it's all wired up. But OpenAPI is verbose to the point of absurdity. You can't feasibly write it by hand. So you can't do schema first development. You need an open API compatible lib for authoring your API, you need some tooling to generate the schema from the code, then you need another tool to generate types from the schema. Each step tends to…

YAML OpenAPI schema, like SQL, is quite easy to write by hand and more importantly by AI. Telling AI to keep the openapi in sync with the latest changes made on an API works great and can even help you identify inconsistencies.

Re: GraphQL: The enterprise honeymoon is over

#237

Earlier quoted context omitted.

Local non-utility does not imply global non-value. Of course there's costs and benefits, but it's hard to have a conversation with good-faith comparison using "many see it as overly complex" -- this is an analysis that completely ignores problem-fit, which you then want to generalize onto all usage.

People can still draw generalizations about a piece of technology that hold true regardless context or problem fit One of those conclusions is that GraphQL is more complex than REST without commensurate ROI

Yeah, that’s a huge over-generalization

Re: GraphQL: The enterprise honeymoon is over

#238

Earlier quoted context omitted.

In my (now somewhat dated) graphql experience, evolving an API is much harder. Input parameters in particular. If a server gets inputs it doesn't recognize, or if client and server disagree that a field is optional or not (even if a value was still supplied for it so the question is moot), the server will reject the request.

> If a server gets inputs it doesn't recognize If you just slap in Zod, the server will drop the extra inputs. If you hate Zod, it's not hard to design a similar thing. > or if client and server disagree that a field is optional or not Doesn't GQL have the concept of required vs optional fields too? IIUC it's the same problem. You just have to be very diligent about this, not really a way around it. Protobufs went as…

> Doesn't GQL have the concept of required vs optional fields too?

Yea, graphql is what I'm referring to.

Re: GraphQL: The enterprise honeymoon is over

#239

The author is missing the #1 benefit of GraphQL: the ability to compose (the data for) your UI from smaller parts. This is not surprising: Apollo only recently added support for data masking and fragment colocation, but it has been a feature of Relay for eternity. See https://www.youtube.com/watch?v=lhVGdErZuN4 for the benefits of this approach: - you can make changes to subcomponents without worrying about affecting…

Reminds me a lot of Grafast too, a new stab at this the people that made postgraphile had. I liked using graphile, haven't needed to rewrite or start a new project yet for grafast. * https://grafast.org/

Re: GraphQL: The enterprise honeymoon is over

#240

Earlier quoted context omitted.

I have that with URQL+gql.tada. What else does relay give me that URQL does not?

I may be wrong on the details, but with URQL: - you don't have a normalized cache. You may not want one! But if you find yourself annoyed that modifying one entity in one location doesn't automatically cause another view into that same entity to update, it's due to a lack of a normalized cache. And this is a more frequent problem than folks admit. You might go from a detail view to an edit view, modify a few things,…

URQL has normalized caching and it works great! You opt into it by adopting their graphcache exchange.

https://nearform.com/open-source/urql/docs/graphcache/

It also works great with fragments.

And its exchange system is super powerful and flexible. I’ve even seen an offline-first sync engine built as a custom URQL exchange in a react native app. The frontend could be written as if the app always is online but it would handle offline capabilities within the exchange.

Post reply on HN