async-graphql/integrations
Koxiaet 7471537036 Improve Rocket integration
This is breaking, but since updating Rocket is also breaking I think
it's fine not to bump the major version number.
2020-10-15 18:19:20 +01:00
..
actix-web Improve Tide integration 2020-10-15 11:52:15 +01:00
rocket Improve Rocket integration 2020-10-15 18:19:20 +01:00
tide Improve Tide integration 2020-10-15 11:52:15 +01:00
warp Improve Warp integration 2020-10-15 14:18:57 +01:00
README.md Add integrations README 2020-09-25 18:25:52 +01:00

Integrations for async-graphql

This directory provides various integrations for async-graphql to various crates in the ecosystem.

Requirements for an HTTP integration

This is a list of criteria for HTTP integrations with async-graphql in order to make sure all integrations are implemented consistently. Currently not all integrations follow this criteria, but we are working on it.

Integrations may provide additional functionality to better integrate with the specific library, but they must all internally use the below functions.

  • Conversion from HTTP library's request to async_graphql::BatchRequest:
    1. If the request is a GET request:
      1. Return the request's query parameters deserialized as an async_graphql::Request.
    2. Otherwise:
      1. Get the request's Content-Type header.
      2. Call async_graphql::http::receive_batch_body on the request's body.
      3. Convert ParseRequestError::PayloadTooLarge to a 413 Payload Too Large response.
      4. Convert all other errors to a 400 Bad Request response.
  • Conversion from HTTP library's request to async_graphql::Request:
    1. Call the above function to convert the request to an async_graphql::BatchRequest.
    2. Call BatchRequest::into_single on the result.
    3. Convert all errors to a 400 Bad Request response.
  • Conversion from async_graphql::BatchResponse to HTTP library's response:
    1. Create a 200 OK response.
    2. If the GraphQL response is ok, set the response's Cache-Control header to the response's cache control value.
    3. Set the response's body to the GraphQL response serialized as JSON, also setting the Content-Type header to application/json.
  • GraphQL over websocket support:
    1. Create an async_graphql::http:WebSocket using async_graphql::http::WebSocket::with_data.
    2. Support the basics of the websocket protocol:
      • Respond to ping messages with pong messages.
      • Treat continuation messages identically to data messages.
    3. Stream all websocket messages that send data (bytes/text/continuations) to the async_graphql::http::WebSocket.
    4. Convert all responses to websocket text responses.