Live data from Hacker News

Is GraphQL the Next Frontier for Web APIs?

brandur.org

41–50 of 74 posts

Re: Is GraphQL the Next Frontier for Web APIs?

#41
"Roy Fielding’s original ideas around REST are elegant and now quite widespread"

I don't think this is actually true. I think you see some ideas plucked from Fielding's paper, but describing REST in terms of performing CRUD on resources is not what Fielding's paper is largely about. There's some good RESTful APIs out there, and Stripe does have a pretty nice API for the current state of API affairs. But I'd say we're still decently early in figuring out how to more widely leverage concepts from Fielding's paper, so declaring that REST isn't fulfilling needs seems a little short to me. I'd rather see what happens if more people commit to understanding & implementing other beneficial concepts in their APIs.

"REST also has other problems. Resource payloads can be quite large because they return everything instead of just what you need, and in many cases they don’t map well to the kind of information that clients actually want, forcing expensive N + 1 query situations."

So maybe the idea here is that it's harder to implement, but you can absolutely structure REST APIs to have these same benefits, and actually you may find it to offer benefits over graphql here. There is nothing un-REST-like about returning different message formats based on the client sending you a specified request header, or providing a url parameter, or what have you. You can actually leverage this to you (& your API client's benefit) by providing a small subset of different response "shapes", or you could just allow them to specify exactly what they need for a request in a free-for-all sort of fashion. It's all up to you, but I can't buy this argument for GraphQL, it's a symptom of writing inflexible REST-ish APIs, not a damning fact of REST as a concept.

Re: Is GraphQL the Next Frontier for Web APIs?

#42

I can see three contenders: 1. CRDTs/sync solutions (like Firebase) 2. GraphQL with real-time subscriptions 3. A variant of REST over WebSockets with real-time subscriptions I don't think #1 will be able to cover all necessary use cases because it is much more computationally expensive (in terms of memory, CPU and bandwidth). Both #2 and #3 are good solutions but I think #3 will prevail in the end because it's a lot…

This list is very interesting!

Which one performs the best in:

• Raw Performance

• Proven Architecture

• Robustness & Congestion Tolerance

• Backward & forward compatibility

• Customizability

Is ASN.1 by Fabrice Bellard the fastest serialization format? http://bellard.org/ffasn1/

Here's a lits of all formats: https://en.wikipedia.org/wiki/Comparison_of_data_serializati...

Re: Is GraphQL the Next Frontier for Web APIs?

#43
post #28
post #3

