Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipart/mixed transport support for deferred queries #3341

Merged

Conversation

giulio-opal
Copy link
Contributor

@giulio-opal giulio-opal commented Oct 21, 2024

@defer spec doesn't necessarily specify which request headers need to be supported, but Apollo Client injects a multipart/mixed header whenever the query contains a @defer directive and expects a multipart/mixed response:

Spec: https://github.com/graphql/graphql-wg/blob/e4ef5f9d5997815d9de6681655c152b6b7838b4c/rfcs/DeferStream.md
This partially solves: #3335 and #2771

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

Note that the response is actually wrapped in a incremental property because that's how the Apollo Client expects it: https://github.com/apollographql/apollo-client/blob/v3.11.8/src/link/http/__tests__/responseIterator.ts#L79-L91

Example of communication (redacted few fields):

$ curl 'http://localhost:3000/query' -H 'Authorization: bearer xxx==' -H 'Connection: keep-alive' -H 'accept: multipart/mixed' -H 'content-type: application/json' --data-raw '{"operationName":"InventoryPage","variables":{},"query":"query InventoryPage {\n  apps {\n    apps {\n      id\n      ...AppGroupCountCell @defer(label: \"AppGroupCountCell\")\n      ...AppUserCountCell @defer(label: \"AppUserCountCell\")\n      __typename\n    }\n    __typename\n  }\n}\n\nfragment AppGroupCountCell on App {\n  groupAccessCount\n  __typename\n}\n\nfragment AppUserCountCell on App {\n  userAccessCount\n  __typename\n}\n"}'
--graphql
Content-Type: application/json

{"data":{"apps":{"apps":[{"id":"123","groupAccessCount":null,"__typename":"App","userAccessCount":null},{"id":"123","groupAccessCount":null,"__typename":"App","userAccessCount":null},{"id":"123","groupAccessCount":null,"__typename":"App","userAccessCount":null},{"id":"123","groupAccessCount":null,"__typename":"App","userAccessCount":null},{"id":"123","groupAccessCount":null,"__typename":"App","userAccessCount":null},{"id":"1324","groupAccessCount":null,"__typename":"App","userAccessCount":null},{"id":"sdf","groupAccessCount":null,"__typename":"App","userAccessCount":null},{"id":"asdf","groupAccessCount":null,"__typename":"App","userAccessCount":null}],"__typename":"AppsOutput"}},"hasNext":true}

--graphql
Content-Type: application/json

{"incremental":[{"data":{"groupAccessCount":0},"label":"AppGroupCountCell","path":["apps","apps",6],"hasNext":true}],"hasNext":true}

--graphql
Content-Type: application/json

{"incremental":[{"data":{"groupAccessCount":0},"label":"AppGroupCountCell","path":["apps","apps",23],"hasNext":true}],"hasNext":true}

--graphql
Content-Type: application/json

{"incremental":[{"data":{"groupAccessCount":0},"label":"AppGroupCountCell","path":["apps","apps",4],"hasNext":true}],"hasNext":true}

...

@coveralls
Copy link

Coverage Status

coverage: 59.267% (+0.4%) from 58.893%
when pulling ec8dffd on giulio-opal:giulio/defer-over-multipart
into acd9b6a on 99designs:master.

@StevenACoffman StevenACoffman merged commit abc7c61 into 99designs:master Oct 22, 2024
16 of 17 checks passed
@StevenACoffman StevenACoffman added the defer-or-stream Related to GraphQL @defer or @stream directives label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defer-or-stream Related to GraphQL @defer or @stream directives
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants