Skip to content

Commit

Permalink
Merge pull request #359 from 99designs/fix-null-arg-error
Browse files Browse the repository at this point in the history
Fix Issue With Argument Pointer Type
  • Loading branch information
Mathew Byrne authored Oct 2, 2018
2 parents ee86271 + 48724de commit 1cae19b
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 66 deletions.
1 change: 0 additions & 1 deletion codegen/directive_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (cfg *Config) buildDirectives(types NamedTypes) ([]*Directive, error) {
if err != nil {
return nil, errors.Errorf("default value for directive argument %s(%s) is not valid: %s", dir.Name, arg.Name, err.Error())
}
newArg.StripPtr()
}
args = append(args, newArg)
}
Expand Down
1 change: 0 additions & 1 deletion codegen/object_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func (cfg *Config) buildObject(types NamedTypes, typ *ast.Definition, imports *I
if err != nil {
return nil, errors.Errorf("default value for %s.%s is not valid: %s", typ.Name, field.Name, err.Error())
}
newArg.StripPtr()
}
args = append(args, newArg)
}
Expand Down
31 changes: 0 additions & 31 deletions codegen/testserver/element.go

This file was deleted.

77 changes: 75 additions & 2 deletions codegen/testserver/generated.go

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

14 changes: 14 additions & 0 deletions codegen/testserver/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ func TestGeneratedServer(t *testing.T) {
sub.Close()
})
})

t.Run("null args", func(t *testing.T) {
var resp struct {
NullableArg *string
}
err := c.Post(`query { nullableArg(arg: null) }`, &resp)
require.Nil(t, err)
require.Equal(t, "Ok", *resp.NullableArg)
})
}

func TestResponseExtension(t *testing.T) {
Expand Down Expand Up @@ -227,6 +236,11 @@ func (r *testQueryResolver) User(ctx context.Context, id int) (User, error) {
return User{ID: 1}, nil
}

func (r *testQueryResolver) NullableArg(ctx context.Context, arg *int) (*string, error) {
s := "Ok"
return &s, nil
}

func (r *testResolver) Subscription() SubscriptionResolver {
return &testSubscriptionResolver{r}
}
Expand Down
3 changes: 3 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (r *queryResolver) Valid(ctx context.Context) (string, error) {
func (r *queryResolver) User(ctx context.Context, id int) (User, error) {
panic("not implemented")
}
func (r *queryResolver) NullableArg(ctx context.Context, arg *int) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) {
panic("not implemented")
}
Expand Down
1 change: 1 addition & 0 deletions codegen/testserver/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Query {
errorBubble: Error
valid: String!
user(id: Int!): User!
nullableArg(arg: Int = 123): String
}

type Subscription {
Expand Down
17 changes: 11 additions & 6 deletions example/scalars/generated.go

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

2 changes: 1 addition & 1 deletion example/scalars/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *queryResolver) User(ctx context.Context, id external.ObjectID) (*model.
}, nil
}

func (r *queryResolver) Search(ctx context.Context, input model.SearchArgs) ([]model.User, error) {
func (r *queryResolver) Search(ctx context.Context, input *model.SearchArgs) ([]model.User, error) {
location := model.Point{X: 1, Y: 2}
if input.Location != nil {
location = *input.Location
Expand Down
Loading

0 comments on commit 1cae19b

Please sign in to comment.