This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package graph | |
| // This file will not be regenerated automatically. | |
| // | |
| // It serves as dependency injection for your app, add any dependencies you require here. | |
| import ( | |
| "golang-clean-architecture-ent-gqlgen/ent" | |
| "golang-clean-architecture-ent-gqlgen/graph/generated" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package ent | |
| //go:generate go run -mod=mod entc.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //go:build ignore | |
| // +build ignore | |
| package main | |
| import ( | |
| "errors" | |
| "log" | |
| "entgo.io/contrib/entgql" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "golang-clean-architecture-ent-gqlgen/config" | |
| "golang-clean-architecture-ent-gqlgen/graph" | |
| "golang-clean-architecture-ent-gqlgen/graph/generated" | |
| "net/http" | |
| "github.com/99designs/gqlgen/graphql/handler" | |
| "github.com/99designs/gqlgen/graphql/playground" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Edges of the User. | |
| func (User) Edges() []ent.Edge { | |
| return []ent.Edge{ | |
| edge.To("todos", Todo.Type), | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Edges of the Todo. | |
| func (Todo) Edges() []ent.Edge { | |
| return []ent.Edge{ | |
| edge.From("user", User.Type). | |
| Ref("todos"). | |
| Unique(). | |
| Field("user_id"), | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Fields of the Todo. | |
| func (Todo) Fields() []ent.Field { | |
| return []ent.Field{ | |
| field.Int("user_id").Optional(), | |
| field.String("name").Default(""), | |
| field.Enum("status"). | |
| NamedValues( | |
| "InProgress", "IN_PROGRESS", | |
| "Completed", "COMPLETED", | |
| ). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Migrate scheme in ent to database | |
| migrate_schema: | |
| go run ./cmd/migration/main.go | |
| .PHONY: start setup_db migrate_schema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "golang-clean-architecture-ent-gqlgen/config" | |
| "golang-clean-architecture-ent-gqlgen/ent" | |
| "golang-clean-architecture-ent-gqlgen/ent/migrate" | |
| "log" | |
| "entgo.io/ent/dialect" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Fields of the User. | |
| func (User) Fields() []ent.Field { | |
| return []ent.Field{ | |
| field.String("name"). | |
| NotEmpty(). | |
| MaxLen(255), | |
| field.Int("age"). | |
| Positive(), | |
| field.Time("created_at"). | |
| Default(time.Now). |