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(GraphQL): This PR extend int64 range to 64-bit numeric values and adds input coercing and validation for integers. #6275

Merged
merged 24 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d9892f8
added validation and test for out of range
JatinDev543 Aug 26, 2020
31d12ac
modified test
JatinDev543 Aug 26, 2020
9489906
add int64 validation and added tests
JatinDev543 Aug 26, 2020
96c7b9f
fixe formatting
JatinDev543 Aug 26, 2020
a33e567
fixed test by adding schema
JatinDev543 Aug 27, 2020
cbf0c56
Merge branch 'master' of github.com:dgraph-io/dgraph into jatin/graph…
JatinDev543 Aug 27, 2020
7085ca8
clean up code
JatinDev543 Aug 27, 2020
e23e1ae
fixed test
JatinDev543 Aug 27, 2020
820309a
fixed antipattern error
JatinDev543 Aug 27, 2020
b8826dd
Merge branch 'master' of github.com:dgraph-io/dgraph into jatin/graph…
JatinDev543 Aug 27, 2020
23bffbd
moved predicates in json output file a bit
JatinDev543 Aug 27, 2020
acc700d
corrected tests and added check
JatinDev543 Aug 28, 2020
6ef3ef8
full 64-bit range support for Int64
abhimanyusinghgaur Aug 28, 2020
c324d28
added tests,modified validation
JatinDev543 Aug 28, 2020
bf88eb3
fixed tests and modified code
JatinDev543 Sep 1, 2020
d32a70a
fixed output coercing for resolver tests
JatinDev543 Sep 2, 2020
9962657
resolved abhimanyu's comments.
JatinDev543 Sep 2, 2020
3d2de0d
changed formatting a bit
JatinDev543 Sep 2, 2020
e8fd9ab
Merge branch 'master' of github.com:dgraph-io/dgraph into jatin/graph…
JatinDev543 Sep 2, 2020
d1bd6ff
added missed test
JatinDev543 Sep 3, 2020
d8ab759
fuxed schemagen error
JatinDev543 Sep 3, 2020
5de04f1
unexported valueKindToString functions
JatinDev543 Sep 3, 2020
93742d3
Merge branch 'master' of github.com:dgraph-io/dgraph into jatin/graph…
JatinDev543 Sep 3, 2020
13c3275
changed documentation message for int64
JatinDev543 Sep 3, 2020
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
19 changes: 19 additions & 0 deletions graphql/e2e/common/error_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,22 @@
[ { "message": "Cannot query field \"getAuthor\" on type \"Subscription\".",
"locations": [ { "line": 2, "column": 3 } ] } ]

-
name: "Out of range error for int type"
gqlrequest: |
mutation {
addPost(input:[{title:"Dgraph",author:{name:"Bob"},numLikes:2147483648}]){
post{
title
numLikes
author{
name
}
}
}
}
gqlvariables:
{ }
errors:
[ { "message": "Out of range value '2147483648', for Variable type `Int`",
"locations": [ { "line": 2, "column": 63 } ] } ]
1 change: 1 addition & 0 deletions graphql/schema/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func init() {

validator.AddRule("Check variable type is correct", variableTypeCheck)
validator.AddRule("Check for list type value", listTypeCheck)
validator.AddRule("Check range for Int type", intRangeCheck)

}

Expand Down
26 changes: 26 additions & 0 deletions graphql/schema/validation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package schema
import (
"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/validator"
"math"
"strconv"
)

func listTypeCheck(observers *validator.Events, addError validator.AddErrFunc) {
Expand Down Expand Up @@ -63,3 +65,27 @@ func variableTypeCheck(observers *validator.Events, addError validator.AddErrFun
value.ExpectedType.String()), validator.At(value.Position))
})
}

func intRangeCheck(observers *validator.Events, addError validator.AddErrFunc) {
observers.OnValue(func(walker *validator.Walker, value *ast.Value) {
if value.Definition == nil || value.ExpectedType == nil {
return
}

if value.Kind != ast.IntValue || value.Definition.Name != "Int" {
return
}

intVal, err := strconv.ParseInt(value.Raw, 10, 64)
if err != nil {
addError(validator.Message("%s", err))
return
}
if intVal <= math.MaxInt32 && intVal >= math.MinInt32 {
return
}

addError(validator.Message("Out of range value '%s', for Variable type `%s`",
value.Raw, value.Definition.Name), validator.At(value.Position))
})
}