From 55d7d6cabd3d8cdef89a22c1c625b2e8080b8262 Mon Sep 17 00:00:00 2001 From: mimoham24 <69579255+mimoham24@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:35:03 +0900 Subject: [PATCH] fix(server): cannot unset a schema field's title (#1073) * fix title unsetting bug * Update server/pkg/schema/schema.go Co-authored-by: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> --------- Co-authored-by: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> --- server/e2e/gql_field_test.go | 4 +++- server/pkg/schema/schema.go | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/e2e/gql_field_test.go b/server/e2e/gql_field_test.go index 8cb5bbbc79..282d8519e4 100644 --- a/server/e2e/gql_field_test.go +++ b/server/e2e/gql_field_test.go @@ -370,7 +370,7 @@ func TestCreateField(t *testing.T) { tags := res.Path("$.data.node.schema.fields[0].typeProperty.tags").Raw().([]any) _, _ = updateField(e, mId, fId, "test", "test", "test", - true, true, true, true, nil, "Tag", + true, true, false, true, nil, "Tag", map[string]any{ "tag": map[string]any{ "defaultValue": []string{"s1", "s3"}, @@ -385,6 +385,8 @@ func TestCreateField(t *testing.T) { Value("node").Object(). HasValue("id", mId) + title := res.Path("$.data.node.schema.fields[0].isTitle").Raw().(bool) + assert.False(t, title) _, _ = createField(e, mId, "test2", "test2", "test2", false, false, false, false, "Tag", map[string]any{ diff --git a/server/pkg/schema/schema.go b/server/pkg/schema/schema.go index 760461ef86..33c06a7bdc 100644 --- a/server/pkg/schema/schema.go +++ b/server/pkg/schema/schema.go @@ -103,8 +103,13 @@ func (s *Schema) TitleField() *FieldID { } func (s *Schema) SetTitleField(tf *FieldID) error { - if !s.HasField(*tf) || s.Fields() == nil || len(s.Fields()) == 0 { + // unsetting title + if tf == nil { s.titleField = nil + return nil + } + + if !s.HasField(*tf) || s.Fields() == nil || len(s.Fields()) == 0 { return ErrInvalidTitleField } s.titleField = tf.CloneRef()