hasura / go-graphql-client

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

bigint type is not handled #78

Closed YazeedAlKhalaf closed 1 year ago

YazeedAlKhalaf commented 1 year ago

i believe we need to change the Int64 to be considered "bigint", unless there is some reason behind making all Int types be Int.

switch t.Kind() {
    case reflect.Slice, reflect.Array:
        // List. E.g., "[Int]".
        io.WriteString(w, "[")
        writeArgumentType(w, t.Elem(), nil, true)
        io.WriteString(w, "]")
    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
        reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
        io.WriteString(w, "Int")
    case reflect.Float32, reflect.Float64:
        io.WriteString(w, "Float")
    case reflect.Bool:
        io.WriteString(w, "Boolean")
    default:
        n := t.Name()
        if n == "string" {
            n = "String"
        }
        io.WriteString(w, n)
    }
hgiasac commented 1 year ago

Hi @YazeedAlKhalaf

That is the expected behavior. The GraphQL client is generic and can convert basic GraphQL scalar types in the spec. I guess you assume the bigint type should be handled because the library is forked by Hasura, right? We still follow the design of the original client and don't try to satisfy Hasura GraphQL Engine only.

YazeedAlKhalaf commented 1 year ago

Thanks @hgiasac for the quick reply.

Makes sense, yes I thought it would be handled.

Well if it helps anybody in the future, here is how I was able to input a bigint in the query, I used a raw query and called the Exec function with the rawQuery, nil variables and if it is a subscription the handler.

Now for the raw query you can use fmt.Sprintf to include the variables in their places and no need for the ($var_name:var_type) when using this method.

hgiasac commented 1 year ago

You can use a type alias instead. The client uses reflection to infer and print the equivalent type. We mention this in the doc https://github.com/hasura/go-graphql-client#specify-graphql-type-name

type bigint int64

a := bigint(20)