Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for int64 datatype #924

Closed
sumanthakannantha opened this issue Nov 8, 2019 · 3 comments
Closed

Support for int64 datatype #924

sumanthakannantha opened this issue Nov 8, 2019 · 3 comments
Labels

Comments

@sumanthakannantha
Copy link

sumanthakannantha commented Nov 8, 2019

What happened?

Currently, int parameters defined in schema are mapped to 32-bit version. If the number is > 2^32 then it will be truncated.

What did you expect?

Can we map Int datatype to int64 by default?
If it is not feasible, any workaround to achieve this?

Minimal graphql.schema and models to reproduce

versions

  • gqlgen version?
  • go version?
  • dep or go modules?
@imiskolee
Copy link

sure, you can map your owner type into graphql.

@karthikraobr
Copy link
Contributor

karthikraobr commented Nov 26, 2019

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```

@stale
Copy link

stale bot commented Jan 25, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants