diff --git a/graphql/id.go b/graphql/id.go index 4f532037d08..2e78a5ec4b2 100644 --- a/graphql/id.go +++ b/graphql/id.go @@ -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: diff --git a/graphql/id_test.go b/graphql/id_test.go new file mode 100644 index 00000000000..ad600102edb --- /dev/null +++ b/graphql/id_test.go @@ -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) + } + }) + } +}