Skip to content

Commit

Permalink
Fix pointer returns from directive
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Jun 30, 2019
1 parent 21b6511 commit beaa2ae
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions codegen/args.gotpl
Expand Up @@ -14,6 +14,10 @@ func (ec *executionContext) {{ $name }}(ctx context.Context, rawArgs map[string]
}
if data, ok := tmp.({{ $arg.TypeReference.GO | ref }}) ; ok {
arg{{$i}} = data
{{- if $arg.TypeReference.IsNilable }}
} else if tmp == nil {
arg{{$i}} = nil
{{- end }}
} else {
return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ $arg.TypeReference.GO }}`, tmp)
}
Expand Down
5 changes: 5 additions & 0 deletions codegen/field.gotpl
Expand Up @@ -107,6 +107,11 @@
if data, ok := tmp.({{ .TypeReference.GO | ref }}) ; ok {
return data, nil
}
{{- if .TypeReference.IsNilable -}}
else if tmp == nil {
return nil, nil
}
{{- end }}
return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ .TypeReference.GO }}`, tmp)
{{- else -}}
ctx = rctx // use context from middleware stack in children
Expand Down
4 changes: 4 additions & 0 deletions codegen/input.gotpl
Expand Up @@ -25,6 +25,10 @@
}
if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok {
it.{{$field.GoFieldName}} = data
{{- if $field.TypeReference.IsNilable }}
} else if tmp == nil {
it.{{$field.GoFieldName}} = nil
{{- end }}
} else {
return it, fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp)
}
Expand Down
6 changes: 6 additions & 0 deletions codegen/testserver/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit beaa2ae

Please sign in to comment.