You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Respects context.Context timeouts and cancellation
Build and execute any kind of GraphQL request
Use strong Go types for response data
Use variables and upload files
Simple error handling
Installation
Make sure you have a working Go environment. To install graphql, simply run:
$ go get github.com/machinebox/graphql
Usage
import"context"// create a client (safe to share across requests)client:=graphql.NewClient("https://machinebox.io/graphql")
// make a requestreq:=graphql.NewRequest(` query ($key: String!) { items (id:$key) { field1 field2 field3 } }`)
// set any variablesreq.Var("key", "value")
// set header fieldsreq.Header.Set("Cache-Control", "no-cache")
// define a Context for the requestctx:=context.Background()
// run it and capture the responsevarrespDataResponseStructiferr:=client.Run(ctx, req, &respData); err!=nil {
log.Fatal(err)
}
File support via multipart form data
By default, the package will send a JSON body. To enable the sending of files, you can opt to
use multipart form data instead using the UseMultipartForm option when you create your Client: