Skip to content

Commit

Permalink
feat: improve edge usages
Browse files Browse the repository at this point in the history
  • Loading branch information
GalvinGao committed Aug 28, 2023
1 parent 6ee0a97 commit 6ed7b5f
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 35 deletions.
10 changes: 5 additions & 5 deletions cmd/app/cli/script/import_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ func ReadCSVFile(filePath string) [][]string {
func PostEvent(content map[string]any, researchID string) {
client := graphql.NewClient("http://localhost:3500/graphql")
req := graphql.NewRequest(`
mutation CreateEvent($newEvent: NewEvent!) {
createEvent(input: $newEvent) {
mutation CreateEvent($input: CreateEventInput!) {
createEvent(input: $input) {
content
}
}`,
)
userAgent := "cli"
newEvent := model.CreateEventInput{
input := model.CreateEventInput{
Content: content,
ResearchID: researchID,
UserAgent: userAgent,
}
req.Var("newEvent", newEvent)
// req.Header.Set("Authorization", "")
req.Var("input", input)
req.Header.Set("Authorization", "Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyb2d1ZXN0YXRzIiwiZXhwIjoxNjk0MjA0MjY1LCJpYXQiOjE2OTI5OTQ2NjUsImlzcyI6InJvZ3Vlc3RhdHMvdjAuMC4wIiwibmJmIjoxNjkyOTk0NjY1LCJzdWIiOiIwMWg4cTVlYnJuNWV0aG0xcDZ6anhyOWVmdyJ9.AHlIYrx7tKj6nnXO4MYRd_0mXqzOVWPyG6FHidPitfI2IbrtZI3-lXA-bZP_nl0Op7d4TgzacdYwJPDgYGLoZcznAfopT-ahoHmDZrflhrK-Soo8ji7OZENjOIH5VetkkTaKl9zuqdAivds4DQPefSYngsn5vqzIgIZhaoR8nJoaq6MT")
ctx := context.Background()
var respData any
if err := client.Run(ctx, req, &respData); err != nil {
Expand Down
24 changes: 22 additions & 2 deletions internal/ent/event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions internal/ent/event/event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/ent/event_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions internal/ent/event_query.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/ent/research/research.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions internal/ent/research_query.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions internal/ent/schema/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ func (Event) Fields() []ent.Field {
Annotations(
entgql.OrderField("ID"),
),
field.Time("created_at").Immutable().Default(time.Now).Annotations(
entgql.OrderField("CREATED_AT"),
),
field.Time("created_at").
Immutable().
Default(time.Now).
Annotations(
entgql.OrderField("CREATED_AT"),
),
field.String("user_id"),
field.String("research_id"),
field.String("user_agent"),
field.JSON("content", map[string]any{}),
}
Expand All @@ -41,8 +46,14 @@ func (Event) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("events").
Field("user_id").
Required().
Unique(),
edge.From("research", Research.Type).
Ref("events").
Field("research_id").
Required().
Unique(),
edge.From("research", Research.Type).Ref("events").Unique(),
}
}

Expand Down
3 changes: 1 addition & 2 deletions internal/ent/schema/research.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func (Research) Fields() []ent.Field {
func (Research) Edges() []ent.Edge {
return []ent.Edge{
edge.To("events", Event.Type).
Required().
StorageKey(edge.Column("research_id")).
// Required().
Annotations(entsql.OnDelete(entsql.NoAction)),
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/ent/schema/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func (User) Fields() []ent.Field {
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("events", Event.Type).
Required().
StorageKey(edge.Column("user_id")).
// Required().
Annotations(entsql.OnDelete(entsql.NoAction)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ent/user/user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions internal/ent/user_query.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ed7b5f

Please sign in to comment.