Documentation ¶
Index ¶
- type Client
- func (p *Client) MustPost(query string, response any, options ...Option)
- func (p *Client) Post(query string, response any, options ...Option) error
- func (p *Client) RawPost(query string, options ...Option) (*Response, error)
- func (p *Client) SSE(ctx context.Context, query string, options ...Option) *SSE
- func (p *Client) SetCustomDecodeConfig(dc *mapstructure.DecoderConfig)
- func (p *Client) SetCustomTarget(target string)
- func (p *Client) Websocket(query string, options ...Option) *Subscription
- func (p *Client) WebsocketOnce(query string, resp any, options ...Option) error
- func (p *Client) WebsocketWithPayload(query string, initPayload map[string]any, options ...Option) *Subscription
- type Option
- func AddCookie(cookie *http.Cookie) Option
- func AddHeader(key, value string) Option
- func BasicAuth(username, password string) Option
- func Extensions(extensions map[string]any) Option
- func Operation(name string) Option
- func Path(url string) Option
- func Var(name string, value any) Option
- func WithFiles() Option
- type RawJsonError
- type Request
- type Response
- type SSE
- type SSEResponse
- type Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client used for testing GraphQL servers. Not for production use.
func New ¶
New creates a graphql client Options can be set that should be applied to all requests made with this client
func (*Client) MustPost ¶
MustPost is a convenience wrapper around Post that automatically panics on error
func (*Client) Post ¶
Post sends a http POST request to the graphql endpoint with the given query then unpacks the response into the given object.
func (*Client) RawPost ¶ added in v0.6.0
RawPost is similar to Post, except it skips decoding the raw json response unpacked onto Response. This is used to test extension keys which are not available when using Post.
func (*Client) SetCustomDecodeConfig ¶ added in v0.17.33
func (p *Client) SetCustomDecodeConfig(dc *mapstructure.DecoderConfig)
SetCustomDecodeConfig sets a custom decode hook for the client
func (*Client) SetCustomTarget ¶ added in v0.17.56
SetCustomTarget sets a custom target path for the client
func (*Client) Websocket ¶
func (p *Client) Websocket(query string, options ...Option) *Subscription
func (*Client) WebsocketOnce ¶ added in v0.10.0
Grab a single response from a websocket based query
func (*Client) WebsocketWithPayload ¶ added in v0.6.0
type Option ¶
type Option func(bd *Request)
Option implements a visitor that mutates an outgoing GraphQL request
This is the Option pattern - https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
func AddHeader ¶ added in v0.10.0
AddHeader adds a header to the outgoing request. This is useful for setting expected Authentication headers for example.
func Extensions ¶ added in v0.15.0
Extensions sets the extensions to be sent with the outgoing request
type RawJsonError ¶
type RawJsonError struct {
json.RawMessage
}
RawJsonError is a json formatted error from a GraphQL server.
func (RawJsonError) Error ¶
func (r RawJsonError) Error() string
type Request ¶
type Request struct { Query string `json:"query"` Variables map[string]any `json:"variables,omitempty"` OperationName string `json:"operationName,omitempty"` Extensions map[string]any `json:"extensions,omitempty"` HTTP *http.Request `json:"-"` }
Request represents an outgoing GraphQL request
type Response ¶ added in v0.10.0
type Response struct { Data any Errors json.RawMessage Extensions map[string]any }
Response is a GraphQL layer response from a handler.