golangQL
golangQL allows you to use graphQL syntactics to select fields from json
-tagged Golang structs.
Description
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.
Features
All filter functions are cached, for field structs also, so if you request
{
name {
firstName
lastName
}
nephews {
name {
firstName
}
hat
}
it also will cache
{
nephews {
name {
firstName
}
}
{
name {
firstName
lastName
}
}
{
name {
firstName
}
}
requests for the relevant types.
Installation
To install the library, run:
go get github.com/ngalayko/golangQL