Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
func NewHandler(u websocket.Upgrader, s *SubscriptionManager, e ConnectionEventHandlers) http.Handler
NewHandler returns a websocket based HTTP handler for graphQL.
Types ¶
type ConnectionEventHandlers ¶
type ConnectionEventHandlers struct {
// Close is called whenever the connection is closed, regardless of
// whether this happens because of an error or a deliberate termination
// by the client.
Close func(conn *websocket.Conn)
// Start handler is called whenever the client demands that a GraphQL
// operation be started (typically a subscription). Event handlers
// are expected to take the necessary steps to register the operation
// and send data back to the client with the results eventually.
Start func(s *Subscription)
// Stop handler is called whenever the client stops a previously
// started GraphQL operation (typically a subscription). Event handlers
// are expected to unregister the operation and stop sending result
// data to the client.
Stop func(subID string)
}
ConnectionEventHandlers define the event handlers for a connection. Event handlers allow other system components to react to events such as the connection closing or an operation being started or stopped.
type ConnectionMessage ¶
type ConnectionMessage struct {
OperationID string `json:"id,omitempty"`
Type string `json:"type"`
Payload struct {
OperationName string `json:"operationName,omitempty"`
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
} `json:"payload,omitempty"`
}
ConnectionMessage represents the GraphQL WebSocket message.
type Handler ¶
type Handler func(payload interface{}) error
Handler represents the handler func that should be triggered when an event fires.
type PubSub ¶
type PubSub interface {
Subscribe(event string, handler Handler) (subID string)
Publish(event string, payload interface{})
Unsubscribe(subID string)
}
PubSub is the interface that describes the publish and subscribe system.
type Subscription ¶
type Subscription struct {
ID string
RequestString string
Variables map[string]interface{}
OperationName string
Conn *websocket.Conn
CallBack CallBack
SubscriberID string
}
Subscription represents the graphQL client subscription.
type SubscriptionManager ¶
type SubscriptionManager struct {
PubSub PubSub
Schema *graphql.Schema
// contains filtered or unexported fields
}
SubscriptionManager manages the graphQL subscriptions.
func NewSubscriptionManager ¶
func NewSubscriptionManager(schema *graphql.Schema, ps PubSub) *SubscriptionManager
NewSubscriptionManager creates a new subscription manager.
func (*SubscriptionManager) AddSubscription ¶
func (sm *SubscriptionManager) AddSubscription(s *Subscription) error
AddSubscription adds a new subscription to the subscription manager.
func (*SubscriptionManager) RemoveSubscription ¶
func (sm *SubscriptionManager) RemoveSubscription(subscriptionID string)
RemoveSubscription removes the a previously added subscription.