Skip to content

Commit

Permalink
Merge branch 'master' into fix-directive-nil
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Aug 19, 2019
2 parents 94ad3f2 + 8590ede commit f33e09e
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 0 deletions.
12 changes: 12 additions & 0 deletions codegen/directives.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
}
{{- end }}
{{- end }}
if ec.directives.{{$directive.Name|ucFirst}} == nil {
return nil, errors.New("directive {{$directive.Name}} is not implemented")
}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs $in $i }})
}
{{ end -}}
Expand All @@ -34,6 +37,9 @@
{{- end }}
n := next
next = func(ctx context.Context) (interface{}, error) {
if ec.directives.{{$directive.Name|ucFirst}} == nil {
return nil, errors.New("directive {{$directive.Name}} is not implemented")
}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}})
}
{{- end }}
Expand Down Expand Up @@ -81,6 +87,9 @@ func (ec *executionContext) _subscriptionMiddleware(ctx context.Context, obj *as
{{- end }}
n := next
next = func(ctx context.Context) (interface{}, error) {
if ec.directives.{{$directive.Name|ucFirst}} == nil {
return nil, errors.New("directive {{$directive.Name}} is not implemented")
}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}})
}
{{- end }}
Expand Down Expand Up @@ -121,6 +130,9 @@ func (ec *executionContext) _subscriptionMiddleware(ctx context.Context, obj *as
{{- end }}
n := next
next = func(ctx context.Context) (interface{}, error) {
if ec.directives.{{$directive.Name|ucFirst}} == nil {
return nil, errors.New("directive {{$directive.Name}} is not implemented")
}
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}})
}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions codegen/testserver/directive.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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
directive @unimplemented on FIELD_DEFINITION

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

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

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

srv := httptest.NewServer(
handler.GraphQL(
NewExecutableSchema(Config{
Expand Down Expand Up @@ -144,6 +149,7 @@ func TestDirectives(t *testing.T) {
Directive2: func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
return next(ctx)
},
Unimplemented: nil,
},
}),
handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
Expand Down Expand Up @@ -234,6 +240,16 @@ func TestDirectives(t *testing.T) {
require.Equal(t, "Ok", resp.DirectiveDouble)
})

t.Run("directive is not implemented", func(t *testing.T) {
var resp struct {
DirectiveUnimplemented string
}

err := c.Post(`query { directiveUnimplemented }`, &resp)

require.EqualError(t, err, `[{"message":"directive unimplemented is not implemented","path":["directiveUnimplemented"]}]`)
})

t.Run("ok", func(t *testing.T) {
var resp struct {
DirectiveFieldDef string
Expand Down
123 changes: 123 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 @@ -179,6 +179,9 @@ func (r *queryResolver) DirectiveField(ctx context.Context) (*string, error) {
func (r *queryResolver) DirectiveDouble(ctx context.Context) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) DirectiveUnimplemented(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
Loading

0 comments on commit f33e09e

Please sign in to comment.