graphql feature mounts a GraphQL endpoint on the same Axum router as your REST controllers, and the ws feature adds WebSocket gateways with the same #[injectable] provider injection and guard/pipe/interceptor cross-cutting you use everywhere else.
GraphQL
Setup
Add thegraphql feature to your nestrs dependency and add async-graphql and nestrs-graphql:
nestrs-graphql crate is re-exported as nestrs::graphql when the feature is enabled.
Defining a schema
Define your query and mutation types usingasync-graphql attributes and build a Schema. Then pass it to enable_graphql:
GET /graphql (GraphQL Playground) and POST /graphql (query endpoint) on the same router as your REST routes. The global prefix and URI versioning settings apply to the GraphQL path the same way they apply to REST controllers.
Custom path and options
Useenable_graphql_with_path to change the mount point:
enable_graphql_with_options to control Playground availability and other HTTP-surface settings:
Mutations and resolvers
Federation, schema stitching, and codegen are outside the nestrs core. Use async-graphql’s federation support and Apollo Router or GraphOS to compose subgraphs. nestrs exposes a single
/graphql endpoint — treat it as one subgraph in your platform.WebSockets
Setup
Add thews feature:
nestrs-ws is re-exported as nestrs::ws when the feature is enabled.
Wire format
WebSocket frames are JSON objects with the shape{ "event": "name", "data": <json> }. The server sends the same format back to clients. Unknown frames and error conditions are sent to the client on the special "error" event name (nestrs::ws::WS_ERROR_EVENT).
Defining a gateway
Use#[ws_gateway] on a struct and #[ws_routes] on its impl block. Individual message handlers are annotated with #[subscribe_message("event-name")]:
Emitting to a client
WsClient::emit serializes a value and sends it as a JSON frame:
WsClient::emit_json sends a pre-built serde_json::Value directly.
Guards, pipes, and interceptors
Apply cross-cutting to WebSocket handlers with thews-specific attributes:
Error frame shapes
All errors are delivered on
WS_ERROR_EVENT ("error").
Full WebSocket example
Full WebSocket example