Closed marticrespi closed 5 years ago
Did you ever figure this out? I am also unable to unmarshall my response into my res
object, despite getting the correct HTTP response. The runWithJSON
method in graphql.go
just straight up doesn't deserialize the buffer into my response object correctly and I have no idea why.
I am having a similar issue, deserializing into a map[string]interface{}
shows the field names correctly, but there are no values.
This library has Data structure defined in the response in itself: https://github.com/machinebox/graphql/blob/3a92531802258604bd12793465c2e28bc4b2fc85/graphql.go#L260-L263
which it assigns the "data" object from received json: https://github.com/machinebox/graphql/blob/3a92531802258604bd12793465c2e28bc4b2fc85/graphql.go#L113-L115
So to be able to unmarshal the response to a structure, you need to pass it the Data struct and not the outer, enclosing struct.
In @marticrespi example, remove the enclosing StatsResponse struct and pass Data struct to client.Run:
var res Data
ctx := context.Background()
if err := client.Run(ctx, req, &res); err != nil {
log.Fatal(err)
}
Hi, after a few hours investigating what is happening, I can't find the problem.
Here is my full code, I have used that website to convert a response in struct from a web interface response (playground).
https://mholt.github.io/json-to-go/
I'm always receiving an empty res object, and if I send it through playground works perfectly. What am I doing wrong? Someone can help me?
Many thanks!