client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const OK = 0

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 GraphREST 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) Delete

func (p *Client) Delete(target 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) Get

func (p *Client) Get(target 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) MustDelete

func (p *Client) MustDelete(target string, response interface{}, options ...Option)

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

func (*Client) MustGet

func (p *Client) MustGet(target string, response interface{}, options ...Option)

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

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

func (p *Client) MustPut(target string, response interface{}, options ...Option)

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

func (*Client) Post

func (p *Client) Post(target 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) Put

func (p *Client) Put(target 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) RawRequest

func (p *Client) RawRequest(method string, target 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.

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

func AddCookie(cookie *http.Cookie) Option

AddCookie adds a cookie to the outgoing request

func AddHeader

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

func BasicAuth(username, password string) Option

BasicAuth authenticates the request using http basic auth.

func Body

func Body(payload string) Option

Operation sets the operation name for the outgoing request

func Prefix

func Prefix(urlPrefix string) Option

Prefix 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.

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 {
	HTTP *http.Request
}

Request represents an outgoing GraphQL request

type Response

type Response struct {
	Code    int
	Message string
	Data    interface{}
}

Response is a GraphQL layer response from a handler.

Jump to

Keyboard shortcuts

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