start of wiring for configurable context

This commit is contained in:
Ben Kraft
2021-03-22 19:09:17 -07:00
parent 17a95fd4de
commit 59ca841a6b
19 changed files with 56 additions and 51 deletions
+7 -3
View File
@@ -3,7 +3,9 @@ package {{.Config.Package}}
// Code generated by github.com/Khan/genql, DO NOT EDIT.
import (
"context"
{{- if .Config.ContextType -}}
"{{.Config.ContextPackage}}"
{{end}}
{{- if .ImportJSON -}}
"encoding/json"
{{end}}
@@ -11,11 +13,13 @@ import (
"github.com/Khan/genql/graphql"
)
{{/* TODO: type-assert that your ctx type implements context.Context */}}
{{.Types}}
{{range .Operations}}
{{.Doc}}
func {{.Name}}({{if $.Config.UseContext}}ctx context.Context, {{end}}client *graphql.Client{{range .Args}}, {{.GoName}} {{.GoType}}{{end}}) (*{{.ResponseName}}, error) {
func {{.Name}}({{if $.Config.ContextType}}ctx {{$.Config.ContextType}}, {{end}}client *graphql.Client{{range .Args}}, {{.GoName}} {{.GoType}}{{end}}) (*{{.ResponseName}}, error) {
{{- if .Args -}}
variables := map[string]interface{}{
{{range .Args -}}
@@ -24,7 +28,7 @@ func {{.Name}}({{if $.Config.UseContext}}ctx context.Context, {{end}}client *gra
}
{{end}}
var retval {{.ResponseName}}
err := client.MakeRequest({{if $.Config.UseContext}}ctx{{else}}context.Background(){{end}}, `{{.Body}}`, &retval, {{if .Args}}variables{{else}}nil{{end}})
err := client.MakeRequest({{if $.Config.ContextType}}ctx{{else}}nil{{end}}, `{{.Body}}`, &retval, {{if .Args}}variables{{else}}nil{{end}})
return &retval, err
}
{{end}}