client

package
v0.17.45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 16 Imported by: 9

README

This client is used internally for testing. I wanted a simple graphql client sent user specified queries.

You might want to look at:

Documentation

Index

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

func New(h http.Handler, opts ...Option) *Client

New creates a graphql client Options can be set that should be applied to all requests made with this client

func (*Client) MustPost

func (p *Client) MustPost(query string, response interface{}, options ...Option)

MustPost is a convenience wrapper around Post that automatically panics on error

func (*Client) Post

func (p *Client) Post(query string, response interface{}, options ...Option) error

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

func (p *Client) RawPost(query string, options ...Option) (*Response, error)

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) SSE added in v0.17.32

func (p *Client) SSE(ctx context.Context, query string, options ...Option) *SSE

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) Websocket

func (p *Client) Websocket(query string, options ...Option) *Subscription

func (*Client) WebsocketOnce added in v0.10.0

func (p *Client) WebsocketOnce(query string, resp interface{}, options ...Option) error

Grab a single response from a websocket based query

func (*Client) WebsocketWithPayload added in v0.6.0

func (p *Client) WebsocketWithPayload(query string, initPayload map[string]interface{}, options ...Option) *Subscription

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 AddCookie added in v0.10.0

func AddCookie(cookie *http.Cookie) Option

AddCookie adds a cookie to the outgoing request

func AddHeader added in v0.10.0

func AddHeader(key string, value string) Option

AddHeader adds a header to the outgoing request. This is useful for setting expected Authentication headers for example.

func BasicAuth added in v0.10.0

func BasicAuth(username, password string) Option

BasicAuth authenticates the request using http basic auth.

func Extensions added in v0.15.0

func Extensions(extensions map[string]interface{}) Option

Extensions sets the extensions to be sent with the outgoing request

func Operation

func Operation(name string) Option

Operation sets the operation name for the outgoing request

func Path added in v0.10.0

func Path(url string) Option

Path sets the url that this request will be made against, useful if you are mounting your entire router and need to specify the url to the graphql endpoint.

func Var

func Var(name string, value interface{}) Option

Var adds a variable into the outgoing request

func WithFiles added in v0.15.0

func WithFiles() Option

WithFiles encodes the outgoing request body as multipart form data for file variables

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]interface{} `json:"variables,omitempty"`
	OperationName string                 `json:"operationName,omitempty"`
	Extensions    map[string]interface{} `json:"extensions,omitempty"`
	HTTP          *http.Request          `json:"-"`
}

Request represents an outgoing GraphQL request

type Response added in v0.10.0

type Response struct {
	Data       interface{}
	Errors     json.RawMessage
	Extensions map[string]interface{}
}

Response is a GraphQL layer response from a handler.

type SSE added in v0.17.32

type SSE struct {
	Close func() error
	Next  func(response interface{}) error
}

type SSEResponse added in v0.17.32

type SSEResponse struct {
	Data       interface{}            `json:"data"`
	Label      string                 `json:"label"`
	Path       []interface{}          `json:"path"`
	HasNext    bool                   `json:"hasNext"`
	Errors     json.RawMessage        `json:"errors"`
	Extensions map[string]interface{} `json:"extensions"`
}

type Subscription

type Subscription struct {
	Close func() error
	Next  func(response interface{}) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL