repositorypackage
0.2.7
Repository: https://github.com/leonardacademy/graphqlc.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
graphqlc

Low-level GraphQL client for Go. This project was forked from machinebox's repo and includes some breaking changes, so some assembly is required if you are migrating from there.
- Simple, familiar API
- 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
- (Coming soon!) Subscriptions
Installation
Make sure you have a working Go environment. To install graphql, simply run:
$ go get github.com/leonardacademy/graphqlc
Usage
import "context"
// create a client (safe to share across requests)
client := graphqlc.NewClient("https://machinebox.io/graphql")
// make a request
req := graphqlc.NewRequest(`
query ($key: String!) {
items (id:$key) {
field1
field2
field3
}
}
`)
// set any variables
req.Var("key", "value")
// set header fields
req.Header.Set("Cache-Control", "no-cache")
// 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)
}
File support via multipart form data
By default, the package will send a JSON body. When files are included, the package transparently uses multipart form data instead.
For more information, read the godoc package documentation
Thanks
Thanks to Machinebox for creating the initial plugin.