Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/machinebox/graphql
Simple low-level GraphQL HTTP client for Go
https://github.com/machinebox/graphql
client godoc golang graphql machinebox sdk
Last synced: about 1 month ago
JSON representation
Simple low-level GraphQL HTTP client for Go
- Host: GitHub
- URL: https://github.com/machinebox/graphql
- Owner: machinebox
- License: apache-2.0
- Created: 2017-12-06T20:04:19.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T22:57:01.000Z (11 months ago)
- Last Synced: 2024-02-19T15:39:36.104Z (10 months ago)
- Topics: client, godoc, golang, graphql, machinebox, sdk
- Language: Go
- Homepage: https://blog.machinebox.io/a-graphql-client-library-for-go-5bffd0455878
- Size: 57.6 KB
- Stars: 919
- Watchers: 12
- Forks: 211
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-graphql - machinebox/graphql - Simple low-level GraphQL client for Go (Libraries / Go Libraries)
- awesome-ccamel - machinebox/graphql - Simple low-level GraphQL HTTP client for Go (Go)
- awesome-graphql - machinebox/graphql - Simple low-level GraphQL client for Go (Libraries / Go Libraries)
README
# graphql [![GoDoc](https://godoc.org/github.com/machinebox/graphql?status.png)](http://godoc.org/github.com/machinebox/graphql) [![Build Status](https://travis-ci.org/machinebox/graphql.svg?branch=master)](https://travis-ci.org/machinebox/graphql) [![Go Report Card](https://goreportcard.com/badge/github.com/machinebox/graphql)](https://goreportcard.com/report/github.com/machinebox/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/machinebox/graphql
```## Usage
```go
import "context"// create a client (safe to share across requests)
client := graphql.NewClient("https://machinebox.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://machinebox.io/graphql", graphql.UseMultipartForm())
```For more information, [read the godoc package documentation](http://godoc.org/github.com/machinebox/graphql) or the [blog post](https://blog.machinebox.io/a-graphql-client-library-for-go-5bffd0455878).
## Thanks
Thanks to [Chris Broadfoot](https://github.com/broady) for design help.