transport

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosedConnection = fmt.Errorf("closed connection")

Functions

This section is empty.

Types

type ChanResponse

type ChanResponse struct {
	// contains filtered or unexported fields
}

func NewChanResponse

func NewChanResponse(onClose func() error) *ChanResponse

func (*ChanResponse) Close

func (r *ChanResponse) Close()

func (*ChanResponse) CloseCh

func (r *ChanResponse) CloseCh()

func (*ChanResponse) CloseWithError added in v0.0.7

func (r *ChanResponse) CloseWithError(err error)

func (*ChanResponse) Done added in v0.0.4

func (r *ChanResponse) Done() <-chan struct{}

func (*ChanResponse) Err

func (r *ChanResponse) Err() error

func (*ChanResponse) Get

func (*ChanResponse) Next

func (r *ChanResponse) Next() bool

func (*ChanResponse) Send

func (r *ChanResponse) Send(op OperationResponse)

type ConnOptions

type ConnOptions struct {
	Context context.Context
	URL     string
	Timeout time.Duration
}

type Func

type Func func(Request) Response

func (Func) Request

func (f Func) Request(req Request) Response

type Http

type Http struct {
	URL string
	// Client defaults to http.DefaultClient
	Client           *http.Client
	RequestOptions   []HttpRequestOption
	UseFormMultipart bool
}

func (*Http) Request

func (h *Http) Request(req Request) Response

type HttpRequestOption

type HttpRequestOption func(req *http.Request)

type Mock

type Mock map[string]Func

func (Mock) Request

func (m Mock) Request(req Request) Response

type Operation

type Operation string
const (
	Query        Operation = "query"
	Mutation     Operation = "mutation"
	Subscription Operation = "subscription"
)

type OperationMessage

type OperationMessage struct {
	ID      string               `json:"id,omitempty"`
	Type    OperationMessageType `json:"type"`
	Payload json.RawMessage      `json:"payload,omitempty"`
}

func (OperationMessage) String

func (msg OperationMessage) String() string

type OperationMessageType

type OperationMessageType string
const (
	// GQL_CONNECTION_INIT the Client sends this message after plain websocket connection to start the communication with the server
	GQL_CONNECTION_INIT OperationMessageType = "connection_init"
	// GQL_CONNECTION_ERROR The server may responses with this message to the GQL_CONNECTION_INIT from client, indicates the server rejected the connection.
	GQL_CONNECTION_ERROR OperationMessageType = "conn_err"
	// GQL_START Client sends this message to execute GraphQL operation
	GQL_START OperationMessageType = "start"
	// GQL_STOP Client sends this message in order to stop a running GraphQL operation execution (for example: unsubscribe)
	GQL_STOP OperationMessageType = "stop"
	// GQL_ERROR Server sends this message upon a failing operation, before the GraphQL execution, usually due to GraphQL validation errors (resolver errors are part of GQL_DATA message, and will be added as errors array)
	GQL_ERROR OperationMessageType = "error"
	// GQL_DATA The server sends this message to transfter the GraphQL execution result from the server to the client, this message is a response for GQL_START message.
	GQL_DATA OperationMessageType = "data"
	// GQL_COMPLETE Server sends this message to indicate that a GraphQL operation is done, and no more data will arrive for the specific operation.
	GQL_COMPLETE OperationMessageType = "complete"
	// GQL_CONNECTION_KEEP_ALIVE Server message that should be sent right after each GQL_CONNECTION_ACK processed and then periodically to keep the client connection alive.
	// The client starts to consider the keep alive message only upon the first received keep alive message from the server.
	GQL_CONNECTION_KEEP_ALIVE OperationMessageType = "ka"
	// GQL_CONNECTION_ACK The server may responses with this message to the GQL_CONNECTION_INIT from client, indicates the server accepted the connection. May optionally include a payload.
	GQL_CONNECTION_ACK OperationMessageType = "connection_ack"
	// GQL_CONNECTION_TERMINATE the Client sends this message to terminate the connection.
	GQL_CONNECTION_TERMINATE OperationMessageType = "connection_terminate"

	// GQL_UNKNOWN is an Unknown operation type, for logging only
	GQL_UNKNOWN OperationMessageType = "unknown"
	// GQL_INTERNAL is the Internal status, for logging only
	GQL_INTERNAL OperationMessageType = "internal"
)

type OperationRequest

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

func NewOperationRequestFromRequest added in v0.0.7

func NewOperationRequestFromRequest(req Request) OperationRequest

type OperationResponse

type OperationResponse struct {
	Data       json.RawMessage `json:"data,omitempty"`
	Errors     gqlerror.List   `json:"errors,omitempty"`
	Extensions RawExtensions   `json:"extensions,omitempty"`
}

func NewMockOperationResponse

func NewMockOperationResponse(v interface{}, errs gqlerror.List) OperationResponse

func (OperationResponse) UnmarshalData

func (r OperationResponse) UnmarshalData(t interface{}) error

type ProxyResponse added in v0.0.7

type ProxyResponse struct {
	// contains filtered or unexported fields
}

func NewProxyResponse added in v0.0.7

func NewProxyResponse() *ProxyResponse

