Skip to content

Commit edea822

Browse files
authored
Fix incorrect validation of zero float value (#547)
Float value of 0.0 is valid. Removed the incorrect if condition. Added a test. Fixes #546
1 parent 882dba2 commit edea822

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

internal/validation/testdata/tests.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,13 @@
15251525
}
15261526
]
15271527
},
1528+
{
1529+
"name": "Validate: Default Float variable set to zero",
1530+
"rule": "DefaultValuesOfCorrectType",
1531+
"schema": 0,
1532+
"query": "\n query Foo($a: Float = 0.0) {\n field(a: $a)\n }\n ",
1533+
"errors": []
1534+
},
15281535
{
15291536
"name": "Validate: No invalid default Float variable values/value out of range",
15301537
"rule": "DefaultValuesOfCorrectType",

internal/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ func validateBuiltInScalar(v string, n string) bool {
895895
return f >= math.MinInt32 && f <= math.MaxInt32
896896
case "Float":
897897
f, fe := strconv.ParseFloat(v, 64)
898-
return fe == nil && f >= math.SmallestNonzeroFloat64 && f <= math.MaxFloat64
898+
return fe == nil && f <= math.MaxFloat64
899899
case "String":
900900
vl := len(v)
901901
return vl >= 2 && v[0] == '"' && v[vl-1] == '"'

0 commit comments

Comments
 (0)