Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
func (*Client) Subscribe ¶
func (c *Client) Subscribe(req Request, handler SubscriptionHandler) (id string, err error)
func (*Client) Unsubscribe ¶
type DetailError ¶
func (*DetailError) Error ¶
func (e *DetailError) Error() string
type GraphQLError ¶
type GraphQLError struct {
Message string `json:"message,omitempty"`
Locations []GraphQLErrorLocation `json:"locations,omitempty"`
Path []interface{} `json:"path,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
Path element's type should be either string or int, according to the samples of http://spec.graphql.org/draft/#sec-Errors
func (*GraphQLError) Error ¶
func (e *GraphQLError) Error() string
type GraphQLErrorLocation ¶
type GraphQLErrors ¶
type GraphQLErrors []GraphQLError
func (GraphQLErrors) Error ¶
func (e GraphQLErrors) Error() string
type Option ¶
type Option struct {
// Endpoint means HTTP server URL
Endpoint string
// HTTPClient specify http client, when it's nil, GraphQL client will use http.DefaultClient
// HTTPClient should not change to nil after init
HTTPClient *http.Client
// Headers apply to http request every time at the beginning
Headers map[string]string
// CloseBody will close http request body immediately for reusing of http client
CloseBody bool
// Client will add Header "Authorization: Bearer <Token>" for every request when BearerAuth is not empty
BearerAuth string
// Custom HTTP Log func like func(s string) { fmt.Println(s) }
Log func(msg string)
// NotCheckHTTPStatusCode200 disable http response status code for some irregular GraphQL Servers
NotCheckHTTPStatusCode200 bool
// WebSocketEndpoint specify websocket endpoint, default is Endpoint's websocket schema
WebSocketEndpoint string
// WebSocketOption specify websocket client option
WebSocketOption WSOption
}
Option be changed at anytime after NewClient
type Request ¶
type Request struct {
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
OperationName string `json:"operationName,omitempty"`
Extensions interface{} `json:"extensions,omitempty"`
// Headers apply to http request at last phase of assembling http request.
Headers map[string]string `json:"-"`
}
type SubscriptionHandler ¶
type SubscriptionHandler func(rawMsg json.RawMessage, gqlErrs GraphQLErrors, completed bool) error
GQL_ERROR will be appended to errors, then errors will be a list that contains only one error. completed is true only happens to GraphQL server send completed, if completed is true, data and errors must be nil. when returned error is not nil, Subscription will be unsubscribed. SubscriptionHandler is executed synchronized, return as soon as possible
type WSClient ¶
type WSClient struct {
*WSOption
// contains filtered or unexported fields
}
func NewWSClient ¶
func (*WSClient) Subscribe ¶
func (c *WSClient) Subscribe(req Request, handler SubscriptionHandler) (id string, err error)
func (*WSClient) UnderlyingConn ¶
func (*WSClient) Unsubscribe ¶
func (*WSClient) UnsubscribeAll ¶
type WSOption ¶
type WSOption struct {
// Dialer specify websocket Dialer, default is using websocket.DefaultDialer
Dialer *websocket.Dialer
// Headers apply to http request
Headers map[string]string
// disable automatic reconnecting
NotReconnect bool
// ReconnectAttempts is the maximum attempts of reconnection after connected, default is math.MaxUint32
ReconnectAttempts uint32
// KeepAliveTimeout is the timeout of server keepalive since last keepalive message.
// Default is 30 seconds, less or equal than 10 second will disable checking keepalive timeout.
KeepAliveTimeout time.Duration
// Custom WebSocket GraphQL Log func like func(s string) { fmt.Println(s) }
Log func(msg string)
}
Option be changed at anytime after NewWSClient
Click to show internal directories.
Click to hide internal directories.