clean up various TODOs and comments
This commit is contained in:
+7
-13
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user