Documentation ¶
Overview ¶
Package gqlclient provides a low level GraphQL client.
// create a client (safe to share across requests) client := gqlclient.NewClient("http://localhost:4000/graphql") // to specify your own http.Client, use the WithHTTPClient option: customHttpClient := &http.Client{} customClient := gqlclient.NewClient("http://localhost:4000/graphql", gqlclient.WithHTTPClient(customHttpClient)) // make a request req := gqlclient.NewRequest(` query { items { field1 field2 field3 } } `) // make a request with variables req := gqlclient.NewRequest(` query ($key: String!) { items (id:$key) { field1 field2 field3 } } `).WithVars(map[string]interface{}{ "key": "value", }) // run it and capture the response var responseData map[string]interface{} res, err := client.Run(ctx, req, &responseData) if err != nil { log.Fatal(err) } // read the cookies in the response cookies := res.Cookies()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // 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) // contains filtered or unexported fields }
Client is a client for interacting with a GraphQL API.
func NewClient ¶
func NewClient(endpoint string, opts ...ClientOption) *Client
NewClient makes a new Client, optimized for GraphQL requests.
func (*Client) HttpClient ¶
HttpClient gets the underlying http.Client.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption are functions that are passed into NewClient to modify the behaviour of the Client.
func ImmediatelyCloseReqBody ¶
func ImmediatelyCloseReqBody() ClientOption
ImmediatelyCloseReqBody will close the req body immediately after each request body is ready
func UseMultipartForm ¶
func UseMultipartForm() ClientOption
UseMultipartForm uses multipart/form-data and activates support for files.
func WithHTTPClient ¶
func WithHTTPClient(httpclient *http.Client) ClientOption
WithHTTPClient specifies the underlying http.Client to use when making requests.
NewClient(endpoint, WithHTTPClient(specificHTTPClient))
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 struct.
func NewRequest ¶
NewRequest makes a new Request with the specified string as query.
func (*Request) File ¶
File sets a file to upload. Files are only supported with a Client that was created with the UseMultipartForm option.
client := gqlclient.NewClient(URL, gqlclient.UseMultipartForm())