https://github.com/infinityworks/graphql
Graphql Client for Golang
https://github.com/infinityworks/graphql
golang graphql graphql-client
Last synced: 5 months ago
JSON representation
Graphql Client for Golang
- Host: GitHub
- URL: https://github.com/infinityworks/graphql
- Owner: infinityworks
- License: apache-2.0
- Created: 2019-12-12T16:23:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-12T16:48:12.000Z (over 6 years ago)
- Last Synced: 2024-11-15T12:44:52.808Z (over 1 year ago)
- Topics: golang, graphql, graphql-client
- Language: Go
- Size: 61.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql [](http://godoc.org/github.com/infinityworks/graphql) [](https://travis-ci.org/infinityworks/graphql) [](https://goreportcard.com/report/github.com/infinityworks/graphql)
Low-level GraphQL client for Go.
* 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
## Installation
Make sure you have a working Go environment. To install graphql, simply run:
```
$ go get github.com/infinityworks/graphql
```
## Usage
```go
import "context"
// create a client (safe to share across requests)
client := graphql.NewClient("https://infinityworks.io/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("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. To enable the sending of files, you can opt to
use multipart form data instead using the `UseMultipartForm` option when you create your `Client`:
```
client := graphql.NewClient("https://infinityworks.io/graphql", graphql.UseMultipartForm())
```
For more information, [read the godoc package documentation](http://godoc.org/github.com/infinityworks/graphql) or the [blog post](https://blog.machinebox.io/a-graphql-client-library-for-go-5bffd0455878).
## Thanks
Thanks to [Machinebox](https://github.com/machinebox/graphql) for their original
work on this library pre-fork.
Thanks to [Chris Broadfoot](https://github.com/broady) for design help.