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 bug and delete String of Int and Float #205

Merged
merged 11 commits into from
Apr 10, 2022

Conversation

pjmd89
Copy link
Contributor

@pjmd89 pjmd89 commented Mar 8, 2022

repair error "cannot use float64 as Int" issue #204 and delete string into Int and Float

return val, nil
}
case "Float":
if kind == reflect.String || kind == reflect.Float32 || kind == reflect.Float64 || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 {
if kind == reflect.Float32 || kind == reflect.Float64 || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why you removed the kind == reflect.String condition as "45.230343" strings are often how they are serialized.

Copy link
Contributor Author

@pjmd89 pjmd89 Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests return an error because you are giving a string to an Int.

I removed the string from the int and float because if you set a variable as int or float you should get an int or a float, not a string, in fact, I got errors for that too. I hope it is useful for something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still, adding the string without removing the validation on the Int, there is no problem. the bad thing is that it can return a string in an int or float.

@StevenACoffman
Copy link
Collaborator

With this change, the tests fail with:

--- FAIL: TestValidateVars (0.01s)
    --- FAIL: TestValidateVars/Scalars (0.00s)
        --- FAIL: TestValidateVars/Scalars/Json_Number_->_Int (0.00s)
            vars_test.go:290: 
                	Error Trace:	vars_test.go:290
                	Error:      	Expected nil, but got: &gqlerror.Error{err:error(nil), Message:"cannot use string as Int", Path:ast.Path{"variable", "var"}, Locations:[]gqlerror.Location(nil), Extensions:map[string]interface {}(nil), Rule:""}
                	Test:       	TestValidateVars/Scalars/Json_Number_->_Int
FAIL

@coveralls
Copy link

coveralls commented Mar 27, 2022

Coverage Status

Coverage decreased (-0.1%) to 92.29% when pulling 441e566 on pjmd89:fixbug/validator into 14b8f03 on vektah:master.

@@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

. "github.com/vektah/gqlparser/v2/ast"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, can you fix this back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

@StevenACoffman
Copy link
Collaborator

So there was a small performance regression with your changes that I corrected by short circuiting for the most common cases. Thanks!

@StevenACoffman StevenACoffman merged commit 815d602 into vektah:master Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants