graphQL

package
v0.0.0-...-549aca6 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

GraphQL is a simple low-level client modified from https://github.com/machinebox/graphql

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Endpoint  string
	Http      *http.Client
	MultiForm bool
	Logs      func(s string)
}

Client is a struct used to interact with any general GraphQL API

func MakeClient

func MakeClient(endpoint string, options ...ClientOption) *Client

MakeNewClient makes a new Client capable of making GraphQL requests.

func (*Client) JsonQuery

func (c *Client) JsonQuery(ctx context.Context, req *Request, resp interface{}) error

func (*Client) PostRequest

func (c *Client) PostRequest(ctx context.Context, req *Request, resp interface{}) error

func (*Client) Run

func (c *Client) Run(ctx context.Context, req *Request, resp interface{}) error

Run executes the query and unmarshals the response from the data field into the response object. Pass in a nil response object to skip response parsing. If the request fails or the server returns an error, the first

error will be returned.

type ClientOption

type ClientOption func(*Client)

ClientOptions is function used to modify Client behaviour

func SetMultiForm

func SetMultiForm() ClientOption

type File

type File struct {
	Name      string
	Reader    io.Reader
	Variables string
}

File is used to upload to api

type GraphError

type GraphError struct {
	Message string
}

func (GraphError) Error

func (e GraphError) Error() string

type GraphResponse

type GraphResponse struct {
	Data   interface{}
	Errors []GraphError
}

type Request

type Request struct {
	Query     string
	Variables map[string]interface{}
	Files     []File
	Header    http.Header
}

Request is a GraphQL struct containing info used for post request.

func MakeRequest

func MakeRequest(query string) *Request

NewRequest makes a new Request with a json string.

func (*Request) SetFields

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

SetFields is a method to define info fields we want to query

func (*Request) UploadFile

func (req *Request) UploadFile(data, filename string, reader io.Reader)

Jump to

Keyboard shortcuts

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