Low-level GraphQL client for Go.
- Simple, familiar API
- Respects
context.Context
timeouts and cancallation - Build and execute any kind of GraphQL request
- Use strong Go types for response data
- Use variables and upload files
- Simple error handling
// create a client (safe to share across requests)
ctx := context.Background()
client, err := graphql.NewClient(ctx, "https://machinebox.io/graphql")
if err != nil {
log.Fatal(err)
}
// 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)
}