graphql

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Endpoint *url.URL
	// contains filtered or unexported fields
}

Reusable structure with the required metadata for talking to a GraphQL API. Client should be reused (not reinstantiated) across multiple requests.

func New

func New(endpoint string) (*Client, error)

New instantiates Client for `endpoint`. If you're looking for a way to instantiate Client with custom headers, check out NewWithHeader.

func NewWithHeader

func NewWithHeader(endpoint string, header *http.Header) (*Client, error)

NewWithHeader instantiates Client for `endpoint` with custom headers. If you don't need to specify headers, check out New.

func (*Client) Query

func (c *Client) Query(request *Request) (*Response, error)

Query performs a single GraphQL query and returns its results as a Response.

The returned error does not represent GraphQL errors, those are stored within the Response itself.

func (*Client) QueryMany

func (c *Client) QueryMany(requests []*Request) (chan *Response, chan error)

QueryMany performs multiple GraphQL queries concurrently and returns a channel that will hold their results as Response structures.

The returned errors do not represent GraphQL errors, those are stored within the Responses themselves.

QueryMany is non-blocking, but you should handle that by reading responses from the returned Response channel. The Response channel is closed automatically when all queries are done.

type Request

type Request struct {
	Query     string                 `json:"query"`
	Variables map[string]interface{} `json:"variables"`
}

Request holds the common structure/syntax across all GraphQL requests.

type Response

type Response struct {
	Data   interface{}
	Errors []interface{}
}

Response wraps the common structure/syntax across all GraphQL responses.

Source Files

Jump to

Keyboard shortcuts

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