Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorsFromGraphQLErrors(errors []gqlerrors.FormattedError) []error
- func NewConfigFactory() *configFactory
- func NewHandlerConfigFactory() *handlerConfigFactory
- func NewHttpHandler(handlerConfig HandlerConfig, connectionConfig Config, ...) http.Handler
- func NewSubscriber() *subscriber
- func SubscriptionFieldNamesFromDocument(doc *ast.Document) []string
- func ValidateSubscription(s *Subscription) []error
- type Config
- type Conn
- type ConnState
- type ConnectionInitHandler
- type ConnectionStartHandler
- type ConnectionStopHandler
- type ConnectionTerminateHandler
- type GQLConnectionError
- type GQLConnectionInit
- type GQLConnectionTerminate
- type GQLData
- type GQLDataObject
- type GQLObject
- type GQLStart
- type GQLStop
- type GQLType
- type Handler
- type HandlerConfig
- type HandlerError
- type OperationMessage
- type RWType
- type StringTopic
- type Subscriber
- type Subscription
- type SubscriptionStartHandler
- type SubscriptionStopHandler
- type SystemRecoverHandler
- type Topic
- type WebSocketUpgrader
- type WebsocketCloseHandler
- type WebsocketPingHandler
- type WebsocketPongHandler
Constants ¶
Variables ¶
var ( ErrConnectionClosed = errors.New("connection already closed") ErrUpgraderRequired = errors.New("upgrader required") ErrSchemaRequired = errors.New("schema required") ErrClientDoesNotImplementGraphqlWS = errors.New("client does not implement the `graphql-ws` subprotocol") ErrSubscriptionNotFound = errors.New("subscription not found") // ErrReinitializationForbidden is triggered when a `gqlConnectionInit` is // received twice. ErrReinitializationForbidden = errors.New("reinitalization forbidden") // ErrConnectionNotFullyEstablished is triggered when a `gqlStart` is received // without finishing a `gqlConnectionInit`. ErrConnectionNotFullyEstablished = errors.New("connection not established") // ErrInvalidTopic is triggered when a `Subscriber.SubscriberSubscribe` // receives an invalid `Topic`. ErrInvalidTopic = errors.New("invalid topic") // ErrInvalidSubscriber is triggered when a `graphql.SubscribeParams.Subscriber` // is not a instance that implements the `graphqlws.Subscriber` interface. ErrInvalidSubscriber = errors.New("invalid subscriber") )
var ( ErrSubscriptionIDEmpty = errors.New("subscription ID is empty") ErrSubscriptionHasNoConnection = errors.New("subscription is not associated with a connection") ErrSubscriptionHasNoQuery = errors.New("subscription query is empty") )
var ( TraceLevelInternalGQLMessages = 10000 TraceLevelConnectionEvents = 10001 )
var ( // ConnectionCount is the counter of new connections, also used to identify // each individual connection in the log. ConnectionCount uint64 )
var DefaultConfig = Config{
ReadLimit: &defaultReadLimit,
PongWait: &defaultPongWait,
WriteTimeout: &defaultWriteTimeout,
}
DefaultConfig holds de default param initialization values for NewConfigFactory.
Functions ¶
func ErrorsFromGraphQLErrors ¶
func ErrorsFromGraphQLErrors(errors []gqlerrors.FormattedError) []error
ErrorsFromGraphQLErrors convert from GraphQL errors to regular errors.
func NewConfigFactory ¶
func NewConfigFactory() *configFactory
NewConfigFactory creates Config instances using sugar syntax.
Example:
config := NewConfigFactory().ReadLimit(2048).PongWait(time.Second*60).Build()
You can call Build how many times you wish, it will always return a new instance with the same configuration set.
func NewHandlerConfigFactory ¶
func NewHandlerConfigFactory() *handlerConfigFactory
NewHandlerConfigFactory creates HandlerConfig instances using sugar syntax.
Example:
config := NewHandlerConfigFactory().Schema(&schemas).Upgrader(upgrader).Build()
You can call Build how many times you wish, it will always return a new instance with the same configuration set.
func NewHttpHandler ¶
func NewHttpHandler(handlerConfig HandlerConfig, connectionConfig Config, handler func(*Conn, error)) http.Handler
NewHttpHandler returns a `http.Handler` ready for being used.
`handler`: Is triggered when a connection is established. There, you should add handlers to the conn and keep track when it is active.
IMPORTANT: If `conn` is not finished. It will stay on forever.
func NewSubscriber ¶
func NewSubscriber() *subscriber
NewSubscriber creates a default implementation of a subscriber.
func ValidateSubscription ¶
func ValidateSubscription(s *Subscription) []error
Types ¶
type Config ¶
type Config struct { // ReadLimit is the maximum size of the buffer used to receive raw messages // from the websocket. ReadLimit *int64 // PongWait is how much time we will wait without sending any message to the // client before sending a PONG. PongWait *time.Duration // WriteTimeout is how much time is wait for sending a message to the // websocket before triggering a timeout error. WriteTimeout *time.Duration }
Config holds the configuration for a graphqlws connection.
See Also the NewConfigFactory for easily create Config structs.
type Conn ¶
type Conn struct { Logger rlog.Logger Schema *graphql.Schema Subscriptions sync.Map Handlers []Handler // contains filtered or unexported fields }
Conn is a connection with a client.
func (*Conn) RemoveHandler ¶
RemoveHandler removes a `Handler` from the connection.
See also `Handler`
func (*Conn) SendData ¶
func (c *Conn) SendData(message *OperationMessage)
SendData enqueues a message to be sent by the writePump.
type ConnectionInitHandler ¶
type ConnectionInitHandler interface { Handler HandleConnectionInit(*GQLConnectionInit) error }
ConnectionInitHandler describes the handler that will be called when a GQL_CONNECTION_INIT is happens.
More information abuot GQL_CONNECTION_INIT at https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_init
type ConnectionStartHandler ¶
ConnectionStartHandler describes the handler that will be called when a GQL_START is happens.
More information about GQL_START at https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_start
type ConnectionStopHandler ¶
ConnectionStopHandler describes the handler that will be called when a GQL_STOP is happens.
More information abuot GQL_STOP at https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_stop
type ConnectionTerminateHandler ¶
type ConnectionTerminateHandler interface { Handler HandleConnectionTerminate(*GQLConnectionTerminate) error }
ConnectionTerminateHandler describes the handler that will be called when a GQL_CONNECTION_TERMINATE is happens.
More information abuot GQL_CONNECTION_TERMINATE at https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_terminate
type GQLConnectionError ¶
type GQLConnectionError struct {
Payload interface{} `json:"payload"`
}
type GQLConnectionInit ¶
type GQLConnectionInit struct {
Payload json.RawMessage `json:"payload"`
}
GQLConnectionInit is sent from the client after the websocket connection is started.
The server will response only with GQL_CONNECTION_ACK + GQL_CONNECTION_KEEP_ALIVE (if used) or GQL_CONNECTION_ERROR to this message.
See Also [graphql-ws GQL_CONNECTION_INIT PROTOCOL](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_init)
type GQLConnectionTerminate ¶
type GQLConnectionTerminate struct{}
GQLConnectionTerminate is sent from the client to temrinate the connection and all its operations.
See Also [graphql-ws GQL_CONNECTION_TERMINATE PROTOCOL](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_terminate)
type GQLData ¶
type GQLData struct { ID string `json:"id"` Payload GQLDataObject `json:"payload"` }
type GQLDataObject ¶
type GQLDataObject struct { Data interface{} `json:"data"` Errors []error `json:"errors,omitempty"` }
type GQLObject ¶
type GQLObject struct { Query string `json:"query"` Variables map[string]interface{} `json:"variables,omitempty"` OperationName string `json:"operationName,omitempty"` }
GQLObject represents the payload af a GQLStart command.
type GQLStart ¶
GQLStart is sent from the client to be execute as a GraphQL command.
See Also [graphql-ws GQL_START PROTOCOL](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_start)
type GQLStop ¶
type GQLStop struct {
ID string `json:"id"`
}
GQLStop is sent from the client to stop a running GraphQL operation execution.
See Also [graphql-ws GQL_START PROTOCOL](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_stop)
type Handler ¶
type Handler interface { }
Handler is an abstraction of a callback for a specific action in the system.
type HandlerConfig ¶
type HandlerConfig struct { Upgrader WebSocketUpgrader Schema *graphql.Schema }
HandlerConfig holds the configuration for the http Handler.
type HandlerError ¶
type HandlerError struct {
// contains filtered or unexported fields
}
func (*HandlerError) Error ¶
func (err *HandlerError) Error() string
func (*HandlerError) PreventDefault ¶
func (err *HandlerError) PreventDefault() *HandlerError
PreventDefault set a flag for not executing the default implementation of an event.
func (*HandlerError) StopPropagation ¶
func (err *HandlerError) StopPropagation() *HandlerError
StopPropagation set a flag for not executing the subsequent handlers of an event.
type OperationMessage ¶
type OperationMessage struct { ID string `json:"id,omitempty"` Type GQLType `json:"type,omitempty"` Payload json.RawMessage `json:"payload"` }
OperationMessage represents all messages sent the customer to the server.
type StringTopic ¶
type StringTopic string
StringTopic is a simple implementaiton of `Topic` for those PubSub systems that use simple strings as topics.
func (StringTopic) ID ¶
func (topic StringTopic) ID() interface{}
type Subscriber ¶
type Subscriber interface { // Topics returns the array of topics subscribed. // It is designed for accumulating subscriptions before applying it to a // connection. Topics() []Topic // Subscribe does a subcription, or accumulate it (depends on the // implementation). Subscribe(topic Topic) error }
SubscriptionSubscriber does subscriptions in behalf a single Subscription
type Subscription ¶
type Subscription struct { ID string Query string Variables map[string]interface{} OperationName string Document *ast.Document Fields []string Schema *graphql.Schema Connection *Conn Logger rlog.Logger }
Subscription holds all information about a GraphQL subscription made by a client, including a function to send data back to the client when there are updates to the subscription query result.
From https://github.com/functionalfoundry/graphqlws
func (*Subscription) MatchesField ¶
func (s *Subscription) MatchesField(field string) bool
MatchesField returns true if the subscription is for data that belongs to the given field.
func (*Subscription) SendData ¶
func (s *Subscription) SendData(data *GQLDataObject) error
type SubscriptionStartHandler ¶
type SubscriptionStartHandler interface { Handler HandleSubscriptionStart(subscription *Subscription) error }
SubscriptionStartHandler describes the handler that will be called when a subscription starts.
type SubscriptionStopHandler ¶
type SubscriptionStopHandler interface { Handler HandleSubscriptionStop(subscription *Subscription) error }
SubscriptionStopHandler describes the handler that will be called when a subscription stops.
type SystemRecoverHandler ¶
SystemRecoverHandler describes the handler that will be called when any panic happens while interacting with the client.
type Topic ¶
type Topic interface { // ID will return the structure ID of the topic on the technology used for // that purpose. For example, using a Redis PubSub system, this method would // return a string containing identifier of the channel. ID() interface{} }
Topic represents a custom interface that represents a topic that will be used along with a PubSub system.
type WebSocketUpgrader ¶
type WebSocketUpgrader interface { AddSubprotocol(protocol string) Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error) }
WebSocketUpgrader is an interface that serve as a proxy to the original `gorilla.Upgrader`. It is needed to enable developers to customize their process of upgrade a HTTP connection to a WebSocket connection.
Also, it is a good way to customize the `responseHeader`.
func NewUpgrader ¶
func NewUpgrader(upgrader *websocket.Upgrader) WebSocketUpgrader
NewUpgrader implements a `WeSocketUpgrader` interface.
type WebsocketCloseHandler ¶
WebsocketCloseHandler describes the handler that will be called when the gorilla websocket close handler is called.
type WebsocketPingHandler ¶
WebsocketPongHandler describes the handler that will be called when the gorilla websocket pong handler is called.
type WebsocketPongHandler ¶
WebsocketPongHandler describes the handler that will be called when the gorilla websocket pong handler is called.