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

Add support for int64 IDs #902

Merged
merged 5 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Itoa(int(v)), nil
cfilby marked this conversation as resolved.
Show resolved Hide resolved
case float64:
return fmt.Sprintf("%f", v), nil
case bool:
Expand Down
36 changes: 36 additions & 0 deletions graphql/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package graphql

import (
"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,
},
cfilby marked this conversation as resolved.
Show resolved Hide resolved
}

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)
}
})
}
}