Documentation
¶
Index ¶
Constants ¶
const (
AbsintheWSSubProtocol = "absinthe"
)
const (
// This might seem confusing, but the protocol is called graphql-ws and uses "graphql-transport-ws" as subprotocol
GraphQLWSSubprotocol = "graphql-transport-ws"
)
const (
// Again, this is not a typo. Somehow they managed to give each protocol name to the other's subprotocol identifier.
SubscriptionsTransportWSSubprotocol = "graphql-ws"
)
Variables ¶
var ( CloseKindNormal = CloseKind{Code: ws.StatusNormalClosure, Reason: "Normal closure"} CloseKindGoingAway = CloseKind{Code: ws.StatusGoingAway, Reason: "Going away"} CloseKindTooManyInits = CloseKind{Code: 4429, Reason: "Too many initialisation requests"} CloseKindInvalidMessageType = CloseKind{Code: 4400, Reason: "Invalid message type"} )
Functions ¶
func IsSupportedSubprotocol ¶
func Subprotocols ¶
func Subprotocols() []string
Types ¶
type CloseError ¶
CloseError signals that the protocol layer (or a downstream handler) wants the connection torn down with a specific close kind. The protocol layer does not write the close frame itself — it returns this error so the transport-layer message loop owns the single Close call. Unwraps to the underlying cause for log/debug purposes.
func (*CloseError) Error ¶
func (e *CloseError) Error() string
func (*CloseError) Unwrap ¶
func (e *CloseError) Unwrap() error
type CloseKind ¶
type CloseKind struct {
Code ws.StatusCode
Reason string
}
CloseKind is the WebSocket close code and reason sent to the downstream client when the connection handler tears down. Connection-level concern — never sent from the resolver.
func CloseKindOf ¶
CloseKindOf returns the close kind to use when tearing down a connection after err. Errors that wrap a *CloseError carry their own kind; everything else (network read failure, JSON decode error, etc.) falls back to CloseKindNormal.
type Message ¶
type Message struct {
ID string
Type MessageType
Payload json.RawMessage
}
type MessageType ¶
type MessageType int
MessageType indicates the type of the message received from the client
const ( MessageTypePing MessageType = iota + 1 MessageTypePong MessageTypeSubscribe MessageTypeComplete MessageTypeTerminate )
type Proto ¶
type Proto interface {
Subprotocol() string
// Initialize starts the protocol and returns the initial payload received from the client.
// On a protocol-level rejection (bad first message, etc.) it returns a *CloseError carrying
// the close code and reason. The transport-layer caller writes the close frame.
Initialize() (json.RawMessage, error)
// ReadMessage reads the next message from the client. On a protocol-level rejection
// (duplicate connection_init, unknown message type, etc.) it returns a *CloseError; the
// transport-layer caller writes the close frame.
ReadMessage() (*Message, error)
Pong(*Message) error
WriteGraphQLData(id string, data json.RawMessage, extensions json.RawMessage) error
WriteGraphQLErrors(id string, errors json.RawMessage, extensions json.RawMessage) error
// Complete is sent to indicate the requested operation is done and no more results will come in
Complete(id string) error
}