-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get all request fields from query #954
Comments
Ok, I've resolved this Updated examples 11 May 2020: New PR for: query {
flowBlocks {
id
block {
id
title
type
choices {
id
title
description
slug
}
}
}
} We don't want to overfetch our database so we want to know which field are requested. func GetPreloads(ctx context.Context) []string {
return GetNestedPreloads(
graphql.GetOperationContext(ctx),
graphql.CollectFieldsCtx(ctx, nil),
"",
)
}
func GetNestedPreloads(ctx *graphql.OperationContext, fields []graphql.CollectedField, prefix string) (preloads []string) {
for _, column := range fields {
prefixColumn := GetPreloadString(prefix, column.Name)
preloads = append(preloads, prefixColumn)
preloads = append(preloads, GetNestedPreloads(ctx, graphql.CollectFields(ctx, column.Selections, nil), prefixColumn)...)
}
return
}
func GetPreloadString(prefix, name string) string {
if len(prefix) > 0 {
return prefix + "." + name
}
return name
} So if we call these helpers in our resolver: func (r *queryResolver) FlowBlocks(ctx context.Context) ([]*FlowBlock, error) {
preloads := getPreloads(ctx) it will result in the following string slice:
|
@vektah I think a lot of people want something like this, maybe we could describe this in the documentation? |
Related: #746 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@vektah I've made a pull request for this :) |
Based on this 99designs#954 was tagged as 'need documentation'
What happened?
I'm using https://relay.dev/ as client library where you can put data inside fragments to structure your query more logically.
This is query Relay executes.
I called
It returned:
What did you expect?
I expected at least
And even better something like this:
Minimal graphql.schema and models to reproduce
versions
v0.10.2-dev
go version go1.13 darwin/amd64
github.com/99designs/gqlgen v0.10.2
The text was updated successfully, but these errors were encountered: