set opname

This commit is contained in:
Ben Kraft
2021-03-30 11:27:43 -07:00
parent e3f6afeb78
commit 2c52314494
17 changed files with 23 additions and 2 deletions
+6 -2
View File
@@ -40,6 +40,7 @@ type Client interface {
// (Errors are returned.) But again, MakeRequest may customize this.
MakeRequest(
ctx context.Context,
opName string,
query string,
retval interface{},
variables map[string]interface{},
@@ -68,10 +69,12 @@ func NewClient(endpoint string, httpClient *http.Client) Client {
return &client{endpoint, http.MethodPost, httpClient}
}
// TODO: set OperationName?
type payload struct {
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
// OpName is only required if there are multiple queries in the document,
// but we set it unconditionally, because that's easier.
OpName string `json:"operationName"`
}
type response struct {
@@ -79,10 +82,11 @@ type response struct {
Errors gqlerror.List `json:"errors"`
}
func (c *client) MakeRequest(ctx context.Context, query string, retval interface{}, variables map[string]interface{}) error {
func (c *client) MakeRequest(ctx context.Context, opName string, query string, retval interface{}, variables map[string]interface{}) error {
body, err := json.Marshal(payload{
Query: query,
Variables: variables,
OpName: opName,
})
if err != nil {
return err