A small sets of useful function for gqlgen.com grqphql module.
go get github.com/ubgo/gqlutil
query {
user {
id
firstName
genres {
id
name
}
}
}
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]
get the fields requested in a graphql query Useful for constructing SQL queries from the GraphQL query
gqlutil.GetFieldsRequested(ctx)
// output: [id firstName genres]
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)
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.
- Author - Aman Khanakia
- Website - https://khanakia.com
goutil is MIT licensed.