I was recently confronted with the following issue with my project and was stunned:
{
"data": {},
"errors": [
{
"message": "could not unmarshal 210 (float64) into int32: incompatible type"
}
]
}
I was like "What? That is definitely an integer that I'm passing, how, what, why?" So I dug a bit in the code looking where the error originated from. It originated from internal/exec/packer/packer.go#unmarshalInput. It turns out that it does not accept int types for model properties, you instead have to use int32 because GraphQL uses 32-bit integers for Int. This is an understandable choice, but could this be documented in the README or elsewhere? That'd clear this weird error up for future people. Or could the error perhaps be something along the lines of:
incompatible type, are you using int32 types and not int types in your structs?
In short, you'd have to replace the following in your structs:
type Event struct {
- Seconds int
+ Seconds int32
}
Maybe we need a better (actionable) error message in this case. Or validation during schema parse time.
+1, I just spent a couple minutes trying to figure this out. I'd imagine this causes confusion for almost everyone at least once.
Should be a quick change to: https://github.com/graph-gophers/graphql-go/blob/master/internal/exec/resolvable/resolvable.go#L180-L198
It's actually already pretty well documented in the specification, but that error message would throw anyone off. So I'd opt for changing the error message, rather than this project's documentation.
edit: nevermind. I really can't read sometimes :)