Currently, int parameters defined in schema are mapped to 32-bit version. If the number is > 2^32 then it will be truncated.
Can we map Int datatype to int64 by default?
If it is not feasible, any workaround to achieve this?
gqlgen version? go version?sure, you can map your owner type into graphql.
scalar Int64 # graphql.schema
```
//If the type referenced in .gqlgen.yml is a function that returns a marshaller we can use it to encode and decode
// onto any existing go type.
func MarshalInt64(t int64) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = io.WriteString(w, strconv.FormatInt(t, 10))
})
}
// Unmarshal{Typename} is only required if the scalar appears as an input. The raw values have already been decoded
// from json into int/float64/bool/nil/map[string]interface/[]interface
func UnmarshalInt64(v interface{}) (int64, error) {
if res, ok := v.(json.Number); ok {
return res.Int64()
}
if res, ok := v.(string); ok {
return json.Number(res).Int64()
}
if res, ok := v.(int64); ok {
return res, nil
}
if res, ok := v.(*int64); ok {
return *res, nil
}
return 0, fmt.Errorf("could not convert %v of type %T to Int64", v, v)
} ```
Int64:
model: github.com/firm/project/internal/handlers/graphql.Int64 # gqlgen.yml
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
scalar Int64 # graphql.schema```
//If the type referenced in .gqlgen.yml is a function that returns a marshaller we can use it to encode and decode
// onto any existing go type.
func MarshalInt64(t int64) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = io.WriteString(w, strconv.FormatInt(t, 10))
})
}
// Unmarshal{Typename} is only required if the scalar appears as an input. The raw values have already been decoded
// from json into int/float64/bool/nil/map[string]interface/[]interface
func UnmarshalInt64(v interface{}) (int64, error) {
if res, ok := v.(json.Number); ok {
return res.Int64()
}
if res, ok := v.(string); ok {
return json.Number(res).Int64()
}
if res, ok := v.(int64); ok {
return res, nil
}
if res, ok := v.(*int64); ok {
return *res, nil
}
return 0, fmt.Errorf("could not convert %v of type %T to Int64", v, v)
} ```
Int64: model: github.com/firm/project/internal/handlers/graphql.Int64 # gqlgen.yml