b2422452a1
This enables accessing the Extensions field, as defined in the response format: https://spec.graphql.org/October2021/#sec-Response-Format Extensions can be enabled using configuration option use_extensions. This will change the return parameters of the generated client functions. Making it a breaking change if enabled. Since extensions are untyped as defined in the spec, the Client will return an interface of type map[string]interface{}.
47 lines
1.3 KiB
Cheetah
47 lines
1.3 KiB
Cheetah
{{.Doc}}
|
|
func {{.Name}}(
|
|
{{if ne .Config.ContextType "-" -}}
|
|
ctx {{ref .Config.ContextType}},
|
|
{{end}}
|
|
{{- if not .Config.ClientGetter -}}
|
|
client {{ref "github.com/Khan/genqlient/graphql.Client"}},
|
|
{{end}}
|
|
{{- if .Input -}}
|
|
{{- range .Input.Fields -}}
|
|
{{/* the GraphQL name here is the user-specified variable-name */ -}}
|
|
{{.GraphQLName}} {{.GoType.Reference}},
|
|
{{end -}}
|
|
{{end -}}
|
|
) (*{{.ResponseName}}, {{if .Config.Extensions -}}map[string]interface{},{{end}} error) {
|
|
req := &graphql.Request{
|
|
OpName: "{{.Name}}",
|
|
Query: `{{.Body}}`,
|
|
{{if .Input -}}
|
|
Variables: &{{.Input.GoName}}{
|
|
{{range .Input.Fields -}}
|
|
{{.GoName}}: {{.GraphQLName}},
|
|
{{end -}}
|
|
},
|
|
{{end -}}
|
|
}
|
|
var err error
|
|
{{if .Config.ClientGetter -}}
|
|
var client graphql.Client
|
|
|
|
client, err = {{ref .Config.ClientGetter}}({{if ne .Config.ContextType "-"}}ctx{{else}}{{end}})
|
|
if err != nil {
|
|
return nil, {{if .Config.Extensions -}}nil,{{end -}} err
|
|
}
|
|
{{end}}
|
|
var data {{.ResponseName}}
|
|
resp := &graphql.Response{Data: &data}
|
|
|
|
err = client.MakeRequest(
|
|
{{if ne .Config.ContextType "-"}}ctx{{else}}nil{{end}},
|
|
req,
|
|
resp,
|
|
)
|
|
|
|
return &data, {{if .Config.Extensions -}}resp.Extensions,{{end -}} err
|
|
}
|