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

support input object directive #1525

Merged
merged 2 commits into from
Sep 8, 2021
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
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 @@ -420,7 +425,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.