2 ms·
> There's no way to create a compile-time static type Aren't you just saying that one GraphQL query corresponds to several REST requests? There is the same le
by paulddraper 10y ago
> There's no way to create a compile-time static type
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.
- derefr 10y agoIt's somewhat hard to communicate my exact thought here... in REST, a given verb applies an operation to one resource, and a given resource has a known-at-compile-time representation, where the schema of the returned representation should have a domain that depends only on the referred-to resource itself—i.e. the request path—where the client picks from that domain using the Accept header. A GraphQL query, meanwhile, can include parameterize associations—essentially function calls—and these calls can have non-deterministic return types. I.e., you can't create a static set of types to describe the shapes a GraphQL response might take, because there is a non-finite (push-down automata number of states rather than FSM number of states) number of possible types to the value that the function might spit out. Or, to put that another other way: there's no way to receive a GraphQL response without the ability to dynamically allocate memory. You can't say "I want a response of exactly this shape" and then stream the decoded response into e.g. a protobuf. Because the client has no way of saying to the GraphQL parser, "don't vary your schema here." For GraphQL to be a proper "kind of" thing to use with HTTP, each association in the request would have to be able to take its own Accept-header-alike attribute, so that the client could ensure that if a response is produced, it is of a defined shape.
- paulddraper 10y ago> there's no way to receive a GraphQL response without the ability to dynamically allocate memory You can allocate a fixed amount of memory for a particular GraphQL response. You can allocate a fixed amount of memory for a particular REST resource. You cannot allocate a fixed amount of memory for an arbitrary GraphQL query. You cannot allocate a fixed amount of memory for an arbitrary set of REST resources. So...I agree with what you are saying. At the the level of a single HTTP request, there is more dynamism in GraphQL. But that's not a deep distinction; REST just presents that dynamism at a level above a single HTTP request. --- Note: it is common for people to define sets of REST requests with function calls, but write GraphQL queries in a string. If you defined your set of REST requests in a string and wrote your GraphQL queries with function calls, you'd see many observations reversed.
- derefr 10y agoTo be clearer, what I was saying is that you can't predict how much memory you'll need to allocate for a GraphQL response given the particular query you've made, because there's no way to get the server to give you a guarantee that all the field types are scalars or length-limited strings (or arrays of known-typed maps whose members are all scalars or length-limited strings, etc.) In REST, you can, by Accept-ing only media-types that guarantee such a condition. But there's no way to annotate the "function calls" [field-accessors-with-attributes] that appear within a GraphQL request, to force the GraphQL backend to act in a similar way to a web server with regards to media types of associated fields. You can't say "for this response field, I only Accept these types", and then have the GraphQL backend realize that its response would be unwanted and throw away its work, sending back a 406 error instead.