From 6d61287d17f0ce972aecc5af7c588e0188c460af Mon Sep 17 00:00:00 2001 From: Arongkorn Date: Fri, 15 Sep 2023 02:00:24 +0700 Subject: [PATCH] refactor: return `null` instead of zero value uuid --- graphql/uuid.go | 9 ++++----- graphql/uuid_test.go | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/graphql/uuid.go b/graphql/uuid.go index 1bfb7680d5b..e9f22dccdb6 100644 --- a/graphql/uuid.go +++ b/graphql/uuid.go @@ -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) { diff --git a/graphql/uuid_test.go b/graphql/uuid_test.go index 3dd7d68ff8c..1d209964497 100644 --- a/graphql/uuid_test.go +++ b/graphql/uuid_test.go @@ -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) {