clean up various TODOs and comments

This commit is contained in:
Ben Kraft
2021-03-22 18:11:51 -07:00
parent 463e3ed319
commit a42c9b8166
12 changed files with 62 additions and 59 deletions
+7 -13
View File
@@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/vektah/gqlparser/gqlerror"
@@ -29,8 +28,12 @@ type payload struct {
Variables map[string]interface{} `json:"variables"`
}
type response struct {
Data json.RawMessage `json:"data"`
Errors gqlerror.List `json:"errors"`
}
func (client *Client) MakeRequest(ctx context.Context, query string, retval interface{}, variables map[string]interface{}) error {
// TODO: streaming reads and writes
body, err := json.Marshal(payload{
Query: query,
Variables: variables,
@@ -54,21 +57,12 @@ func (client *Client) MakeRequest(ctx context.Context, query string, retval inte
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("returned error %v: %v", resp.Status, string(body))
}
var dataAndErrors struct {
Data json.RawMessage `json:"data"`
Errors gqlerror.List `json:"errors"`
}
err = json.Unmarshal(body, &dataAndErrors)
var dataAndErrors response
err = json.NewDecoder(resp.Body).Decode(&dataAndErrors)
if err != nil {
return err
}