-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.go
More file actions
83 lines (75 loc) · 2.04 KB
/
Copy pathapplication.go
File metadata and controls
83 lines (75 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
privacymixin "github.com/ron96g/go-graphql/ent/schema/mixin"
)
// Application holds the schema definition for the Application entity.
type Application struct {
ent.Schema
}
// Mixin adds shared mixins to the Application schema.
func (Application) Mixin() []ent.Mixin {
return []ent.Mixin{
privacymixin.PrivacyMixin{},
}
}
// Fields of the Application.
func (Application) Fields() []ent.Field {
return []ent.Field{
field.Text("name").
NotEmpty().
MinLen(3).
MaxLen(15).
Annotations(entgql.OrderField("NAME")),
field.Text("zone").
NotEmpty().
Annotations(entgql.OrderField("ZONE")),
field.Text("clientId").
Immutable().
NotEmpty(),
field.Text("clientSecret").
NotEmpty().
Annotations(entgql.Skip(entgql.SkipMutationCreateInput, entgql.SkipMutationUpdateInput, entgql.SkipWhereInput)),
field.String("app_id").
Optional().
Nillable().
Comment("External application identifier (e.g., appid-123456)"),
}
}
// Edges of the Application.
func (Application) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", Team.Type).
Ref("applications").
Required().
Unique().
Annotations(entgql.Skip(entgql.SkipType)),
edge.To("subscribed_apis", ApiSubscription.Type).
Annotations(entgql.RelayConnection()),
edge.To("subscribed_events", EventSubscription.Type).
Annotations(entgql.RelayConnection()),
edge.To("exposed_apis", ApiExposure.Type).
Annotations(entgql.RelayConnection()),
edge.To("exposed_events", EventExposure.Type).
Annotations(entgql.RelayConnection()),
}
}
func (Application) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.QueryField(),
entgql.MultiOrder(),
entgql.RelayConnection(),
}
}
// Indexes of the Application.
func (Application) Indexes() []ent.Index {
return []ent.Index{
// Application name is unique within a team
index.Fields("name").Edges("owner").Unique(),
}
}