graphql

package
v0.1.21812 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT, Apache-2.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Debug    bool
	Endpoint string
	Host     string
	Token    string
	// contains filtered or unexported fields
}

A Client is an HTTP client for our GraphQL endpoint.

func NewClient

func NewClient(httpClient *http.Client, host, endpoint, token string, debug bool) *Client

NewClient returns a reference to a Client.

func (*Client) Reset

func (cl *Client) Reset(host, endpoint, token string, debug bool)

Reset replaces the existing fields with out creating a new client instance

func (*Client) Run

func (cl *Client) Run(request *Request, resp interface{}) error

Run sends an HTTP request to the GraphQL server and deserializes the response or returns an error. TODO(zzak): This function is fairly complex, we should refactor it nolint: gocyclo

type Request

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

	// Header represent any request headers that will be set
	// when the request is made.
	Header http.Header `json:"-"`
}

Request is a GraphQL request.

func NewRequest

func NewRequest(query string) *Request

NewRequest returns a new GraphQL request.

func (*Request) Encode

func (request *Request) Encode() (bytes.Buffer, error)

Encode will return a buffer of the JSON encoded request body

func (*Request) SetToken

func (request *Request) SetToken(token string)

SetToken sets the Authorization header for the request with the given token.

func (*Request) Var

func (request *Request) Var(key string, value interface{})

Var sets a variable.

type Response

type Response struct {
	Data   interface{}
	Errors ResponseErrorsCollection
}

Response wraps the result from our GraphQL server response including out-of-band errors and the data itself.

type ResponseError

type ResponseError struct {
	Message   string
	Locations []struct {
		Line   int
		Column int
	}
	Extensions struct {
		Field         string
		Argument      string
		Value         string
		AllowedValues []string `json:"allowed-values"`
		EnumType      string   `json:"enum-type"`
	}
}

ResponseError represents the key-value pair of data returned by the GraphQL server to represent errors.

type ResponseErrorsCollection

type ResponseErrorsCollection []ResponseError

ResponseErrorsCollection represents a slice of errors returned by the GraphQL server out-of-band from the actual data.

func (ResponseErrorsCollection) Error

func (errs ResponseErrorsCollection) Error() string

Error turns a ResponseErrorsCollection into an acceptable error string that can be printed to the user.

Jump to

Keyboard shortcuts

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