Skip to content

Instantly share code, notes, and snippets.

type User interface {
Get(ctx context.Context, id *model.ID) (*model.User, error)
List(ctx context.Context, after *model.Cursor, first *int, before *model.Cursor, last *int) (*model.UserConnection, error)
}
...
func (u *user) List(ctx context.Context, after *model.Cursor, first *int, before *model.Cursor, last *int) (*model.UserConnection, error) {
return u.userRepository.List(ctx, after, first, before, last)
}
type User interface {
Get(ctx context.Context, id *model.ID) (*model.User, error)
List(ctx context.Context, after *model.Cursor, first *int, before *model.Cursor, last *int) (*model.UserConnection, error)
}
func (r *queryResolver) Users(ctx context.Context, after *model.Cursor, first *int, before *model.Cursor, last *int) (*ent.UserConnection, error) {
panic(fmt.Errorf("not implemented"))
}
// UserConnection is the connection containing edges to User.
type UserConnection = ent.UserConnection
package model
import "golang-clean-architecture-ent-gqlgen/ent"
// Cursor of an edge type.
type Cursor = ent.Cursor
// PageInfo of a connection type.
type PageInfo = ent.PageInfo
type UserConnection {
totalCount: Int!
pageInfo: PageInfo!
edges: [UserEdge]
}
type UserEdge {
node: User
cursor: Cursor!
}
extend type Query {
scalar Cursor
scalar Time
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: Cursor
endCursor: Cursor
}
func (r *queryResolver) Node(ctx context.Context, id ulid.ID) (ent.Noder, error) {
n, err := r.client.Noder(ctx, id, ent.WithNodeType(ent.IDToType))
if err != nil {
return nil, err
}
return n, nil
}
package ent
import (
"context"
"fmt"
"golang-clean-architecture-ent-gqlgen/ent/schema/ulid"
"golang-clean-architecture-ent-gqlgen/pkg/const/globalid"
)
var globalIDs = globalid.New()
field.String("id").
GoType(ulid.ID("")).
DefaultFunc(func() ulid.ID {
return ulid.MustNew(globalid.New().Todo.Prefix)
}),