Skip to content

Query and Mutation methods ignore query content when it's wrapped in an interface #117

@JonasDoe

Description

@JonasDoe

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. :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions