Skip to main content
When using Subscriptions with Cosmo Router locally or through Cosmo Studio, you’d need to configure the correct protocol to talk to your Subgraphs. Cosmo Router Supports WebSockets as well as the SSE (Server-Sent Events) for transport. When using WebSockets, the Router automatically negotiates with the Subgraph what protocol to use. The protocols “graphql-ws” and “graphql-transport-ws” are both supported.

Configure Subscriptions for local development

When composing a Graph locally, you can supply the protocol using the following configuration.
If your Subgraph uses SSE, use the following configuration.
If your Subgraph uses SSE over HTTP POST, the config should look like this.
If your Subscriptions Endpoint differs from the default routing URL, you can use the following configuration.

Configure Subscriptions using wgc

When using Cosmo Studio as a target to publish your Subgraphs, you’ll be using “wgc publish” to upload the Subgraph configuration to the Studio. In this case, you can supply the protocol using the following config.

Setting a custom Subscriptions protocol on wgc publish

Available options are “sse”, “sse_post”, and “ws”.

Setting a custom Subscriptions URL on wgc publish

You can also use `wgc subgraph update …` to update the Subscriptions protocol or URL for a specific Subgraph.

Tuning the upstream subscription client

The router’s upstream WebSocket client (the one that connects to subgraphs for subscriptions) is configured under the engine block. The defaults suit most deployments. The options below are listed with their YAML field and the matching environment variable. Example:

Tuning the server-side WebSocket handler

These options apply to the router’s own WebSocket endpoint (the one clients connect to). They are separate from the upstream client options above.
Subject to change. enable_net_poll, websocket_server_poll_timeout, and websocket_server_conn_buffer_size may be removed or changed in a future release without a standard deprecation cycle. Avoid depending on them.
If you are upgrading from an older release and your configuration sets websocket_client_poll_timeout, websocket_client_read_timeout, websocket_client_conn_buffer_size, or websocket_client_frame_timeout, see the Subscriptions Overhaul migration guide.