Documentation ¶
Index ¶
Constants ¶
const WebSocketSubprotocol = "graphql-transport-ws"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { Handler ConnectionHandler // contains filtered or unexported fields }
Connection represents a server-side GraphQL-WS connection.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close closes the connection. This must not be called from handler functions.
func (*Connection) SendComplete ¶
func (c *Connection) SendComplete(ctx context.Context, id string) error
SendComplete sends the "complete" message to the client. This should be done after queries are executed or subscriptions are stopped.
func (*Connection) Serve ¶
func (c *Connection) Serve(conn *websocket.Conn)
Serve takes ownership of the given connection and begins reading / writing to it.
type ConnectionHandler ¶
type ConnectionHandler interface { // Called when the server receives the init message. If an error is returned, it will be sent to // the client and the connection will be closed. HandleInit(parameters json.RawMessage) error // Called when the client wants to start an operation. If the operation is a query or mutation, // the handler should immediately call SendData followed by SendComplete. If the operation is a // subscription, the handler should call SendData to send events and SendComplete if/when the // event stream ends. HandleStart(id string, query string, variables map[string]interface{}, operationName string) // Called when the client wants to stop an operation. The handler should unsubscribe them from // the corresponding subscription. HandleStop(id string) // Called when an unexpected error occurs. The connection will perform the appropriate response, // but you may want to log it. LogError(err error) // Called when the connection begins closing and all in-flight operations should be canceled. Cancel() // Called when the connection is closed. HandleClose() }
ConnectionHandler methods may be invoked on a separate goroutine, but invocations will never be made concurrently.
type Message ¶
type Message struct { Id string `json:"id,omitempty"` Type MessageType `json:"type"` Payload json.RawMessage `json:"payload,omitempty"` }
Message represents a GraphQL-WS message. This can be used for both client and server messages.
type MessageType ¶
type MessageType string
MessageType represents a GraphQL-WS message type.
const ( MessageTypeConnectionInit MessageType = "connection_init" MessageTypeConnectionAck MessageType = "connection_ack" MessageTypePing MessageType = "ping" MessageTypePong MessageType = "pong" MessageTypeSubscribe MessageType = "subscribe" MessageTypeNext MessageType = "next" MessageTypeError MessageType = "error" MessageTypeComplete MessageType = "complete" )
MessageType represents a GraphQL-WS message type.