diff --git a/client/definitions.go b/client/definitions.go index 269a703ac9..af571d5983 100644 --- a/client/definitions.go +++ b/client/definitions.go @@ -145,9 +145,6 @@ type FieldDefinition struct { // If true, this is the primary half of a relation, otherwise is false. IsPrimaryRelation bool - - // DefaultValue contains the default value for this field. - DefaultValue any } // NewFieldDefinition returns a new [FieldDefinition], combining the given local and global elements @@ -167,7 +164,6 @@ func NewFieldDefinition(local CollectionFieldDescription, global SchemaFieldDesc RelationName: local.RelationName.Value(), Typ: global.Typ, IsPrimaryRelation: kind.IsObject() && !kind.IsArray(), - DefaultValue: local.DefaultValue, } } @@ -178,7 +174,6 @@ func NewLocalFieldDefinition(local CollectionFieldDescription) FieldDefinition { ID: local.ID, Kind: local.Kind.Value(), RelationName: local.RelationName.Value(), - DefaultValue: local.DefaultValue, } } diff --git a/client/document.go b/client/document.go index 4abadcac52..f08b051418 100644 --- a/client/document.go +++ b/client/document.go @@ -771,7 +771,7 @@ func (doc *Document) setAndParseObjectType(value map[string]any) error { } func (doc *Document) setDefaultValues() error { - for _, field := range doc.collectionDefinition.GetFields() { + for _, field := range doc.collectionDefinition.Description.Fields { if field.DefaultValue == nil { continue // no default value to set } diff --git a/tests/integration/collection_description/with_default_fields_test.go b/tests/integration/collection_description/with_default_fields_test.go index 0d35254ca9..e52778e719 100644 --- a/tests/integration/collection_description/with_default_fields_test.go +++ b/tests/integration/collection_description/with_default_fields_test.go @@ -30,7 +30,7 @@ func TestCollectionDescription_WithDefaultFieldValues(t *testing.T) { name: String @default(string: "Bob") age: Int @default(int: 10) points: Float @default(float: 30) - metadata: JSON @default(json: "{\"value\":1}") + metadata: JSON @default(json: {value: 1}) image: Blob @default(blob: "ff0099") } `, @@ -66,9 +66,11 @@ func TestCollectionDescription_WithDefaultFieldValues(t *testing.T) { DefaultValue: "ff0099", }, { - ID: 5, - Name: "metadata", - DefaultValue: "{\"value\":1}", + ID: 5, + Name: "metadata", + DefaultValue: map[string]any{ + "value": float64(1), + }, }, { ID: 6, diff --git a/tests/integration/mutation/create/with_default_values_test.go b/tests/integration/mutation/create/with_default_values_test.go index aeca8a1f0f..acf253800e 100644 --- a/tests/integration/mutation/create/with_default_values_test.go +++ b/tests/integration/mutation/create/with_default_values_test.go @@ -31,7 +31,7 @@ func TestMutationCreate_WithDefaultValues_NoValuesProvided_SetsDefaultValue(t *t name: String @default(string: "Bob") age: Int @default(int: 40) points: Float @default(float: 10) - metadata: JSON @default(json: "{\"one\":1}") + metadata: JSON @default(json: {one: 1}) image: Blob @default(blob: "ff0099") } `, @@ -60,7 +60,7 @@ func TestMutationCreate_WithDefaultValues_NoValuesProvided_SetsDefaultValue(t *t "name": "Bob", "points": float64(10), "created": time.Time(time.Date(2000, time.July, 23, 3, 0, 0, 0, time.UTC)), - "metadata": "{\"one\":1}", + "metadata": map[string]any{"one": float64(1)}, "image": "ff0099", }, }, @@ -84,7 +84,7 @@ func TestMutationCreate_WithDefaultValues_NilValuesProvided_SetsNilValue(t *test name: String @default(string: "Bob") age: Int @default(int: 40) points: Float @default(float: 10) - metadata: JSON @default(json: "{\"one\":1}") + metadata: JSON @default(json: {one: 1}) image: Blob @default(blob: "ff0099") } `, @@ -144,7 +144,7 @@ func TestMutationCreate_WithDefaultValues_ValuesProvided_SetsValue(t *testing.T) name: String @default(string: "Bob") age: Int @default(int: 40) points: Float @default(float: 10) - metadata: JSON @default(json: "{\"one\":1}") + metadata: JSON @default(json: {one: 1}) image: Blob @default(blob: "ff0099") } `, @@ -156,7 +156,7 @@ func TestMutationCreate_WithDefaultValues_ValuesProvided_SetsValue(t *testing.T) "name": "Alice", "points": float64(5), "created": time.Time(time.Date(2024, time.June, 18, 1, 0, 0, 0, time.UTC)), - "metadata": "{\"two\":2}", + "metadata": map[string]any{"two": 2}, "image": "aabb33", }, }, @@ -180,7 +180,7 @@ func TestMutationCreate_WithDefaultValues_ValuesProvided_SetsValue(t *testing.T) "name": "Alice", "points": float64(5), "created": time.Time(time.Date(2024, time.June, 18, 1, 0, 0, 0, time.UTC)), - "metadata": "{\"two\":2}", + "metadata": map[string]any{"two": float64(2)}, "image": "aabb33", }, },