Restore important guidance, improve legacy support#398
Restore important guidance, improve legacy support#398martinbonnin merged 8 commits intoappendix-afrom
Conversation
|
I woke up with a revelation: we can do a hybrid approach that increases compatibility whilst also maximizing use of status codes! For legacy requests (those that
I've written this change up into this proposal, and if further reduces my concerns about breaking the legacy of GraphQL whilst being minimal effort for a server to support, not trading off the status codes that we're pushing for, and only being a non-normative recommendation. |
| If the _GraphQL response_ contains a non-null {data} entry then the server must | ||
| use the `200` status code. | ||
| If the _GraphQL response_ contains a non-null {data} entry then the server MUST | ||
| use a `2xx` status code and SHOULD use the `200` status code. |
There was a problem hiding this comment.
NOTE: this is a change from the previous spec, this is specifically to allow HTTP 294 responses (and other 2xx status codes) to legacy clients. AFAIK at least in the JS ecosystem most people use response.ok or check a status range rather than response.status === 200 and this lines up better with the HTTP semantics - any 2xx is success.
Apollo client checks range: https://github.com/apollographql/apollo-client/blob/7c33689cca049f46192b091eaf979b2e64fd6213/src/link/http/parseAndCheckHttpResponse.ts#L151
URQL checks range: https://github.com/urql-graphql/urql/blob/1df98a66419b523bd8859ef617e13b4c7984bc7f/packages/core/src/internal/fetchSource.ts#L226
Graffle ignores status code: https://github.com/graffle-js/graffle/blob/4c58ee6cec67fe0047cc6708f6f19232077934e3/src/extensions/TransportHttp/TransportHttp.ts#L252-L260
Relay1 ignores status codes: https://relay.dev/docs/guides/network-layer/
Footnotes
-
I guess I should say Relay's network layer example recommended in the documentation, since people keep helpfully pointing out Relay "has no network layer". ↩
|
I think I'm fine with this PR as-is, merging it back into #379 for final review. Still seems a little over-stated but that's okay, and perhaps the extra text improves the reader's ability to understand the goals of the specification. |
In #379, support for
application/jsonbecame optional, severely impacting the legacy of GraphQL clients and servers from the last decade.This PR attempts to soften this blow by recommending that servers respond to
Accept: application/jsonwithContent-Type: application/graphql-response+jsonshould they not wish to implement theapplication/jsonmedia type. For legacy clients that ignore theContent-Typeof the response and only care about responses that containdata, this is a non-breaking change, allowing us to adopt and rely upon the new media type more widely.The PR also performs editorial and restores some previous wording that I deem important - inline comments to follow.
One other key point is I try to recognize that there are/will be more media types the server will/can respond with (multipart, SSE, JSONL, etc) so some of the wording has changed to accommodate this.