graphql-go icon indicating copy to clipboard operation
graphql-go copied to clipboard

Error message missing value

Open MrMatten opened this issue 7 years ago • 8 comments

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.

MrMatten avatar Sep 13 '18 08:09 MrMatten

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
}

vetcher avatar Sep 13 '18 08:09 vetcher

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

MrMatten avatar Sep 13 '18 09:09 MrMatten

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)

vetcher avatar Sep 13 '18 09:09 vetcher

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

MrMatten avatar Sep 18 '18 09:09 MrMatten

yea, error messages are disgusting

vetcher avatar Sep 18 '18 17:09 vetcher

Thanks for reporting. PRs are welcome for fixing this issue. I'll mark it as "Help wanted".

pavelnikolov avatar Dec 03 '18 00:12 pavelnikolov

Hi! Is help still needed with this problem?

adyang94 avatar Oct 06 '22 20:10 adyang94

@adyang94 I haven't tried reproducing it lately. If you can reproduce it, PRs are welcome.

pavelnikolov avatar Oct 11 '22 09:10 pavelnikolov

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.

yamad07 avatar Jun 14 '23 12:06 yamad07