graphql

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a generic GraphQL API client.

func NewClient

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

NewClient returns a Client instance.

func (*Client) Post

func (c *Client) Post(header http.Header, request PostRequest) (*Response, error)

Post is a synchronous GraphQL POST request.

func (*Client) PostAsync

func (c *Client) PostAsync(header http.Header, request PostRequest, callback func(*Response, error)) (context.CancelFunc, error)

PostAsync is an asynchronous GraphQL POST request.

type ClientOption

type ClientOption func(*Client)

ClientOption represents options for a generic GraphQL client.

func WithAPIKey

func WithAPIKey(apiKey string) ClientOption

WithAPIKey returns a ClientOption configured with the given API key

func WithCredential

func WithCredential(credential string) ClientOption

WithCredential returns a ClientOption configured with the given credential

func WithHTTPHeader added in v1.4.0

func WithHTTPHeader(header http.Header) ClientOption

WithHTTPHeader returns a ClientOption configured with the given http.Header

func WithHTTPProxy

func WithHTTPProxy(proxy string) ClientOption

WithHTTPProxy returns a ClientOption configured with the given http proxy

func WithMaxElapsedTime

func WithMaxElapsedTime(maxElapsedTime time.Duration) ClientOption

WithMaxElapsedTime returns a ClientOption configured with the given maxElapsedTime

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout returns a ClientOption configured with the given timeout

type PostRequest

type PostRequest struct {
	Query         string           `json:"query"`
	OperationName *string          `json:"operationName"`
	Variables     *json.RawMessage `json:"variables"`
}

PostRequest is a generic GraphQL POST request body.

func (*PostRequest) IsMutation

func (p *PostRequest) IsMutation() bool

IsMutation checks if the Request is "Mutation" or not.

func (*PostRequest) IsQuery

func (p *PostRequest) IsQuery() bool

IsQuery checks if the Request is "Query" or not.

func (*PostRequest) IsSubscription

func (p *PostRequest) IsSubscription() bool

IsSubscription checks if the Request is "Subscription" or not.

type Response

type Response struct {
	StatusCode *int           `json:"statusCode"`
	Data       interface{}    `json:"data"`
	Errors     *[]interface{} `json:"errors"`
	Extensions *interface{}   `json:"extensions"`
}

Response represents a generic GraphQL response body.

func (*Response) DataAs

func (r *Response) DataAs(v interface{}) error

DataAs converts Response.Data to the specified struct

Jump to

Keyboard shortcuts

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