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 issue #160: validateVarType parsing numbers #162

Closed
wants to merge 1 commit into from
Closed

fix issue #160: validateVarType parsing numbers #162

wants to merge 1 commit into from

Conversation

f10et
Copy link
Contributor

@f10et f10et commented Sep 2, 2021

This is to fix issue #160, which I run into as well.

When we find a variable which is json.Number, depending on the variable type request, we'll extract either the Int64 value, or the float value from the json.Number.

This should work well with gqlgen, which uses the json decoder UseNumber function to decode numbers.

https://github.com/99designs/gqlgen/blob/master/graphql/handler/transport/http_get.go#L76

Let me know if I can help make it any better, or if you have any better solution for this problem.

if v.Type.NamedType == "Int" {
n, err := jsonNumber.Int64()
if err != nil {
return nil, gqlerror.ErrorPathf(validator.path, "cannot use value %s as %s", n, v.Type.NamedType)
Copy link

@si3nloong si3nloong Sep 30, 2021

Choose a reason for hiding this comment

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

I see you have typo here, it should be

gqlerror.ErrorPathf(validator.path, "cannot use value %d as %s", n, v.Type.NamedType)

Because n is not a string, it's a int64

@StevenACoffman
Copy link
Collaborator

Rebased (and fixed typo per @si3nloong comment) in #216 so closing

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