Serving

Once we have built a GraphQL schema, the next obvious step would be to serve it, so clients can interact with our GraphQL API. Usually, GraphQL APIs are served via HTTP.

Web server frameworks

Though the juniper crate doesn't provide a built-in HTTP server, the surrounding ecosystem does.

Officially supported

Juniper officially supports the following widely used and adopted web server frameworks in Rust ecosystem:

See their API docs and usage examples (accessible from API docs) for further details of how they should be used.

NOTE: All the officially supported web server framework integrations provide a simple and convenient way for exposing GraphiQL and/or GraphQL Playground with the GraphQL schema along. These powerful tools ease the development process by enabling you to explore and send client requests to the GraphQL API under development.

WebSocket

NOTE: WebSocket is a crucial part for serving GraphQL subscriptions over HTTP.

There are two widely adopted protocols for serving GraphQL over WebSocket:

  1. Legacy graphql-ws GraphQL over WebSocket Protocol, formerly used by Apollo and the subscriptions-transport-ws npm package, and now being deprecated.
  2. New graphql-transport-ws GraphQL over WebSocket Protocol, provided by the graphql-ws npm package and being used by Apollo as for now.

In the Juniper ecosystem, both implementations are provided by the juniper_graphql_ws crate. Most of the officially supported web server framework integrations are able to serve a GraphQL schema over WebSocket (including subscriptions) and even support auto-negotiation of the correct protocol based on the Sec-Websocket-Protocol HTTP header value. See their API docs and usage examples (accessible from API docs) for further details of how to do so.