It's probably not super popular to suggest that REST isn't the be-all and end-all when it comes to web APIs, but I'm interested in a future that lets us integrate with APIs more quickly and more safely. I'm interested to hear about what people think about the subject. (I'm the author.)

Thinking about the problems with client-side SQL seems informative[0]: * Security; allowing evaluation rather than a describing results. * DDL; Data Structure and Types need to be learned out-of-band. Ideally we want a sort-of interactive INFORMATION_SCHEMA over http, so our tools can inform us about types/structure and we always have updated info as we write queries. * Performance; Stored Procedures (server-side) pr…

So I think it's a bit of a misconception that GraphQL is going to essentially map to SQL in the backend. Essentially, it's up to the service provider to decide what query paths and mutations are available in GraphQL, and design their schema accordingly.

So for example, if you allowed "comments" to be queried within a "user", you'd make sure that users could be looked up efficiently by their ID, and that comments could be loaded in bulk efficiently based on user ID. You'd also make sure that your implementation for both those operations is secure.

It's not too dissimilar to REST in that you're still very much designing what your API should look like and not exposing anything else.

Re: Is GraphQL the Next Frontier for Web APIs?

#44
post #3

It's probably not super popular to suggest that REST isn't the be-all and end-all when it comes to web APIs, but I'm interested in a future that lets us integrate with APIs more quickly and more safely. I'm interested to hear about what people think about the subject. (I'm the author.)

I'm a big fan of postgrest ( https://github.com/begriffs/postgrest/ ). It creates a RESTful HTTP API out of your existing postgres schema. It practically eliminates the need to write a CRUD backend.

Yes, PostgREST is awesome :)

It turns out that most of what is usually expressed in implementation code assuming that you're hitting a dumb backend is just as well-served by SQL functions and schemas. This probably breaks down for larger projects, but it certainly has its place, and I can imagine something very similar be done for GraphQL.

Re: Is GraphQL the Next Frontier for Web APIs?

#45
GraphQL was not meant to be a replacement for REST. It doesn't seem to right to compare an architectural concept to a query language.

The main power of GraphQL is for client developers and lies in the decoupling it provides between the client and server and the ability to fulfill the client needs in a single round trip. This is great for mobile devices with slower networks.

Introspection is a really powerful tool and you can build tools around that to do compile time checks and automatically generate class definitions based on your schema.

Re: Is GraphQL the Next Frontier for Web APIs?

#46
post #16

REST is horrible. It encourages new developers to think in terms of CRUD, which is also horrible. ( https://msdn.microsoft.com/en-us/library/ms978509.aspx ). RPC is great. It encourages developers to think in terms of functions and leverage more creative ways of getting things done. Event Sourcing, CQRS, etc. GraphQL is really neither here nor there. It's more of a convention on top of those layers. I think it's a go…

REST is horrible. It encourages new developers to think in terms of CRUD, which is also horrible. It encourages developers to think in terms of data , which is amazing. At the end of the day, we're just doing data transformations, that's it. GraphQL is an interesting iteration on that idea, because it focuses more on the data. REST is simply a way to design your APIs so that they're extensible, usable, and maintainab…

> At the end of the day, we're just doing data transformations, that's it

That's kind of the thing though. REST doesn't do transformations. It just does CRUD of resources.

For me, when designing an application, I will think, "is representational state transfer the only thing this application will ever need to do?" If the answer is "no" then REST seems like a poor model to build around. I've never answered "yes" to that question. (That said, I spent many years mindlessly building REST apps before I started asking myself that).

Per CQRS etc., that's right. It's a tool. Use it when appropriate. Don't use it when not. (That said, the scare factor of that article is a bit high--I've had very little trouble with it since switching to it as my go-to update pattern about five years ago. Also note Martin Fowler has changed his mind on several topics lately, such as the Rich vs Anemic domain model, away from OOP and toward a more FP viewpoint. CQRS is certainly the more FP model here.)

Re: Is GraphQL the Next Frontier for Web APIs?

#47
post #37
post #18

Earlier quoted context omitted.

I have a fairly dumb question. If one were building a standard web app... say, a super simple web store that lists products, allows someone to submit products and such. How would they use RPC instead of rest? Can you give some concrete examples of how it's different / better.

Users, for instance. If you think of users as a resource, then updating them is a PUT to /users/{id}. Fine, they can update their info. But you also need a way to change their password. That's a different entrypoint. Where does it go? /users/{id}/password? Is it a PUT or a POST? I mean, nothing here can't be worked around. Millions of sites do this just fine. But to me, the mental model just doesn't match up. The RES…

> If you think of users as a resource, then updating them is a PUT to /users/{id}. Fine, they can update their info.

That sounds a lot more like a user profile resource than a user resource.

> But you also need a way to change their password. That's a different entrypoint.

Or, if you have a user resource rather than separate profile I and password resources, all partial updates could go to the same resource as PATCHes.

> Where does it go?

If you spend a lot of time thinking about that, you probably aren't doing REST.

> Is it a PUT or a POST?

Is it a replacement or a new resource? Largely, that depends on your domain model, and models under which either answer (or PATCH) make sense. As long as the definitions of your resource representations tell what operations are supported, and what they mean, for endpoints represented by the relevant link relations, it really doesn't matter all that much.

> The REST model tries to present a facade that everything is a "resource". In my experience, as apps get bigger, more and more things start not quite fitting that model.

I can't imagine how anything could fail to fit the model, unless you assume (as REST does not) that resources must be completely independent so that an action on one resource has no effects on the state of other resources.

Re: Is GraphQL the Next Frontier for Web APIs?

#48
post #44

Earlier quoted context omitted.

I'm a big fan of postgrest ( https://github.com/begriffs/postgrest/ ). It creates a RESTful HTTP API out of your existing postgres schema. It practically eliminates the need to write a CRUD backend.

Yes, PostgREST is awesome :) It turns out that most of what is usually expressed in implementation code assuming that you're hitting a dumb backend is just as well-served by SQL functions and schemas. This probably breaks down for larger projects, but it certainly has its place, and I can imagine something very similar be done for GraphQL.

