Skip to content

Commit

Permalink
define implDirectives template
Browse files Browse the repository at this point in the history
  • Loading branch information
asamusev committed Jun 25, 2019
1 parent 56f3f92 commit dd162f0
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 308 deletions.
22 changes: 5 additions & 17 deletions codegen/args.gotpl
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
{{ range $name, $args := .Args }}
func (ec *executionContext) {{ $name }}(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
func (ec *executionContext) {{ $name }}(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
{{- range $i, $arg := . }}
var arg{{$i}} {{ $arg.TypeReference.GO | ref}}
if tmp, ok := rawArgs[{{$arg.Name|quote}}]; ok {
if tmp, ok := in[{{$arg.Name|quote}}]; ok {
{{- if $arg.Directives }}
getArg0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $arg.TypeReference.UnmarshalFunc }}(ctx, tmp) }

{{- range $i, $directive := $arg.Directives }}
getArg{{add $i 1}} := func(ctx context.Context) (res interface{}, err error) {
{{- range $dArg := $directive.Args }}
{{- if and $dArg.TypeReference.IsPtr ( notNil "Value" $dArg ) }}
{{ $dArg.VarName }} := {{ $dArg.Value | dump }}
{{- end }}
{{- end }}
n := getArg{{$i}}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs "tmp" "n" }})
}
{{- end }}

tmp, err = getArg{{$arg.Directives|len}}(ctx)
directive0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $arg.TypeReference.UnmarshalFunc }}(ctx, tmp) }
{{ template "implDirectives" $arg }}
tmp, err = directive{{$arg.Directives|len}}(ctx)
if err != nil {
return nil, err
}
Expand Down
13 changes: 13 additions & 0 deletions codegen/directives.gotpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
{{ define "implDirectives" }}
{{- range $i, $directive := .Directives -}}
directive{{add $i 1}} := func(ctx context.Context) (interface{}, error) {
{{- range $arg := $directive.Args }}
{{- if and $arg.TypeReference.IsPtr ( notNil "Value" $arg ) }}
{{ $arg.VarName }} := {{ $arg.Value | dump }}
{{- end }}
{{- end }}
n := directive{{$i}}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs "in" "n" }})
}
{{- end }}
{{ end }}

{{define "queryDirectives"}}
for _, d := range obj.Directives {
Expand Down
22 changes: 5 additions & 17 deletions codegen/input.gotpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{- range $input := .Inputs }}
{{- if not .HasUnmarshal }}
func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, v interface{}) ({{.Type | ref}}, error) {
func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, in interface{}) ({{.Type | ref}}, error) {
var it {{.Type | ref}}
var asMap = v.(map[string]interface{})
var asMap = in.(map[string]interface{})
{{ range $field := .Fields}}
{{- if $field.Default}}
if _, present := asMap[{{$field.Name|quote}}] ; !present {
Expand All @@ -17,21 +17,9 @@
case {{$field.Name|quote}}:
var err error
{{- if $field.Directives }}
getField0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v) }

{{- range $i, $directive := $field.Directives }}
getField{{add $i 1}} := func(ctx context.Context) (res interface{}, err error) {
{{- range $dArg := $directive.Args }}
{{- if and $dArg.TypeReference.IsPtr ( notNil "Value" $dArg ) }}
{{ $dArg.VarName }} := {{ $dArg.Value | dump }}
{{- end }}
{{- end }}
n := getField{{$i}}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs "it" "n" }})
}
{{- end }}

tmp, err := getField{{$field.Directives|len}}(ctx)
directive0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v) }
{{ template "implDirectives" $field }}
tmp, err := directive{{$field.Directives|len}}(ctx)
if err != nil {
return it, err
}
Expand Down
Loading

0 comments on commit dd162f0

Please sign in to comment.