by aikah · 11y ago · 0 comments
To me it is another example of something that may benefit a project that has 500 million daily users , that is useless for 99% of projects out there, yet is advertised as a silver bullet that will make a poorly optimized app magically scale.
It is exactly what I'm saying. It's yet another layer on the server, it doesn't solve caching issues, and it will certainly not make your average app faster, especially when http2 support is here.
GraphQL is an ORM for rest apis. I thought rest apis were supposed to be universal, why need another layer on top of it? How many ORMs do developers need ? how much more complex does it have to get? The goal of REST is first and foremost readability and simplicity. The purpose of fat clients are to push complexity on the client. With graphQL simplicity is gone since everything is POST thus no http caching, and the server now gets another layer of complexity instead of being client agnostic.
Again, it might make sense at Facebook scale, but many articles promoting GraphQL are not talking about the fact that, it might not make sense for the majority of applications out there, even worse, it actually might make apps slower because of that extra layer.
No, GraphQL is a protocol that replaces REST.
Its closest analogue is the unholy beast that is SOAP + WSDL, except without the insanity of XML. With SOAP/WSDL you declare a schema for your API, which then accepts API calls containing parameters. SOAP/WSDL follows a classical RPC paradigm where you execute functions that take positional arguments.
GraphQL dispenses with that terminology, but is still very much RPCish. A key difference is that "arguments" are keyword-based. Where SOAP/WSDL would have you pass a "complex type" (ie., a struct) with optional fields, in GraphQL everything is built out of structs. Another key difference is that the output follows the structure of the input.
GraphQL remaps REST's paths to nested keys. For example, given the routes:
/books
/books/:id
/books/:id/authors
This becomes: query {
book(id: ...) {
authors
}
}
Where REST doesn't help you is when you want to be able to filter on a lot of things — either your API becomes an explosion of all permutations of relationships, or you do (as many do) create a "query API" that takes all sorts of criteria as inputs. For example: When you get a books' authors you might want to filter by editors only. Or you want to find all books written by an author that were published in the 1950s. REST also doesn't help the client pick which fields to include, or which relationships to follow. Sure, you can implement it on top of REST, but any such solution becomes ad-hoc and app-specific.Part of that is, firstly, because REST is a set of rules, not a complete protocol, and secondly, REST wants to deal with resources, not queries. Queries (ie., POST to some collection) are left as an exercise for the reader.
Coincidentally, there is no reason why you can't encode GraphQL queries as GET URLs via paths:
/books/id=1/year=1950..1959/authors/name=~John
This probably violates the tenets of REST, which says that resource URLs should uniquely identify a resource. I forget what REST says, if anything, about "views" into resources.on the other hand having super dump backend makes it expensive to query data, since we have light speed limit for roundtrip between request and response at best.
what graphql does - it shifts point which does all these multiple requests closer to the storage layer and return you processed results based on query you asked.
if you application already returns rich data structures - graphql is probably do not belong here (right now). if you develop true microservices architecture - graphql sitting on top of it certainly might make sense.
as usual - it depends :)
you need to implement resolve method to map properties to your backend(s)
yes, it is not drop in, but using any node.js http request library should do the trick.
also, both can co-exist if you have application which already uses existing rest api layer.
But it always does. rest client needs rest backend. graphql client needs graphql backend.
Do you have some concrete examples where we've done that? We're trying hard in our communication to be honest about the trade-offs that are made.