genql: quick hack at variables

This commit is contained in:
Ben Kraft
2020-01-02 17:52:55 -08:00
parent 77670363d3
commit 9746c818fd
7 changed files with 111 additions and 30 deletions
+10 -3
View File
@@ -9,10 +9,17 @@ import (
{{range .Operations}}
type {{.ResponseName}} = {{.ResponseType}}
// {{.OperationDoc}}
func {{.OperationName}}(ctx context.Context, client *graphql.Client) (*{{.ResponseName}}, error) {
// {{.Doc}}
func {{.Name}}(ctx context.Context, client *graphql.Client{{range .Args}}, {{.GoName}} {{.GoType}}{{end}}) (*{{.ResponseName}}, error) {
{{if .Args}}
variables := map[string]interface{}{
{{range .Args}}
"{{.GraphQLName}}": {{.GoName}},
{{end}}
}
{{end}}
var retval {{.ResponseName}}
err := client.MakeRequest(ctx, `{{.Operation}}`, &retval)
err := client.MakeRequest(ctx, `{{.Body}}`, &retval, {{if .Args}}variables{{else}}nil{{end}})
return &retval, err
}
{{end}}