Skip to content

Commit

Permalink
move default value off of FieldDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
nasdf committed Oct 18, 2024
1 parent 8181a15 commit f42f255
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
5 changes: 0 additions & 5 deletions client/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand All @@ -178,7 +174,6 @@ func NewLocalFieldDefinition(local CollectionFieldDescription) FieldDefinition {
ID: local.ID,
Kind: local.Kind.Value(),
RelationName: local.RelationName.Value(),
DefaultValue: local.DefaultValue,
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
`,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/mutation/create/with_default_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
`,
Expand Down Expand Up @@ -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",
},
},
Expand All @@ -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")
}
`,
Expand Down Expand Up @@ -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")
}
`,
Expand All @@ -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",
},
},
Expand All @@ -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",
},
},
Expand Down

0 comments on commit f42f255

Please sign in to comment.