From 2bf0030e9269e605296b89833d9832e2bf0de1cc Mon Sep 17 00:00:00 2001 From: mdrakos Date: Wed, 13 Nov 2024 11:43:14 -0800 Subject: [PATCH 1/4] Debug test --- internal/testhelpers/e2e/env.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/testhelpers/e2e/env.go b/internal/testhelpers/e2e/env.go index 38cb7cb14b..7270368d84 100644 --- a/internal/testhelpers/e2e/env.go +++ b/internal/testhelpers/e2e/env.go @@ -40,6 +40,7 @@ func sandboxedTestEnvironment(t *testing.T, dirs *Dirs, updatePath bool, extraEn constants.ServiceSockDir + "=" + dirs.SockRoot, constants.HomeEnvVarName + "=" + dirs.HomeDir, systemHomeEnvVarName + "=" + dirs.HomeDir, + constants.DebugServiceRequestsEnvVarName + "=true", "NO_COLOR=true", "CI=true", }...) From 8ef7da780754695e985177a3fb1c7e538940eea4 Mon Sep 17 00:00:00 2001 From: mdrakos Date: Wed, 13 Nov 2024 12:58:51 -0800 Subject: [PATCH 2/4] Apply same unmarshalling to gqlclient --- internal/gqlclient/gqlclient.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/gqlclient/gqlclient.go b/internal/gqlclient/gqlclient.go index 273a6e7b5a..a9589bc51f 100644 --- a/internal/gqlclient/gqlclient.go +++ b/internal/gqlclient/gqlclient.go @@ -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())) @@ -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) } From 9f1af8ed3e65f195dc5c4bfbe6dc7e85e3b2403e Mon Sep 17 00:00:00 2001 From: mdrakos Date: Wed, 13 Nov 2024 13:11:13 -0800 Subject: [PATCH 3/4] Remove debug code --- internal/testhelpers/e2e/env.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/testhelpers/e2e/env.go b/internal/testhelpers/e2e/env.go index 7270368d84..38cb7cb14b 100644 --- a/internal/testhelpers/e2e/env.go +++ b/internal/testhelpers/e2e/env.go @@ -40,7 +40,6 @@ func sandboxedTestEnvironment(t *testing.T, dirs *Dirs, updatePath bool, extraEn constants.ServiceSockDir + "=" + dirs.SockRoot, constants.HomeEnvVarName + "=" + dirs.HomeDir, systemHomeEnvVarName + "=" + dirs.HomeDir, - constants.DebugServiceRequestsEnvVarName + "=true", "NO_COLOR=true", "CI=true", }...) From 2ecd5c7ace6628e7f2e94d3266fbf32793ef3ce7 Mon Sep 17 00:00:00 2001 From: mdrakos Date: Thu, 14 Nov 2024 10:02:10 -0800 Subject: [PATCH 4/4] Add comment --- internal/gqlclient/gqlclient.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/gqlclient/gqlclient.go b/internal/gqlclient/gqlclient.go index a9589bc51f..d9e4c1ae60 100644 --- a/internal/gqlclient/gqlclient.go +++ b/internal/gqlclient/gqlclient.go @@ -373,6 +373,8 @@ func (c *Client) runWithFiles(ctx context.Context, gqlReq RequestWithFiles, resp return errors.Wrap(err, "decoding response") } + // If the response is a single object, meaning we only have a single query in the request, we can unmarshal the + // response directly to the response type. Otherwise, we need to marshal the response as we normally would. if len(intermediateResp) == 1 { for _, val := range intermediateResp { data, err := json.Marshal(val)