Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSubscriptionError ¶
AddSubscriptionError is used to let websocket return an error message after subscription resolver returns a channel. for example:
func (r *subscriptionResolver) Method(ctx context.Context) (<-chan *model.Message, error) {
ch := make(chan *model.Message)
go func() {
defer func() {
close(ch)
}
// some kind of block processing (e.g.: gRPC client streaming)
stream, err := gRPCClientStreamRequest(ctx)
if err != nil {
transport.AddSubscriptionError(ctx, err)
return // must return and close channel so websocket can send error back
}
for {
m, err := stream.Recv()
if err == io.EOF {
return
}
if err != nil {
transport.AddSubscriptionError(ctx, err)
return // must return and close channel so websocket can send error back
}
ch <- m
}
}()
return ch, nil
}
see https://github.com/99designs/gqlgen/pull/2506 for more details
Types ¶
type InitPayload ¶
type InitPayload map[string]interface{}
InitPayload is a structure that is parsed from the websocket init message payload. TO use request headers for non-websocket, instead wrap the graphql handler in a middleware.
type Message ¶
type Message struct {
Ref *string `json:"ref"`
JoinRef *string `json:"join_ref"`
Topic *string `json:"topic"`
Event string `json:"event"`
Payload json.RawMessage `json:"payload"`
}
func (Message) MarshalJSON ¶
MarshalJSON overrides the default JSON marshalling
type MessageExchanger ¶
type MessageExchanger struct {
// contains filtered or unexported fields
}
func (MessageExchanger) NextMessage ¶
func (me MessageExchanger) NextMessage() (Message, error)
func (MessageExchanger) Send ¶
func (me MessageExchanger) Send(m *Message) error
type Websocket ¶
type Websocket struct {
Upgrader websocket.Upgrader
InitFunc WebsocketInitFunc
InitTimeout time.Duration
ErrorFunc WebsocketErrorFunc
CloseFunc WebsocketCloseFunc
}
Websocket is a custom websocket transport that extends the default transport with Phoenix-specific functionality. Phoenix is a web framework for Elixir that uses websockets for real-time communication; the goal of this transport is to provide a way for the GraphQL server to communicate with Phoenix clients.
func (Websocket) Do ¶
func (t Websocket) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor)
type WebsocketCloseFunc ¶
Callback called when websocket is closed.
type WebsocketErrorFunc ¶
type WebsocketInitFunc ¶
type WebsocketInitFunc func(ctx context.Context, initPayload InitPayload) (context.Context, *InitPayload, error)