graphql-go
graphql-go copied to clipboard
Error message missing value
I am actually not entirely sure this is the right place to post it, so let me know if it needs to go elsewhere.
I ran into a problem where I had
func (r *Resolver) ResolverName(args *struct {
SomeVar SomeType
}) *ResolverNameResolver {
type SomeType struct {
UserID int32
SomeOtherVar int32
}
The mutation struct was
type LifeBalance {
UserID: ID!
SomeOtherVar: Int
}
I called ResolverName with
{
"UserID": "2",
"SomeVar": 4
}
And instead of getting something like UserID should be int instead of string
I got Error while fetching query: Error at path "ResolverName": missingValue
I kept looking for a missing value, so it took me a while to spot the difference in type.
The problem is in UserID int32. By graphql spec ID is a string. Changing type to graphql.ID should fix your problem
Or change the schema to
type LifeBalance {
UserID: Int!
SomeOtherVar: Int
}
Didn't think the graphql.ID type was Postgres friendly, but if it translates to string I guess it is fine. I will close this
You should not use graphql.ID as your primary key in db. Just extract string from this type and use it as your wish (as uuid or convert to int, idk)
But then I still consider it a problem that the error message is confusing. If I provide an Int and it is supposed to be a String, I shouldn't get Missing Value as an error message
yea, error messages are disgusting
Thanks for reporting. PRs are welcome for fixing this issue. I'll mark it as "Help wanted".
Hi! Is help still needed with this problem?
@adyang94 I haven't tried reproducing it lately. If you can reproduce it, PRs are welcome.
Hi! I've attempted to replicate the issue, but I've been unable to do so. Here's the schema I've written:
type Query {
organization(OrganizationID: ID!): Organization!
}
I've also implemented the resolver as follows:
func (c Controller) Organization(ctx context.Context, args *struct{ OrganizationID int32 }) (resolver.Organization, error) {
log.Println(args.OrganizationID)
...
}
However, I'm able to access the API without any issues. When I send a string type that cannot be marshaled into int32, such as
gq http://localhost:9000 \
-q "query {organization(OrganizationID: \"f170c10c-6896-46fc-b9a4-69e2b9a15154\"){ name } }"
the API responds with:
Error: {
errors: [
{
message: 'could not unmarshal "f170c10c-6896-46fc-b9a4-69e2b9a15154" (string) into int32: incompatible type'
}
],
data: {}
}
In my opinion, the error message is quite clear. It indicates that there's an incompatibility issue while trying to convert the string into an int32.