Skip to content

ubgo/gqlutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gqlutil GitHub license

A small sets of useful function for gqlgen.com grqphql module.

Installation

go get github.com/ubgo/gqlutil

Example Query (Check output from each functin below)

query {
  user {
    id
    firstName
    genres {
      id
      name
    }
  }
}

GetPreloads(ctx context.Context) []string

get the fields requested as json keys

gqlutil.GetPreloads(ctx)

// output: [id firstName genres][id User.id firstName User.firstName genres User.genres genres.id Genre.id genres.name Genre.name]

GetFieldsRequested(ctx context.Context) []string

get the fields requested in a graphql query Useful for constructing SQL queries from the GraphQL query

gqlutil.GetFieldsRequested(ctx)

// output: [id firstName genres]

GetParentFieldsRequested(ctx context.Context) []string

this get the same as above, but for use within the field resolver. So in the field resolver if we didn't get a field we can grab what was requested above and load it. Check this link https://gqlgen.com/reference/resolvers/#binding-priority

  • Useful for lazy resolving data
  • NB this will panic if there is no parent.
gqlutil.GetParentFieldsRequested(ctx)

Contribute

If you would like to contribute to the project, please fork it and send us a pull request. Please add tests for any new features or bug fixes.

Stay in touch

License

goutil is MIT licensed.

About

A small sets of useful function for http://gqlgen.com grqphql module.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages