Loading...
There are many GraphQL client written in golang. machinebox/graphql is a Low-level GraphQL client for Go.
This client is,
Make sure you have a working Go environment. To install graphql, simply run:
$ go get github.com/machinebox/graphql
Tip:
Always remember to replace
API_SECRETin the Bearer Token andproject-idin the URL with the correct values from the Apito console.
If you are unsure where to find your API secrets and endpoints for your project, visit this page.
import "context"
// create a client (safe to share across requests)
client := graphql.NewClient("https://api.apito.io/secured/graphql")
// make a request
req := graphql.NewRequest(`
query ($key: String!) {
items (id:$key) {
field1
field2
field3
}
}
`)
// set any variables
req.Var("key", "value")
// set header fields
req.Header.Set("Authorization", "Bearer API_SECRET")
// define a Context for the request
ctx := context.Background()
// run it and capture the response
var respData ResponseStruct
if err := client.Run(ctx, req, &respData); err != nil {
log.Fatal(err)
}