Documentation ¶
Overview ¶
Package graphql provides a low level GraphQL client.
// create a client (safe to share across requests) client := graphql.NewClient("https://machinebox.io/graphql") // make a request req := graphql.NewRequest(` query ($key: String!) { items (id:$key) { field1 field2 field3 } } `) // 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) }
Specify client ¶
To specify your own http.Client, use the WithHTTPClient option:
httpclient := &http.Client{} client := graphql.NewClient("https://machinebox.io/graphql", graphql.WithHTTPClient(httpclient))
Index ¶
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 {
// contains filtered or unexported fields
}
Client is a client for accessing a GraphQL dataset.
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) Run ¶ added in v0.2.0
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. Use IsGraphQLErr to determine which it was.
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.
func WithHTTPClient ¶ added in v0.2.0
func WithHTTPClient(httpclient *http.Client) ClientOption
WithHTTPClient specifies the underlying http.Client to use when making requests.
NewClient(endpoint, WithHTTPClient(specificHTTPClient))