84 points · by guifortaine · 9y ago · 10 comments
> GraphQL turns the REST paradigm as it's usually implemented on its head: instead of providing a fixed structure of all types and relations in the system, GraphQL defines a schema which your users can query.
I have no idea what that means.
With graphql, you have a smaller number of endpoints, but you have one big schema definition. You can then choose who to query it the way you want.
This means not only that a graphql API is more flexible and easier have a entire view of, but also that GRAPHQL is a nicer generic data interface. You can use it not just for HTTP requests, but also between components. You can use it as a source of truth. You can allow joins without having to design them, and even easily implement several data sources for them, including caching.
Graphql kinda have the benefit of SQL and a Web API.
REST defines media formats, and the relationships are described by hyperlinks in the media.
GraphQL is much the same in that it has a relational schema.
The difference is that GraphQL has filter and join capabilities. Vanilla REST is usually all-or-nothing for a resource.
GraphQL, meanwhile, allows the user to specify the "shape" of the result they want, by specifying what fields or associations they want to be included in the result—but these can also be parameterized, and the accessor-function that receives the arguments is free to do anything it likes with them, instead of just using them to select an association or field to pass back. It's effectively equivalent to the ability, in SQL, to do "SELECT arbitrary_function(field) AS column".
There's no way to create a compile-time static type, especially on the backend, which could hold the response to an arbitrary GraphQL query. (Or, equivalently, you can think of a GraphQL response as being a tree of widely-product-typed fields, similar to modelling a decoded JSON object in a statically-typed language.)
Which might, more to the point, include "application/graphql".
In real REST, semantics are determined by media types of resource representations supported by endpoints.
REST is not limited to mapping CRUD operations on a crude data model to HTTP verbs.
Aren't you just saying that one GraphQL query corresponds to several REST requests?
There is the same level of typedness between an arbitrary GraphQL query and an arbitrary set of REST requests.
https://arstechnica.com/security/2016/01/juniper-drops-nsa-d...