golangQL allows you to use graphQL syntactics to select fields from json-tagged Golang structs.
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.
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.
To install the library, run:
go get github.com/ngalayko/golangQL