I don't think it breaks down (as long as most of the data comes form the database). For example i know exactly how paymoapp.com (similar to basecamp) is structured , i consider it to be a fairly large system and i know for a fact that PostgREST can support that. As for the "very similar be done for GraphQL", there is https://github.com/postgraphql/postgraphql which was based on postgrest ideas. Another approach would be to build graphql on top of postgrest (my comment below)

Re: Is GraphQL the Next Frontier for Web APIs?

#49

I can see three contenders: 1. CRDTs/sync solutions (like Firebase) 2. GraphQL with real-time subscriptions 3. A variant of REST over WebSockets with real-time subscriptions I don't think #1 will be able to cover all necessary use cases because it is much more computationally expensive (in terms of memory, CPU and bandwidth). Both #2 and #3 are good solutions but I think #3 will prevail in the end because it's a lot…

This list is very interesting! Which one performs the best in: • Raw Performance • Proven Architecture • Robustness & Congestion Tolerance • Backward & forward compatibility • Customizability Is ASN.1 by Fabrice Bellard the fastest serialization format? http://bellard.org/ffasn1/ Here's a lits of all formats: https://en.wikipedia.org/wiki/Comparison_of_data_serializati...

GraphQL and REST solutions will almost certainly be much faster than any CRDT solution. I think that the REST solution should be more efficient than the GraphQL solution but it probably won't be a drastic difference.

The essence of the REST philosophy is to deal with data as small atomic building blocks - I think that this is one of the most important and well-tested ideas in software engineering so on that basis, I would go with REST. Though you could also argue that the idea of querying (which is what GraphQL essentially is) is also well tested.

CRDTs are bad with bandwidth and they require very heavy/complex clients that are difficult to implement - Once implemented, they make life easier for many use cases but take away flexibility and customizability.

I think the main challenge with GraphQL actually might be doing access control on the back-end. If you have a GraphQL query that fetches many different resource types, it's a lot more difficult to establish whether or not a user is allowed to access all these resources at once (GraphQL approach) vs just a single resource at a time (REST Approach).

With GraphQL you may have to deal with partial access rights - where the user is only allowed to see part of the query's result. With REST, each request can only have a single allowed/blocked response.

Re: Is GraphQL the Next Frontier for Web APIs?

#50

Earlier quoted context omitted.

This list is very interesting! Which one performs the best in: • Raw Performance • Proven Architecture • Robustness & Congestion Tolerance • Backward & forward compatibility • Customizability Is ASN.1 by Fabrice Bellard the fastest serialization format? http://bellard.org/ffasn1/ Here's a lits of all formats: https://en.wikipedia.org/wiki/Comparison_of_data_serializati...

GraphQL and REST solutions will almost certainly be much faster than any CRDT solution. I think that the REST solution should be more efficient than the GraphQL solution but it probably won't be a drastic difference. The essence of the REST philosophy is to deal with data as small atomic building blocks - I think that this is one of the most important and well-tested ideas in software engineering so on that basis, I…

> The essence of the REST philosophy is to deal with data as small atomic building blocks

It's actually not; that seems to be something imposed after the fact by association of REST with a thin layer over a normalized DB model.

REST is neutral about both the size and atomicity of resources.

Post reply on HN