Skip to content

Instantly share code, notes, and snippets.

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
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)
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
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
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)
// 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
}
...
//go:build ignore
// +build ignore
package main
import (
"log"
"entgo.io/contrib/entgql"
"entgo.io/ent/entc"
{{ define "mutation_input" }}
{{- /*gotype: entgo.io/ent/entc/gen.Graph*/ -}}
{{ $pkg := base $.Config.Package }}
{{- with extend $ "Package" $pkg }}
{{ template "header" . }}
{{- end }}
{{ template "import" $ }}
input CreateUserInput {
name: String!
age: Int!
}
input UpdateUserInput {
id: ID!
name: String
age: Int
}
type Query
type Mutation