Skip to content

Commit

Permalink
Apply same unmarshalling to gqlclient
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Nov 13, 2024
1 parent 2bf0030 commit 8ef7da7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/gqlclient/gqlclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ func (c *Client) runWithFiles(ctx context.Context, gqlReq RequestWithFiles, resp
logging.Debug("gqlclient: response: %s", responseData)
}

intermediateResp := make(map[string]interface{})
gr := &graphResponse{
Data: response,
Data: &intermediateResp,
}
req = req.WithContext(ctx)
c.Log(fmt.Sprintf(">> Raw Request: %s\n", req.URL.String()))
Expand Down Expand Up @@ -371,5 +372,20 @@ func (c *Client) runWithFiles(ctx context.Context, gqlReq RequestWithFiles, resp
if err := json.Unmarshal(resp, &gr); err != nil {
return errors.Wrap(err, "decoding response")
}
return nil

if len(intermediateResp) == 1 {
for _, val := range intermediateResp {
data, err := json.Marshal(val)
if err != nil {
return errors.Wrap(err, "remarshaling response")
}
return json.Unmarshal(data, response)
}
}

data, err := json.Marshal(intermediateResp)
if err != nil {
return errors.Wrap(err, "remarshaling response")
}
return json.Unmarshal(data, response)
}

0 comments on commit 8ef7da7

Please sign in to comment.