Skip to content

Commit

Permalink
Merge pull request 99designs#77 from vektah/opentracing
Browse files Browse the repository at this point in the history
Add resolver middleware Add opentracing support
  • Loading branch information
vektah authored Apr 6, 2018
2 parents 990b3c8 + 6aaba8a commit 5bfdacd
Show file tree
Hide file tree
Showing 20 changed files with 885 additions and 146 deletions.
1 change: 1 addition & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"sort": ["path"],
"Deadline": "2m",
"Linters": {
"errcheck": {
"Command": "errcheck -abspath -ignore '[rR]ead|[wW]rite|Close'",
Expand Down
92 changes: 91 additions & 1 deletion Gopkg.lock

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

4 changes: 2 additions & 2 deletions codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func (f *Field) CallArgs() string {
}
}

for i := range f.Args {
args = append(args, "arg"+strconv.Itoa(i))
for _, arg := range f.Args {
args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")")
}

return strings.Join(args, ", ")
Expand Down
2 changes: 2 additions & 0 deletions codegen/templates/args.gotpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if . }}args := map[string]interface{}{} {{end}}
{{- range $i, $arg := . }}
var arg{{$i}} {{$arg.Signature }}
if tmp, ok := field.Args[{{$arg.GQLName|quote}}]; ok {
Expand Down Expand Up @@ -25,4 +26,5 @@
}
}
{{end }}
args[{{$arg.GQLName|quote}}] = arg{{$i}}
{{- end -}}
4 changes: 2 additions & 2 deletions codegen/templates/data.go

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

14 changes: 12 additions & 2 deletions codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,22 @@
}
{{- end }}
{{- else }}
rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})
res, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})
rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Object: {{$object.GQLType|quote}},
Args: {{if $field.Args }}args{{else}}nil{{end}},
Field: field,
})
resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) {
return ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})
})
if err != nil {
ec.Error(err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.({{$field.Signature}})
{{- end }}
{{ $field.WriteJson }}
{{- if $field.IsConcurrent }}
Expand Down
Loading

0 comments on commit 5bfdacd

Please sign in to comment.