start of wiring for configurable context
This commit is contained in:
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user