graphqlws

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CloseDeadlineDuration time.Duration = 100 * time.Millisecond
)

Functions

func NewConnection

func NewConnection(ctx context.Context, config Config) (*wsConnection, error)

NewConnection establishes a GraphQL WebSocket connection. It implements the GraphQL WebSocket protocol by managing its internal state and handling the client-server communication.

Types

type CloseCode

type CloseCode int
const (
	// Subprotocol - https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
	Subprotocol = "graphql-ws"

	// CloseCodes
	NormalClosure       CloseCode = 1000
	ProtocolError       CloseCode = 1002
	UnexpectedCondition CloseCode = 1011

	// Thresholds
	WriteTimeout = 10 * time.Second
)

type Config

type Config struct {
	WS                  *websocket.Conn
	Schema              *graphql.Schema
	Logger              *logger.LogWrapper
	Request             *http.Request
	KeepAlive           time.Duration
	RootValueFunc       func(ctx context.Context, r *http.Request, op *ast.OperationDefinition) map[string]interface{}
	ContextValueFunc    func(c protocol.Context, msg protocol.OperationMessage, execArgs graphql.Params) (context.Context, gqlerrors.FormattedErrors)
	OnConnect           func(c protocol.Context, payload interface{}) (interface{}, error)
	OnDisconnect        func(c protocol.Context)
	OnOperation         func(c protocol.Context, msg StartMessage, params *graphql.Params) (*graphql.Params, error)
	OnOperationComplete func(c protocol.Context, id string)
}

ConnectionConfig defines the configuration parameters of a GraphQL WebSocket connection.

type StartMessage

type StartMessage struct {
	ID      string               `json:"id,omitempty"`
	Type    protocol.MessageType `json:"type"`
	Payload StartMessagePayload  `json:"payload,omitempty"`
}

type StartMessagePayload

type StartMessagePayload struct {
	Query         string                 `json:"query"`
	Variables     map[string]interface{} `json:"variables"`
	OperationName string                 `json:"operationName"`
}

StartMessagePayload defines the parameters of an operation that a client requests to be started.

func (*StartMessagePayload) Validate

func (s *StartMessagePayload) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL