gqlgen: github.com/99designs/gqlgen/client Index | Files

package client

import "github.com/99designs/gqlgen/client"

Index

Package Files

client.go errors.go options.go websocket.go

type Client Uses

type Client struct {
    // contains filtered or unexported fields
}

Client used for testing GraphQL servers. Not for production use.

func New Uses

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 Uses

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 Uses

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 Uses

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

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

func (*Client) WebsocketOnce Uses

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

Grab a single response from a websocket based query

func (*Client) WebsocketWithPayload Uses

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

type Option Uses

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 Uses

func AddCookie(cookie *http.Cookie) Option

AddCookie adds a cookie to the outgoing request

func AddHeader Uses

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 Uses

func BasicAuth(username, password string) Option

BasicAuth authenticates the request using http basic auth.

func Operation Uses

func Operation(name string) Option

Operation sets the operation name for the outgoing request

func Path Uses

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 Uses

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

Var adds a variable into the outgoing request

type RawJsonError Uses

type RawJsonError struct {
    json.RawMessage
}

RawJsonError is a json formatted error from a GraphQL server.

func (RawJsonError) Error Uses

func (r RawJsonError) Error() string

type Request Uses

type Request struct {
    Query         string                 `json:"query"`
    Variables     map[string]interface{} `json:"variables,omitempty"`
    OperationName string                 `json:"operationName,omitempty"`
    HTTP          *http.Request          `json:"-"`
}

Request represents an outgoing GraphQL request

type Response Uses

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

Response is a GraphQL layer response from a handler.

type Subscription Uses

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

Package client imports 9 packages (graph) and is imported by 2 packages. Updated 2019-09-25. Refresh now. Tools for package owners.