Skip to content

Commit

Permalink
Merge pull request 99designs#314 from 99designs/directive-obj
Browse files Browse the repository at this point in the history
Add obj to Directives
  • Loading branch information
vektah authored Aug 24, 2018
2 parents df8c6c8 + e35812f commit 87315f4
Show file tree
Hide file tree
Showing 19 changed files with 567 additions and 579 deletions.
4 changes: 2 additions & 2 deletions codegen/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Directive struct {
}

func (d *Directive) CallArgs() string {
args := []string{"ctx", "n"}
args := []string{"ctx", "obj", "n"}

for _, arg := range d.Args {
args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")")
Expand All @@ -22,7 +22,7 @@ func (d *Directive) CallArgs() string {
}

func (d *Directive) Declaration() string {
res := ucFirst(d.Name) + " func(ctx context.Context, next graphql.Resolver"
res := ucFirst(d.Name) + " func(ctx context.Context, obj interface{}, next graphql.Resolver"

for _, arg := range d.Args {
res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature())
Expand Down
4 changes: 2 additions & 2 deletions codegen/templates/data.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Field: field,
}
ctx = graphql.WithResolverContext(ctx, rctx)
resTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
resTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(ctx context.Context) (interface{}, error) {
{{- if $field.IsResolver }}
return ec.resolvers.{{ $field.ShortInvocation }}
{{- else if $field.IsMethod }}
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/generated.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type executionContext struct {
{{ template "input.gotpl" $input }}
{{- end }}

func (ec *executionContext) FieldMiddleware(ctx context.Context, next graphql.Resolver) (ret interface{}) {
func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
Expand Down
120 changes: 60 additions & 60 deletions codegen/testserver/generated.go

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions example/chat/generated.go

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions example/config/generated.go

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions example/dataloader/generated.go

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions example/scalars/generated.go

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions example/selection/generated.go

Large diffs are not rendered by default.

146 changes: 73 additions & 73 deletions example/starwars/generated.go

Large diffs are not rendered by default.

Loading

0 comments on commit 87315f4

Please sign in to comment.