hasura / go-graphql-client

Package graphql provides a GraphQL client implementation.
MIT License
405 stars 94 forks source link

Smallint type problem #90

Closed dogukanoksuz closed 1 year ago

dogukanoksuz commented 1 year ago

Hello,

Thanks for great work, i appreciate it. Library works great with Hasura but i am encountered a bug.

When mutating, i must send smallint as type but when i create smallint as type on Golang it still returns Int!

This typecasting works with strings without problems but on int values i encounter this error;

Message: variable 'user_defined' is declared as 'Int', but used where 'smallint' is expected, Locations: [], Extensions: map[code:validation-failed path:$.selectionSet.....]
image

Thanks.

hgiasac commented 1 year ago

I guess the type reflection can't infer private types from other packages. You can try to define the inline type in the same package, for instance:

type smallint int
err := gql.Connection().Mutate(context.Background(), &q, map[string]interface{}{
  "user_defined": smallint(1)
})

Another approach is the GraphQLType interface if you like to reuse that type for multiple packages.

type SmallInt int

func (i SmallInt) GetGraphQLType() string { 
  return "smallint" 
}
dogukanoksuz commented 1 year ago

Looks like second approach works.

As i tested we can reflect private types from other packages if it's based on string.

I think this lines causes the bug;

image