@@ -312,8 +312,9 @@ func (c *Client) runWithFiles(ctx context.Context, gqlReq RequestWithFiles, resp
312312 logging .Debug ("gqlclient: response: %s" , responseData )
313313 }
314314
315+ intermediateResp := make (map [string ]interface {})
315316 gr := & graphResponse {
316- Data : response ,
317+ Data : & intermediateResp ,
317318 }
318319 req = req .WithContext (ctx )
319320 c .Log (fmt .Sprintf (">> Raw Request: %s\n " , req .URL .String ()))
@@ -371,5 +372,22 @@ func (c *Client) runWithFiles(ctx context.Context, gqlReq RequestWithFiles, resp
371372 if err := json .Unmarshal (resp , & gr ); err != nil {
372373 return errors .Wrap (err , "decoding response" )
373374 }
374- return nil
375+
376+ // If the response is a single object, meaning we only have a single query in the request, we can unmarshal the
377+ // response directly to the response type. Otherwise, we need to marshal the response as we normally would.
378+ if len (intermediateResp ) == 1 {
379+ for _ , val := range intermediateResp {
380+ data , err := json .Marshal (val )
381+ if err != nil {
382+ return errors .Wrap (err , "remarshaling response" )
383+ }
384+ return json .Unmarshal (data , response )
385+ }
386+ }
387+
388+ data , err := json .Marshal (intermediateResp )
389+ if err != nil {
390+ return errors .Wrap (err , "remarshaling response" )
391+ }
392+ return json .Unmarshal (data , response )
375393}
0 commit comments