Determine Int's and Float's
jazzfog opened this issue · comments
Hi!
Does this mean that if I pass value 10
it will be declared as Int
in my query, even though on server the field is declared as Float
?
var typeMap = {
string: "String",
number: function (value) {
return value % 1 === 0 ? "Int" : "Float";
},
boolean: "Boolean"
}
Thanks.
Hi!
Can you write a full example?
Thanks!
I actually didn't try, but according to the documentation and source code (if I got everything right) it will define argument as Int
in query even though server could accept only Float
.
For example, on server side I could have an argument rating
declared as GraphQLFloat
So code like this...
var rate = graph.query(`(@autodeclare) {
rating(rating: $rating) {
rating
}
}`)
rate({
rating: 10
})
...will generate this (since value % 1 === 0
):
query ($rating: Int!) {
rating(rating: $rating) {
rating
}
}
Hope it makes sense.
Ah yes,
But there is no Float
/Int
difference in JavaScript (everything is number
)
You can do that:
rate({
"rating!Float": 10
})
generates what you need.
Yes, obviously JS does not have Int
and Float
so this is why I became curious about details of implementation.
I'd say this nuance should be mentioned in the documentation, because it is quite confusing.
Just wrote it to the README: https://github.com/f/graphql.js#solving-integer-and-float-problem
👍