From c89860bdd01827ad0f7a3f2020935e2ae115ecb7 Mon Sep 17 00:00:00 2001
From: M <rootblack45@gmail.com>
Date: Fri, 15 Sep 2023 19:48:26 +0700
Subject: [PATCH] refactor: return `null` instead of zero value uuid (#2794)

---
 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 1bfb7680d5..e9f22dccdb 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 3dd7d68ff8..1d20996449 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) {