Skip to content

Commit

Permalink
Merge pull request #902 from cfilby/fix-int64-marshalling
Browse files Browse the repository at this point in the history
Add support for int64 IDs
  • Loading branch information
vvakame authored Oct 18, 2019
2 parents dbc8842 + 13c3d92 commit adbceee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions graphql/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func UnmarshalID(v interface{}) (string, error) {
return string(v), nil
case int:
return strconv.Itoa(v), nil
case int64:
return strconv.FormatInt(v, 10), nil
case float64:
return fmt.Sprintf("%f", v), nil
case bool:
Expand Down
47 changes: 47 additions & 0 deletions graphql/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package graphql

import (
"math"
"testing"

"github.com/stretchr/testify/assert"
)

func TestMarshalID(t *testing.T) {
tests := []struct {
Name string
Input interface{}
Expected string
ShouldError bool
}{
{
Name: "int64",
Input: int64(12),
Expected: "12",
ShouldError: false,
},
{
Name: "int64 max",
Input: math.MaxInt64,
Expected: "9223372036854775807",
},
{
Name: "int64 min",
Input: math.MinInt64,
Expected: "-9223372036854775808",
},
}

for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
id, err := UnmarshalID(tt.Input)

assert.Equal(t, tt.Expected, id)
if tt.ShouldError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}

0 comments on commit adbceee

Please sign in to comment.