Skip to content

Commit

Permalink
refactor: return null instead of zero value uuid (#2794)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x221A committed Sep 15, 2023
1 parent 625ca2e commit c89860b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions graphql/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package graphql

import (
"fmt"
"io"
"strconv"

"github.com/google/uuid"
)

func MarshalUUID(id uuid.UUID) Marshaler {
return WriterFunc(func(w io.Writer) {
_, _ = io.WriteString(w, strconv.Quote(id.String()))
})
if id == uuid.Nil {
return Null
}
return MarshalString(id.String())
}

func UnmarshalUUID(v any) (uuid.UUID, error) {
Expand Down
2 changes: 1 addition & 1 deletion graphql/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestMarshalUUID(t *testing.T) {
t.Run("Null Values", func(t *testing.T) {
assert.Equal(t, uuid.Nil, uuid.MustParse("00000000-0000-0000-0000-000000000000"))
assert.Equal(t, "null", m2s(MarshalUUID(uuid.Nil)))
})

t.Run("Valid Values", func(t *testing.T) {
Expand Down

0 comments on commit c89860b

Please sign in to comment.