https://github.com/ngalaiko/golangql
use graphQL syntactics to select fields from json-tagged golang structs to make json api response more compact
https://github.com/ngalaiko/golangql
cache golang graphql json tags
Last synced: 3 months ago
JSON representation
use graphQL syntactics to select fields from json-tagged golang structs to make json api response more compact
- Host: GitHub
- URL: https://github.com/ngalaiko/golangql
- Owner: ngalaiko
- License: apache-2.0
- Created: 2017-04-01T13:23:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-09T08:00:14.000Z (about 9 years ago)
- Last Synced: 2026-01-14T23:51:47.786Z (6 months ago)
- Topics: cache, golang, graphql, json, tags
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# golangQL [](https://travis-ci.org/ngalayko/golangQL)[](https://coveralls.io/github/ngalayko/golangQL?branch=master)[](https://goreportcard.com/report/github.com/ngalayko/golangQL)
golangQL allows you to use [graphQL](http://graphql.org/) syntactics to select fields from `json`-tagged Golang structs.
## Description
```go
func Filter(v interface{}, query string) (interface{}, error)
```
returns an `interface{}` value which actually is a `map[string]interface{}`. Keys of this map are `json`-tags and values are values of struct fields. So result of `json.Marshal(v interface{})` will contain only fields that were described in `graphQL query`. Null values are skipped.
See [example](example/main.go).
## Features
All filter functions are cached, for field structs also, so if you request
```graphQL
{
name {
firstName
lastName
}
nephews {
name {
firstName
}
hat
}
```
it also will cache
```graphQL
{
nephews {
name {
firstName
}
}
```
```graphQL
{
name {
firstName
lastName
}
}
```
```graphQL
{
name {
firstName
}
}
```
requests for the relevant types.
## Installation
To install the library, run:
```bash
go get github.com/ngalayko/golangQL
```