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 ¶
- func IsClientError(err error) bool
- func IsGraphQLError(err error) bool
- func IsInternalServerError(err error) bool
- func IsInvalidArgumentsError(err error) bool
- func IsInvalidError(err error) bool
- func IsMaintenanceError(err error) bool
- func IsNotFoundError(err error) bool
- func IsServerError(err error) bool
- func IsServiceUnavailableError(err error) bool
- func IsUnauthorizedError(err error) bool
- func IsUnprocessableError(err error) bool
- type Client
- type ClientOption
- type File
- type GraphQLError
- type GraphQLErrorExtensions
- type Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsClientError ¶ added in v0.2.3
func IsGraphQLError ¶ added in v0.2.3
func IsInternalServerError ¶ added in v0.2.3
func IsInvalidArgumentsError ¶ added in v0.2.3
func IsInvalidError ¶ added in v0.2.3
func IsMaintenanceError ¶ added in v0.2.3
func IsNotFoundError ¶ added in v0.2.3
func IsServerError ¶ added in v0.2.3
func IsServiceUnavailableError ¶ added in v0.2.3
func IsUnauthorizedError ¶ added in v0.2.3
func IsUnprocessableError ¶ added in v0.2.3
Types ¶
type Client ¶ added in v0.2.0
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 ¶ added in v0.2.0
func NewClient(endpoint string, opts ...ClientOption) *Client
NewClient makes a new Client capable of making GraphQL requests.
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 ImmediatelyCloseReqBody ¶ added in v0.2.3
func ImmediatelyCloseReqBody() ClientOption
ImmediatelyCloseReqBody will close the req body immediately after each request body is ready
func UseMultipartForm ¶ added in v0.2.2
func UseMultipartForm() ClientOption
UseMultipartForm uses multipart/form-data and activates support for files.
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))
type GraphQLError ¶ added in v0.2.3
type GraphQLError struct { Message string Path []string Extensions GraphQLErrorExtensions // contains filtered or unexported fields }
func (*GraphQLError) Error ¶ added in v0.2.3
func (gqlErr *GraphQLError) Error() string
type GraphQLErrorExtensions ¶ added in v0.2.3
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.