func (*ProxyResponse) Bind added in v0.0.7

func (p *ProxyResponse) Bind(res Response, onOpres func(response OperationResponse, send func()))

func (*ProxyResponse) Bound added in v0.0.7

func (p *ProxyResponse) Bound(res Response) bool

func (*ProxyResponse) Unbind added in v0.0.7

func (p *ProxyResponse) Unbind(res Response)

type RawExtensions added in v0.0.7

type RawExtensions map[string]json.RawMessage

func (RawExtensions) Unmarshal added in v0.0.7

func (es RawExtensions) Unmarshal(name string, t interface{}) error

type Request

type Request struct {
	Context   context.Context
	Operation Operation

	OperationName string
	Query         string
	Variables     map[string]interface{}
	Extensions    map[string]interface{}
}

type Response

type Response interface {
	Next() bool
	Get() OperationResponse
	Close()
	CloseWithError(err error)
	Err() error
	Done() <-chan struct{}
}

func NewErrorResponse added in v0.0.7

func NewErrorResponse(err error) Response

type SendResponse added in v0.0.7

type SendResponse interface {
	Response
	Send(OperationResponse)
}

type SingleResponse

type SingleResponse struct {
	// contains filtered or unexported fields
}

func NewSingleResponse

func NewSingleResponse(or OperationResponse) *SingleResponse

func (*SingleResponse) Close

func (r *SingleResponse) Close()

func (*SingleResponse) CloseWithError added in v0.0.7

func (r *SingleResponse) CloseWithError(err error)

func (*SingleResponse) Done added in v0.0.4

func (r *SingleResponse) Done() <-chan struct{}

func (*SingleResponse) Err

func (r *SingleResponse) Err() error

func (*SingleResponse) Get

func (*SingleResponse) Next

func (r *SingleResponse) Next() bool

type Status

type Status int
const (
	StatusDisconnected Status = iota
	StatusConnected
	StatusReady
)

func (Status) String

func (s Status) String() string

type Transport

type Transport interface {
	Request(req Request) Response
}

func Split

func Split(f func(Request) (Transport, error)) Transport

func SplitSubscription

func SplitSubscription(subtr, othertr Transport) Transport

SplitSubscription routes subscription to subtr, and other type of queries to othertr

type Upload added in v0.0.8

type Upload struct {
	Name string
	File io.Reader
}

func NewUpload added in v0.0.8

func NewUpload(f *os.File) Upload

func (Upload) MarshalJSON added in v0.0.8

func (u Upload) MarshalJSON() ([]byte, error)

func (*Upload) UnmarshalJSON added in v0.0.8

func (u *Upload) UnmarshalJSON(data []byte) error

type WebsocketConn

type WebsocketConn interface {
	ReadJSON(v interface{}) error
	WriteJSON(v interface{}) error
	Close() error
	// SetReadLimit sets the maximum size in bytes for a message read from the peer. If a
	// message exceeds the limit, the connection sends a close message to the peer
	// and returns ErrReadLimit to the application.
	SetReadLimit(limit int64)
}

type WebsocketConnProvider

type WebsocketConnProvider func(ctx context.Context, URL string) (WebsocketConn, error)

func DefaultWebsocketConnProvider

func DefaultWebsocketConnProvider(timeout time.Duration, optionfs ...WsDialOption) WebsocketConnProvider

DefaultWebsocketConnProvider is the connections factory A timeout of 0 means no timeout, reading will block until a message is received or the context is canceled If your server supports the keepalive, set the timeout to something greater than the server keepalive (for example 15s for a 10s keepalive)

type WebsocketHandler

type WebsocketHandler struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

WebsocketHandler is default websocket handler implementation using https://github.com/nhooyr/websocket

func (*WebsocketHandler) Close

func (wh *WebsocketHandler) Close() error

func (*WebsocketHandler) ReadJSON

func (wh *WebsocketHandler) ReadJSON(v interface{}) error

func (*WebsocketHandler) WriteJSON

func (wh *WebsocketHandler) WriteJSON(v interface{}) error

type Ws

type Ws struct {
	URL string
	// WebsocketConnProvider defaults to DefaultWebsocketConnProvider(30 * time.Second)
	WebsocketConnProvider WebsocketConnProvider
	// ConnectionParams will be sent during the connection init
	ConnectionParams interface{}
	// contains filtered or unexported fields
}

Ws transports GQL queries over websocket Start() must be called to initiate the websocket connection Close() must be called to dispose of the transport

func (*Ws) Close

func (t *Ws) Close() error

func (*Ws) GetConn

func (t *Ws) GetConn() WebsocketConn

func (*Ws) Request

func (t *Ws) Request(req Request) Response

func (*Ws) Reset

func (t *Ws) Reset()

func (*Ws) ResetWithErr

func (t *Ws) ResetWithErr(err error)

func (*Ws) Start

func (t *Ws) Start(ctx context.Context) <-chan error

func (*Ws) WaitFor

func (t *Ws) WaitFor(st Status, s time.Duration)

type WsDialOption

type WsDialOption func(o *websocket.DialOptions)

Jump to

Keyboard shortcuts

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