Skip to content

Commit

Permalink
fix bug in OBJECT directive
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ichikawa committed Jul 19, 2020
1 parent 0fbf293 commit 49291f2
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 25 deletions.
2 changes: 1 addition & 1 deletion codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (f *Field) ImplDirectives() []*Directive {
loc = ast.LocationInputFieldDefinition
}
for i := range f.Directives {
if !f.Directives[i].Builtin && f.Directives[i].IsLocation(loc) {
if !f.Directives[i].Builtin && f.Directives[i].IsLocation(loc, ast.LocationObject) {
d = append(d, f.Directives[i])
}
}
Expand Down
7 changes: 4 additions & 3 deletions codegen/testserver/directive.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ directive @toNull on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINI
directive @directive1 on FIELD_DEFINITION
directive @directive2 on FIELD_DEFINITION
directive @unimplemented on FIELD_DEFINITION
directive @order(location: String!) on FIELD_DEFINITION | OBJECT
directive @order1(location: String!) on FIELD_DEFINITION | OBJECT
directive @order2(location: String!) on OBJECT

extend type Query {
directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String
directiveNullableArg(arg: Int @range(min:0), arg2: Int @range, arg3: String @toNull): String
directiveInputNullable(arg: InputDirectives): String
directiveInput(arg: InputDirectives!): String
directiveInputType(arg: InnerInput! @custom): String
directiveObject: ObjectDirectives @order(location: "Query_field")
directiveObject: ObjectDirectives @order1(location: "Query_field")
directiveObjectWithCustomGoModel: ObjectDirectivesWithCustomGoModel
directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid")
directiveField: String
Expand All @@ -41,7 +42,7 @@ input InnerDirectives {
message: String! @length(min: 1, message: "not valid")
}

type ObjectDirectives @order(location: "ObjectDirectives_object") {
type ObjectDirectives @order1(location: "ObjectDirectives_object_1") @order2(location: "ObjectDirectives_object_2") {
text: String! @length(min: 0, max: 7, message: "not valid")
nullableText: String @toNull
order: [String!]!
Expand Down
12 changes: 10 additions & 2 deletions codegen/testserver/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ func TestDirectives(t *testing.T) {
Directive2: func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
return next(ctx)
},
Order: func(ctx context.Context, obj interface{}, next graphql.Resolver, location string) (res interface{}, err error) {
Order1: func(ctx context.Context, obj interface{}, next graphql.Resolver, location string) (res interface{}, err error) {
order := []string{location}
res, err = next(ctx)
od := res.(*ObjectDirectives)
od.Order = append(order, od.Order...)
return od, err
},
Order2: func(ctx context.Context, obj interface{}, next graphql.Resolver, location string) (res interface{}, err error) {
order := []string{location}
res, err = next(ctx)
od := res.(*ObjectDirectives)
Expand Down Expand Up @@ -378,7 +385,8 @@ func TestDirectives(t *testing.T) {
require.Equal(t, "Ok", resp.DirectiveObject.Text)
require.True(t, resp.DirectiveObject.NullableText == nil)
require.Equal(t, "Query_field", resp.DirectiveObject.Order[0])
require.Equal(t, "ObjectDirectives_object", resp.DirectiveObject.Order[1])
require.Equal(t, "ObjectDirectives_object_2", resp.DirectiveObject.Order[1])
require.Equal(t, "ObjectDirectives_object_1", resp.DirectiveObject.Order[2])
})
t.Run("when directive returns nil & custom go field is not nilable", func(t *testing.T) {
var resp struct {
Expand Down
52 changes: 39 additions & 13 deletions codegen/testserver/generated.go

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

72 changes: 66 additions & 6 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 49291f2

Please sign in to comment.