class GraphQL::Transport::WebSocket

Overview

Serves a schema over a WebSocket with the graphql-transport-ws protocol used by graphql-ws, Apollo Client, urql and Relay. Not required by require "graphql"; load it with require "graphql/transport/ws".

Hand each accepted socket to a new instance. The block builds the GraphQL::Context for every operation on the connection:

handler = HTTP::WebSocketHandler.new([GraphQL::Transport::WebSocket::PROTOCOL]) do |socket, http|
  GraphQL::Transport::WebSocket.new(schema, socket) { MyContext.new(http.request) }
end

Subscriptions stream until the client sends complete or disconnects. Queries and mutations sent over the socket are executed once and answered with next and complete.

Defined in:

graphql/transport/ws.cr

Constant Summary

PROTOCOL = "graphql-transport-ws"

Constructors

Constructor Detail

def self.new(schema : GraphQL::Schema, socket : HTTP::WebSocket, &context : -> GraphQL::Context) #

def self.new(schema : GraphQL::Schema, socket : HTTP::WebSocket) #