Documentation ¶
Overview ¶
Package graphqlc provides a low level GraphQL client.
// create a client (safe to share across requests) client := graphqlc.NewClient("https://machinebox.io/graphql") // make a request req := graphqlc.NewRequest(` query ($key: String!) { items (id:$key) { field1 field2 field3 } } `) //(optional) set your own http client client.HttpClient = http.DefaultClient //(optional) set any variables req.Var("key", "value") // run it and capture the response var respData ResponseStruct if err := client.Run(ctx, req, &respData); err != nil { log.Fatal(err) }
Index ¶
- type Client
- func (c *Client) Run(req *Request) error
- func (c *Client) RunCtx(ctx context.Context, req *Request) error
- func (c *Client) RunCtxRet(ctx context.Context, req *Request, resp interface{}) error
- func (c *Client) RunRet(req *Request, resp interface{}) error
- func (c *Client) Subscribe(ctx context.Context, req *Request, notifications chan SubscriptionEvent)
- type ClientOption
- type File
- type Request
- type SubscriptionEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.2.0
type Client struct { //The graphql server endpoint. Endpoint string //net/http client used to make requests. HttpClient *http.Client // closeReq will close the request body immediately allowing for reuse of client CloseReq bool // Log is called with various debug information. // To log to standard out, use: // client.Log = func(s string) { log.Println(s) } Log func(s string) //Determines the default http request headers for graphql queries. //If your graphql request has headers that contradict these, the //graphql request headers will take precedence. http.Header }
Client is a client for interacting with a GraphQL API.
func NewClient ¶ added in v0.2.0
func NewClient(endpoint string, opts ...ClientOption) *Client
NewClient makes a new Client capable of making GraphQL requests.
func (*Client) RunCtxRet ¶ added in v0.2.7
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. Pass in a channel for resp if the request a synchronization request in order to get updates. If the request fails or the server returns an error, the first error encountered will be returned.
type ClientOption ¶ added in v0.2.0
type ClientOption func(*Client)
ClientOption are functions that are passed into NewClient to modify the behaviour of the Client.
type Request ¶
type Request struct { // Header represent any request headers that will be set // when the request is made. Header http.Header // contains filtered or unexported fields }
Request is a GraphQL request.
func NewRequest ¶
NewRequest makes a new Request with the specified string.
func (*Request) File ¶
File sets a file to upload. Files are only supported with a Client that was created with the UseMultipartForm option.