Skip to content

Commit b97540c

Browse files
authored
Merge pull request #3591 from ActiveState/DX-3160
Fix Publish Integration Test
2 parents bc92b12 + 2ecd5c7 commit b97540c

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

internal/gqlclient/gqlclient.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)