schema/edge: fix edge annotations with to/from builders (#679)

This commit is contained in:
Ariel Mashraki
2020-08-20 12:15:43 +03:00
committed by GitHub
parent b18716931d
commit 5e56543133
4 changed files with 46 additions and 2 deletions

View File

@@ -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)
}