client

package
v0.0.0-...-bf77483 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 13 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 {
	BaseURL            string
	Client             *http.Client
	HTTPRequestOptions []HTTPRequestOption
	Authorization      ClientAuthorization
}

Client is the http client wrapper

func NewClient

func NewClient(options ClientOptions) *Client

NewClient creates a new http client wrapper

func (*Client) Post

func (c *Client) Post(ctx context.Context, operationName, query string, respData interface{}, vars map[string]interface{}, httpRequestOptions ...HTTPRequestOption) error

Post sends a http POST request to the graphql endpoint with the given query then unpacks the response into the given object.

type ClientAuthorization

type ClientAuthorization struct {
	CognitoIdentityProvider *cognito.CognitoIdentityProvider
	ClientID                string
	UserPoolID              string
	Username                string
	Password                string
}

type ClientAuthorizationOptions

type ClientAuthorizationOptions struct {
	Session    *session.Session
	ClientID   string
	UserPoolID string
	Username   string
	Password   string
}

type ClientOptions

type ClientOptions struct {
	HTTPClient           *http.Client
	HTTPRequestOptions   []HTTPRequestOption
	BaseURL              string
	AuthorizationOptions ClientAuthorizationOptions
}

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 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 HTTPRequestOption

type HTTPRequestOption func(req *http.Request)

HTTPRequestOption represents the options applicable to the http client

type Request

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

Request represents an outgoing GraphQL request

Jump to

Keyboard shortcuts

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