clientv2

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 16 Imported by: 63

Documentation

Index

Constants

View Source
const (
	// EnableInputJsonOmitemptyTagKey is a context key for EnableInputJsonOmitemptyTag
	EnableInputJsonOmitemptyTagKey contextKey = "enable_input_json_omitempty_tag"
)

Variables

This section is empty.

Functions

func MarshalJSON added in v0.20.0

func MarshalJSON(ctx context.Context, v any) ([]byte, error)

func WithEnableInputJsonOmitemptyTag added in v0.29.0

func WithEnableInputJsonOmitemptyTag(ctx context.Context, enable bool) context.Context

WithEnableInputJsonOmitemptyTag returns a new context with EnableInputJsonOmitemptyTag value

Types

type Client

type Client struct {
	Client                     HttpClient
	BaseURL                    string
	RequestInterceptor         RequestInterceptor
	CustomDo                   RequestInterceptorFunc
	ParseDataWhenErrors        bool
	IsUnsafeRequestInterceptor bool
}

Client is the http client wrapper

func NewClient

func NewClient(client HttpClient, baseURL string, options *Options, interceptors ...RequestInterceptor) *Client

NewClient creates a new http client wrapper

func NewClientWithUnsafeRequestInterceptor added in v0.27.4

func NewClientWithUnsafeRequestInterceptor(client HttpClient, baseURL string, options *Options, interceptors ...RequestInterceptor) *Client

func (*Client) Post

func (c *Client) Post(ctx context.Context, operationName, query string, respData any, vars map[string]any, interceptors ...RequestInterceptor) error

Post support send multipart form with files https://gqlgen.com/reference/file-upload/ https://github.com/jaydenseric/graphql-multipart-request-spec

type Encoder added in v0.29.0

type Encoder struct {
	EnableInputJsonOmitemptyTag bool
}

Encoder is a struct for encoding GraphQL requests to JSON

func (*Encoder) Encode added in v0.29.0

func (e *Encoder) Encode(v reflect.Value) ([]byte, error)

Encode encodes any value to JSON

type ErrorResponse

type ErrorResponse struct {
	// populated when http status code is not OK
	NetworkError *HTTPError `json:"networkErrors"`
	// populated when http status code is OK but the server returned at least one graphql error
	GqlErrors *gqlerror.List `json:"graphqlErrors"`
}

ErrorResponse represent an handled error

func (*ErrorResponse) Error

func (er *ErrorResponse) Error() string

func (*ErrorResponse) HasErrors

func (er *ErrorResponse) HasErrors() bool

HasErrors returns true when at least one error is declared

type FormField added in v0.11.3

type FormField struct {
	Name  string
	Value any
}

type GQLRequestInfo

type GQLRequestInfo struct {
	Request *Request
}

func NewGQLRequestInfo

func NewGQLRequestInfo(r *Request) *GQLRequestInfo

type GqlErrorList

type GqlErrorList struct {
	Errors gqlerror.List `json:"errors"`
}

GqlErrorList is the struct of a standard graphql error response

func (*GqlErrorList) Error

func (e *GqlErrorList) Error() string

type HTTPError

type HTTPError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

HTTPError is the error when a GqlErrorList cannot be parsed

type HttpClient added in v0.26.0

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
	Post(url, contentType string, body io.Reader) (*http.Response, error)
}

type MultipartFile added in v0.11.3

type MultipartFile struct {
	File  graphql.Upload
	Index int
}

type MultipartFilesGroup added in v0.11.3

type MultipartFilesGroup struct {
	Files      []MultipartFile
	IsMultiple bool
}

type Options added in v0.11.4

type Options struct {
	// ParseDataAlongWithErrors is a flag that indicates whether the client should try to parse and return the data along with error
	// when error appeared. So in the end you'll get list of gql errors and data.
	ParseDataAlongWithErrors bool
}

Options is a struct that holds some client-specific options that can be passed to NewClient.

type Request

type Request struct {
	Query         string         `json:"query"`
	Variables     map[string]any `json:"variables,omitempty"`
	OperationName string         `json:"operationName,omitempty"`
}

Request represents an outgoing GraphQL request

type RequestInterceptor

type RequestInterceptor func(ctx context.Context, req *http.Request, gqlInfo *GQLRequestInfo, res any, next RequestInterceptorFunc) error

func ChainInterceptor

func ChainInterceptor(interceptors ...RequestInterceptor) RequestInterceptor

func UnsafeChainInterceptor added in v0.27.4

func UnsafeChainInterceptor(interceptors ...RequestInterceptor) RequestInterceptor

func WithEnableInputJsonOmitemptyTagInterceptor added in v0.29.0

func WithEnableInputJsonOmitemptyTagInterceptor(enable bool) RequestInterceptor

WithEnableInputJsonOmitemptyTagInterceptor creates a RequestInterceptor that sets EnableInputJsonOmitemptyTag in context

type RequestInterceptorFunc

type RequestInterceptorFunc func(ctx context.Context, req *http.Request, gqlInfo *GQLRequestInfo, res any) error

Jump to

Keyboard shortcuts

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