mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/edge: fix edge annotations with to/from builders (#679)
This commit is contained in:
@@ -7,6 +7,8 @@ package edge_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/edge"
|
||||
|
||||
@@ -84,3 +86,30 @@ func TestEdge(t *testing.T) {
|
||||
assert.Equal("following", from.Ref.Tag)
|
||||
assert.Equal(edge.StorageKey{Table: "user_followers", Columns: []string{"following_id", "followers_id"}}, *from.Ref.StorageKey)
|
||||
}
|
||||
|
||||
type GQL struct {
|
||||
Field string
|
||||
}
|
||||
|
||||
func (GQL) Name() string {
|
||||
return "GQL"
|
||||
}
|
||||
|
||||
func TestAnnotations(t *testing.T) {
|
||||
type User struct{ ent.Schema }
|
||||
to := edge.To("user", User.Type).
|
||||
Annotations(GQL{Field: "to"}).
|
||||
Descriptor()
|
||||
require.Equal(t, []edge.Annotation{GQL{Field: "to"}}, to.Annotations)
|
||||
from := edge.From("user", User.Type).
|
||||
Annotations(GQL{Field: "from"}).
|
||||
Descriptor()
|
||||
require.Equal(t, []edge.Annotation{GQL{Field: "from"}}, from.Annotations)
|
||||
bidi := edge.To("following", User.Type).
|
||||
Annotations(GQL{Field: "to"}).
|
||||
From("followers").
|
||||
Annotations(GQL{Field: "from"}).
|
||||
Descriptor()
|
||||
require.Equal(t, []edge.Annotation{GQL{Field: "from"}}, bidi.Annotations)
|
||||
require.Equal(t, []edge.Annotation{GQL{Field: "to"}}, bidi.Ref.Annotations)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user