Skip to content

Commit

Permalink
fix go syntax issue when field has 2 directives
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Aug 13, 2019
1 parent 6b70be0 commit cc9fe14
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codegen/directives.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{- end }}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs $in $i }})
}
{{- end -}}
{{ end -}}
{{ end }}

{{define "queryDirectives"}}
Expand Down
3 changes: 3 additions & 0 deletions codegen/testserver/directive.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION
directive @custom on ARGUMENT_DEFINITION
directive @logged(id: UUID!) on FIELD
directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION
directive @directive1 on FIELD_DEFINITION
directive @directive2 on FIELD_DEFINITION

extend type Query {
directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String
Expand All @@ -13,6 +15,7 @@ extend type Query {
directiveObject: ObjectDirectives
directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid")
directiveField: String
directiveDouble: String @directive1 @directive2
}

input InputDirectives {
Expand Down
21 changes: 21 additions & 0 deletions codegen/testserver/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func TestDirectives(t *testing.T) {
return nil, nil
}

resolvers.QueryResolver.DirectiveDouble = func(ctx context.Context) (*string, error) {
s := "Ok"
return &s, nil
}

srv := httptest.NewServer(
handler.GraphQL(
NewExecutableSchema(Config{
Expand Down Expand Up @@ -126,6 +131,12 @@ func TestDirectives(t *testing.T) {
ToNull: func(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) {
return nil, nil
},
Directive1: func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
return next(ctx)
},
Directive2: func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
return next(ctx)
},
},
}),
handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
Expand Down Expand Up @@ -206,6 +217,16 @@ func TestDirectives(t *testing.T) {
require.EqualError(t, err, `[{"message":"not valid","path":["directiveFieldDef"]}]`)
})

t.Run("has 2 directives", func(t *testing.T) {
var resp struct {
DirectiveDouble string
}

c.MustPost(`query { directiveDouble }`, &resp)

require.Equal(t, "Ok", resp.DirectiveDouble)
})

t.Run("ok", func(t *testing.T) {
var resp struct {
DirectiveFieldDef string
Expand Down
89 changes: 89 additions & 0 deletions codegen/testserver/generated.go

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

3 changes: 3 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func (r *queryResolver) DirectiveFieldDef(ctx context.Context, ret string) (stri
func (r *queryResolver) DirectiveField(ctx context.Context) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) DirectiveDouble(ctx context.Context) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) {
panic("not implemented")
}
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/stub.go

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

1 change: 1 addition & 0 deletions example/todo/generated.go

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

1 change: 1 addition & 0 deletions example/type-system-extension/generated.go

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

0 comments on commit cc9fe14

Please sign in to comment.