Skip to content

Commit

Permalink
Merge pull request #1525 from Code-Hex/fix/support-input-object
Browse files Browse the repository at this point in the history
support input object directive
  • Loading branch information
lwc authored Sep 8, 2021
2 parents 1e2b303 + 91b5478 commit 5048f99
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 15 deletions.
8 changes: 7 additions & 1 deletion codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func (b *builder) bindField(obj *Object, f *Field) (errret error) {
if err != nil {
errret = err
}
for _, dir := range obj.Directives {
if dir.IsLocation(ast.LocationInputObject) {
dirs = append(dirs, dir)
}
}
f.Directives = append(dirs, f.Directives...)
}
}()
Expand Down Expand Up @@ -421,7 +426,8 @@ func (f *Field) ImplDirectives() []*Directive {
loc = ast.LocationInputFieldDefinition
}
for i := range f.Directives {
if !f.Directives[i].Builtin && f.Directives[i].IsLocation(loc, ast.LocationObject) {
if !f.Directives[i].Builtin &&
(f.Directives[i].IsLocation(loc, ast.LocationObject) || f.Directives[i].IsLocation(loc, ast.LocationInputObject)) {
d = append(d, f.Directives[i])
}
}
Expand Down
3 changes: 2 additions & 1 deletion 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 @directive3 on INPUT_OBJECT
directive @unimplemented on FIELD_DEFINITION
directive @order1(location: String!) repeatable on FIELD_DEFINITION | OBJECT
directive @order2(location: String!) on OBJECT
Expand All @@ -30,7 +31,7 @@ extend type Subscription {
directiveUnimplemented: String @unimplemented
}

input InputDirectives {
input InputDirectives @directive3 {
text: String! @length(min: 0, max: 7, message: "not valid")
nullableText: String @toNull
inner: InnerDirectives!
Expand Down
3 changes: 3 additions & 0 deletions codegen/testserver/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func TestDirectives(t *testing.T) {
Directive2: func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
return next(ctx)
},
Directive3: func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
return next(ctx)
},
Order1: func(ctx context.Context, obj interface{}, next graphql.Resolver, location string) (res interface{}, err error) {
order := []string{location}
res, err = next(ctx)
Expand Down
78 changes: 67 additions & 11 deletions codegen/testserver/generated.go

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

18 changes: 16 additions & 2 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 5048f99

Please sign in to comment.