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

[Breaking] fix(GRAPHQL): fix input coercing for integers and make them GraphQL spec complaint. #7584

Merged
merged 1 commit into from
Mar 16, 2021
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/dgraph-io/badger/v3 v3.0.0-20210309075542-2245c18dfd1f
github.com/dgraph-io/dgo/v200 v200.0.0-20210212152539-e0a5bde40ba2
github.com/dgraph-io/gqlgen v0.13.2
github.com/dgraph-io/gqlparser/v2 v2.1.8
github.com/dgraph-io/gqlparser/v2 v2.1.9
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed
github.com/dgraph-io/ristretto v0.0.4-0.20210310100713-a4346e5d1f90
github.com/dgraph-io/simdjson-go v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ github.com/dgraph-io/dgo/v200 v200.0.0-20210212152539-e0a5bde40ba2/go.mod h1:zCf
github.com/dgraph-io/gqlgen v0.13.2 h1:TNhndk+eHKj5qE7BenKKSYdSIdOGhLqxR1rCiMso9KM=
github.com/dgraph-io/gqlgen v0.13.2/go.mod h1:iCOrOv9lngN7KAo+jMgvUPVDlYHdf7qDwsTkQby2Sis=
github.com/dgraph-io/gqlparser/v2 v2.1.1/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
github.com/dgraph-io/gqlparser/v2 v2.1.8 h1:d4CprjlDyMNGvnZG/pKqe6Oj6qQd4V0TVsuOIjCKXWQ=
github.com/dgraph-io/gqlparser/v2 v2.1.8/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
github.com/dgraph-io/gqlparser/v2 v2.1.9 h1:rLmGvSY3ZAmHZEWHuus6CrXBLF2Ggdkg+Wu7niqAOUA=
github.com/dgraph-io/gqlparser/v2 v2.1.9/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed h1:pgGMBoTtFhR+xkyzINaToLYRurHn+6pxMYffIGmmEPc=
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed/go.mod h1:7z3c/5w0sMYYZF5bHsrh8IH4fKwG5O5Y70cPH1ZLLRQ=
github.com/dgraph-io/ristretto v0.0.4-0.20210309073149-3836124cdc5a/go.mod h1:MIonLggsKgZLUSt414ExgwNtlOL5MuEoAJP514mwGe8=
Expand Down
20 changes: 10 additions & 10 deletions graphql/e2e/common/error_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,24 @@
} ]

-
name: "String value is Incompatible with Int64 type"
name: "String value is Incompatible with Int32 type given in variable"
gqlrequest: |
mutation {
addPost(input:[{title:"Dgraph",author:{name:"Bob"},numViews:"180143985094"}]){
mutation($numLikes:Int) {
addPost(input:[{title:"Dgraph",author:{name:"Bob"},numLikes:$numLikes}]){
post{
title
numLikes
author{
name
numLikes
author{
name
}
}
}
}
}
gqlvariables: |
{ }
{ "numLikes": "21474836" }
errors:
[ { "message": "Type mismatched for Value `180143985094`, expected: Int64, got: 'String'",
"locations": [ { "line": 2, "column": 64 } ] } ]
[ { "message": "cannot use string as Int",
"path": [ "variable","numLikes" ] } ]

-
name: "Float value is Incompatible with Int64 type"
Expand Down
2 changes: 1 addition & 1 deletion graphql/schema/validation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func intRangeCheck(observers *validator.Events, addError validator.AddErrFunc) {
}
}
case "Int64":
if value.Kind == ast.IntValue {
if value.Kind == ast.IntValue || value.Kind == ast.StringValue {
_, err := strconv.ParseInt(value.Raw, 10, 64)
if err != nil {
if errors.Is(err, strconv.ErrRange) {
Expand Down