Skip to content

Commit

Permalink
Merge pull request #122 from vincenteasy/121/fix-wrong-validation-on-…
Browse files Browse the repository at this point in the history
…input-with-default-value

Fix wrong validation on input field with default value
  • Loading branch information
lwc authored Oct 22, 2020
2 parents 0f583e8 + 52681f0 commit df51733
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions validator/testdata/vars.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ input InputType {
nullName: String
nullEmbedded: Embedded
enum: Enum
defaultName: String! = "defaultFoo"
}

input Embedded {
Expand Down
7 changes: 7 additions & 0 deletions validator/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) *gqlerr
field := val.MapIndex(reflect.ValueOf(fieldDef.Name))
if !field.IsValid() {
if fieldDef.Type.NonNull {
if fieldDef.DefaultValue != nil {
var err error
_, err = fieldDef.DefaultValue.Value(nil)
if err == nil {
continue
}
}
return gqlerror.ErrorPathf(v.path, "must be defined")
}
continue
Expand Down

0 comments on commit df51733

Please sign in to comment.