Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add obj to Directives #314

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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