graphql

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInput         = errors.New("cannot send files with PostFields option")
	ErrCreateVariablesField = errors.New("create variables field")
	ErrEncodeVariablesField = errors.New("encode variables")
	ErrCreateFile           = errors.New("create form file")
	ErrReadBody             = errors.New("read body")
	ErrDecode               = errors.New("decode")
	ErrCopy                 = errors.New("copy")
	ErrRequest              = errors.New("graphql: server returned a non-200 status code")
)

Functions

func NewError

func NewError(err error, wrappedErr error) error

Types

type Client

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

func NewClient

func NewClient(endpoint string, opts ...ClientOption) *Client

NewClient makes a new Client capable of making GraphQL requests.

type ClientOption

type ClientOption func(*Client)

func ImmediatelyCloseReqBody

func ImmediatelyCloseReqBody() ClientOption

ImmediatelyCloseReqBody will close the req body immediately after each request body is ready

func UseMultipartForm

func UseMultipartForm() ClientOption

UseMultipartForm uses multipart/form-data and activates support for files.

func WithHTTPClient

func WithHTTPClient(httpclient HTTPRequestDoer) ClientOption

WithHTTPClient specifies the underlying http.Client to use when making requests.

NewClient(endpoint, WithHTTPClient(specificHTTPClient))

type File

type File struct {
	Field string
	Name  string
	R     io.Reader
}

type GraphError

type GraphError[T any] struct {
	Message    string `json:"message"`
	Extensions T      `json:"extensions"`
}

func (GraphError[T]) Error

func (e GraphError[T]) Error() string

func (GraphError[T]) GetExtensions

func (e GraphError[T]) GetExtensions() T

type GraphqlError

type GraphqlError[T any] interface {
	Message() string
	Error() string
	Extensions() T
}

type HTTPRequestDoer

type HTTPRequestDoer interface {
	Do(r *http.Request) (*http.Response, error)
}

type Query

type Query string

func (Query) String

func (q Query) String() string

type QueryVariables

type QueryVariables map[string]any

type Request

type Request struct {
	Header http.Header
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(q Query) *Request

NewRequest makes a new Request with the specified string.

func (*Request) File

func (req *Request) File(fieldname, filename string, r io.Reader)

File sets a file to upload. Files are only supported with a Client that was created with the UseMultipartForm option.

func (*Request) Files

func (req *Request) Files() []File

Files gets the files in this request.

func (*Request) Query

func (req *Request) Query() Query

Query gets the query string of this request.

func (*Request) Var

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

Var sets a variable.

func (*Request) Vars

func (req *Request) Vars() map[string]interface{}

Vars gets the variables for this Request.

type Requester

type Requester[T any, E any] struct {
	// contains filtered or unexported fields
}

func NewRequester

func NewRequester[T any, E any](client *Client) *Requester[T, E]

func (*Requester[T, E]) Request

func (r *Requester[T, E]) Request(ctx context.Context, req *Request) (Response[T, E], error)

type Response

type Response[T any, E any] struct {
	Data   T               `json:"data"`
	Errors []GraphError[E] `json:"errors"`
}

Jump to

Keyboard shortcuts

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