apollows

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package apollows provides implementation of GraphQL over WebSocket Protocol as defined by apollo graphql see https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md for reference

Index

Constants

View Source
const WebsocketSubprotocol = "graphql-ws"

WebsocketSubprotocol defines websocket subprotocol expected by v1.apollows implementations

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Value interface{}
	json.RawMessage
}

Data encapsulates both client and server json payload, combining json.RawMessage for decoding and arbitrary interface{} type for encoding

func (Data) MarshalJSON

func (payload Data) MarshalJSON() (bs []byte, err error)

MarshalJSON marshals either provided or deserialized Value as json

func (*Data) ReadPayloadData

func (payload *Data) ReadPayloadData() (*PayloadDataResponse, error)

ReadPayloadData client-side method to parse server response

func (*Data) UnmarshalJSON

func (payload *Data) UnmarshalJSON(bs []byte) (err error)

UnmarshalJSON stores provided json as a RawMessage, as well as initializing Value to same RawMessage to support both identity re-serialization and modification of Value after initialization

type Message

type Message struct {
	ID      string    `json:"id,omitempty"`
	Type    Operation `json:"type"`
	Payload Data      `json:"payload,omitempty"`
}

Message encapsulates every message within v1.apollows protocol in both directions

type Operation

type Operation string

Operation type is used to enumerate possible apollo message types

const (
	// OperationConnectionInit is set by the connecting client to initialize the websocket state with connection params
	// (if any)
	OperationConnectionInit Operation = "connection_init"

	// OperationStart client request initiates new operation
	// each operation may have 1-N OperationData / OperationError responses before being OperationComplete by the server
	// (potentially in response to OperationStop client request)
	OperationStart Operation = "start"

	// OperationStop client request to stop previously initiated operation with OperationStart
	OperationStop Operation = "stop"

	// OperationTerminate client request to gracefully close the connection
	OperationTerminate Operation = "connection_terminate"

	// OperationConnectionError server response to unsuccessful OperationConnectionInit attempt
	OperationConnectionError Operation = "connection_error"

	// OperationConnectionAck server response to successful OperationConnectionInit attempt
	OperationConnectionAck Operation = "connection_ack"

	// OperationData server response to previously initiated operation with OperationStart
	// may be multiple within same operation, specifically for subscriptions
	OperationData Operation = "data"

	// OperationError server response to previously initiated operation with OperationStart
	// may be multiple within same operation, specifically for subscriptions
	OperationError Operation = "error"

	// OperationComplete server response to terminate previously initiated operation with OperationStart
	// should be preceded by at least one OperationData or OperationError
	OperationComplete Operation = "complete"

	// OperationKeepAlive server response sent periodically to maintain websocket connection open
	OperationKeepAlive Operation = "ka"
)

type PayloadData

type PayloadData struct {
	Data Data `json:"data,omitempty"`

	// see https://github.com/graph-gophers/graphql-go#custom-errors
	// for adding custom error attributes
	Errors []error `json:"errors,omitempty"`
}

PayloadData provides server-side response for previously started operation

type PayloadDataResponse

type PayloadDataResponse struct {
	Data   map[string]interface{} `json:"data,omitempty"`
	Errors []PayloadError         `json:"errors,omitempty"`
}

PayloadDataResponse provides client-side payload representation

type PayloadError

type PayloadError struct {
	Extensions map[string]interface{} `json:"extensions"`
	Message    string                 `json:"message"`
	Locations  []PayloadErrorLocation `json:"locations"`
	Path       []string               `json:"path"`
}

PayloadError client-side error representation

type PayloadErrorLocation

type PayloadErrorLocation struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

PayloadErrorLocation error location in originating request

type PayloadInit

type PayloadInit map[string]interface{}

PayloadInit provides connection params

type PayloadOperation

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

PayloadOperation provides description for client-side operation initiation

Jump to

Keyboard shortcuts

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