The following code won't work
var query any
// imagine a switch-case pattern here which dynamically decides what the query actually is
query = struct {
Hero struct {
Name graphql.String
Droid struct {
PrimaryFunction graphql.String
} `graphql:"... on Droid"`
Human struct {
Height graphql.Float
} `graphql:"... on Human"`
} `graphql:"hero(episode: \"JEDI\")"`
}{}
err := a.client.Query(context.Background(), &query, nil)
The request body will look like {"query":""}. I set a query string in the graphql tag, it would appear here - but the requested fields etc. would still be missing.
The problem is probably that the type of query is now interface{} | struct {...} (or interface{} | HeroQuery with an explicit type declaration), and only type interface{} is regarded.
Edit: I had a look into the code. Seems like you only process reflect.Ptr, reflect.Type and reflect.Struct in the function writeQuery. The kind here is (pointer to) interface{}. Reflection is such a pain in Go. :/