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

fix field schema directives applied to roots #764

Merged
merged 1 commit into from
Jun 27, 2019
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
3 changes: 3 additions & 0 deletions codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ func (f *Field) HasDirectives() bool {
}

func (f *Field) DirectiveObjName() string {
if f.Object.Root {
return "nil"
}
return f.GoReceiverName
}

Expand Down
25 changes: 25 additions & 0 deletions codegen/testserver/directive.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
directive @length(min: Int!, max: Int, message: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | FIELD_DEFINITION
directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION
directive @custom on ARGUMENT_DEFINITION
directive @logged(id: UUID!) on FIELD

extend type Query {
directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String
directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String
directiveInputNullable(arg: InputDirectives): String
directiveInput(arg: InputDirectives!): String
directiveInputType(arg: InnerInput! @custom): String
directiveFieldDef(ret: String!): String! @length(min: 1, message: "not valid")
directiveField: String
}

input InputDirectives {
text: String! @length(min: 0, max: 7, message: "not valid")
inner: InnerDirectives!
innerNullable: InnerDirectives
thirdParty: ThirdParty @length(min: 0, max: 7)
}

input InnerDirectives {
message: String! @length(min: 1, message: "not valid")
}
25 changes: 25 additions & 0 deletions codegen/testserver/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ func TestDirectives(t *testing.T) {
require.Equal(t, "Ok", *resp.DirectiveArg)
})
})
t.Run("field definition directives", func(t *testing.T) {
resolvers.QueryResolver.DirectiveFieldDef = func(ctx context.Context, ret string) (i string, e error) {
return ret, nil
}

t.Run("too short", func(t *testing.T) {
var resp struct {
DirectiveFieldDef string
}

err := c.Post(`query { directiveFieldDef(ret: "") }`, &resp)

require.EqualError(t, err, `[{"message":"not valid","path":["directiveFieldDef"]}]`)
})

t.Run("ok", func(t *testing.T) {
var resp struct {
DirectiveFieldDef string
}

c.MustPost(`query { directiveFieldDef(ret: "aaa") }`, &resp)

require.Equal(t, "aaa", resp.DirectiveFieldDef)
})
})
t.Run("field directives", func(t *testing.T) {
t.Run("add field directive", func(t *testing.T) {
var resp struct {
Expand Down
Loading