-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
enhancementNew feature or requestNew feature or request
Description
✨ Describe the feature you'd like
It would be great to have the ability to control EdgeEndpoint at the schema level and/or to specify a default value in the global configuration.
Current code:
package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/lrstanley/entrest"
)
type User struct {
ent.Schema
}
func (Person) Annotations() []schema.Annotation {
return []schema.Annotation{
// annotations
}
}
func (Person) Fields() []ent.Field {
return []ent.Field{
// fields
}
}
func (Person) Edges() []ent.Edge {
return []ent.Edge{
edge.From("gender", Gender.Type).
Ref("users").
Field("gender_id").
Unique().
Annotations(
entrest.WithEdgeEndpoint(false),
),
edge.From("nationality", Nationality.Type).
Ref("user").
Field("nationality_id").
Unique().
Annotations(
entrest.WithEdgeEndpoint(false),
),
edge.To("names", Name.Type).
Annotations(
entrest.WithEdgeEndpoint(false),
),
edge.To("pets", Pet.Type).
Annotations(
entrest.WithEdgeEndpoint(false),
),
edge.To("friends", User.Type).
Annotations(
entrest.WithEdgeEndpoint(false),
),
edge.To("books", Book.Type).
Annotations(
entrest.WithEdgeEndpoint(false),
),
edge.To("homes", Home.Type).
Annotations(
entrest.WithEdgeEndpoint(false),
),
edge.To("cars", Car.Type).
Annotations(
entrest.WithEdgeEndpoint(false),
),
}
}Possible solution:
package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/lrstanley/entrest"
)
type User struct {
ent.Schema
}
func (Person) Annotations() []schema.Annotation {
return []schema.Annotation{
// annotations
entrest.WithEdgeEndpoint(false),
}
}
func (Person) Fields() []ent.Field {
return []ent.Field{
// fields
}
}
func (Person) Edges() []ent.Edge {
return []ent.Edge{
edge.From("gender", Gender.Type).
Ref("users").
Field("gender_id").
Unique(),
edge.From("nationality", Nationality.Type).
Ref("user").
Field("nationality_id").
Unique(),
edge.To("names", Name.Type),
edge.To("pets", Pet.Type),
edge.To("friends", User.Type),
edge.To("books", Book.Type),
edge.To("homes", Home.Type),
edge.To("cars", Car.Type),
}
}🌧 Is your feature request related to a problem?
Currently, to disable the generation of EdgeEndpoint, you need to specify an annotation for each individual edge. In our project, we don't need endpoints for edges at all. As a result, we have to add annotations to every edge in every schema.
🔎 Describe alternatives you've considered
As an alternative, you could write custom hooks and reuse them across projects.
⚠ If implemented, do you think this feature will be a breaking change to users?
Not sure
⚙ Additional context
No response
🤝 Requirements
- I have confirmed that someone else has not submitted a similar feature request.
- If implemented, I believe this feature will help others, in addition to solving my problems.
- I have looked into alternative solutions to the best of my ability.
- (optional) I would be willing to contribute to testing this feature if implemented, or making a PR to implement this functionality.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Projects
Status
done