Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ddliu/go-gqlclient

A simple Graphql client for Golang
https://github.com/ddliu/go-gqlclient

apollo client graphql mutation query

Last synced: 15 days ago
JSON representation

A simple Graphql client for Golang

Awesome Lists containing this project

README

        

# go-gqlclient

A simple Graphql client for Golang.

## Install

```
go get -u github.com/ddliu/go-gqlclient
```

## Usage

```go
import (
"github.com/ddliu/go-gqlclient"
"net/http"
"context"
)

client = gqlclient.New(gqlclient.Options{
Endpoint: "http://server/graphql",
Header: http.Header{
"some-secret": []string{"secret string"},
},
})

data, err := client.Query(context.Background(), `
query MyQuery {
post {
id
name
}
}
`, nil)

print(data.String("post.0.name"))

// Unmarshal data
var posts []Post
data.Unmarshal(&posts)
```

With variables:

```go
client.Query(context.Background(), `
query MyQuery($limit: Int) {
post(limit: $limit) {
id
name
}
}
`, map[string]interface{} {
"limit": 10,
})
```

Check out [fractal](https://github.com/ddliu/fractal) for more information of the query result.