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 usecase | |
| import ( | |
| "context" | |
| "golang-clean-architecture-ent-gqlgen/pkg/entity/model" | |
| "golang-clean-architecture-ent-gqlgen/pkg/usecase/repository" | |
| ) | |
| type user struct { | |
| userRepository repository.User |
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 repository | |
| import ( | |
| "context" | |
| "golang-clean-architecture-ent-gqlgen/pkg/entity/model" | |
| ) | |
| // User is an interface of repository | |
| type User interface { | |
| Get(ctx context.Context, id *int) (*model.User, error) |
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 model | |
| import "golang-clean-architecture-ent-gqlgen/ent" | |
| // Todo is the model entity for the Todo schema. | |
| type Todo = ent.Todo | |
| // CreateTodoInput represents a mutation input for creating todos. | |
| type CreateTodoInput = ent.CreateTodoInput |
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 model | |
| import "golang-clean-architecture-ent-gqlgen/ent" | |
| // User is the model entity for the User schema. | |
| type User = ent.User | |
| // CreateUserInput represents a mutation input for creating users. | |
| type CreateUserInput = ent.CreateUserInput |
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
| func (r *mutationResolver) CreateUser(ctx context.Context, input ent.CreateUserInput) (*ent.User, error) { | |
| u, err := r.client.User.Create().SetInput(input).Save(ctx) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return u, nil | |
| } | |
| func (r *mutationResolver) UpdateUser(ctx context.Context, input ent.UpdateUserInput) (*ent.User, error) { | |
| u, err := r.client.User.UpdateOneID(input.ID).SetInput(input).Save(ctx) |
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
| // CreateTodoInput represents a mutation input for creating todos. | |
| type CreateTodoInput struct { | |
| Name *string | |
| Status *todo.Status | |
| Priority *int | |
| CreatedAt *time.Time | |
| UpdatedAt *time.Time | |
| UserID *int | |
| } | |
| ... |
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 ( | |
| "log" | |
| "entgo.io/contrib/entgql" | |
| "entgo.io/ent/entc" |
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
| {{ define "mutation_input" }} | |
| {{- /*gotype: entgo.io/ent/entc/gen.Graph*/ -}} | |
| {{ $pkg := base $.Config.Package }} | |
| {{- with extend $ "Package" $pkg }} | |
| {{ template "header" . }} | |
| {{- end }} | |
| {{ template "import" $ }} |
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
| input CreateUserInput { | |
| name: String! | |
| age: Int! | |
| } | |
| input UpdateUserInput { | |
| id: ID! | |
| name: String | |
| age: Int | |
| } |
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
| type Query | |
| type Mutation |