48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/contrib/entgql"
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Category holds the schema definition for the Category entity.
|
|
type Category struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the Category.
|
|
func (Category) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.UUID("id", uuid.UUID{}).Default(uuid.New).Unique().Immutable(),
|
|
field.Time("created_at").Default(time.Now).Immutable().Annotations(entgql.OrderField("CREATED_AT")),
|
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now).Optional().Annotations(entgql.OrderField("UPDATED_AT")),
|
|
field.String("title").NotEmpty(),
|
|
field.Text("description").Optional(),
|
|
}
|
|
}
|
|
|
|
// Edges of the Category.
|
|
func (Category) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.To("posts", Post.Type).Annotations(
|
|
entgql.RelayConnection(),
|
|
entgql.OrderField("POSTS_COUNT"),
|
|
),
|
|
}
|
|
}
|
|
|
|
// Annotations of the Category.
|
|
func (Category) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entgql.RelayConnection(),
|
|
entgql.QueryField(),
|
|
entgql.Mutations(entgql.MutationCreate(), entgql.MutationUpdate()),
|
|
}
|
|
}
|