stop using reflection

This commit is contained in:
Nimer Farahty 2025-05-31 20:12:32 +03:00
parent b8f49676ff
commit 1a0904e873
8 changed files with 100 additions and 85 deletions

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"reflect"
"git.farahty.com/nimer/go-mongo/models"
"github.com/graph-gophers/dataloader"
@ -45,7 +44,7 @@ func LoaderFor(ctx context.Context) *Loaders {
}
// CreateBatch creates a generic batched loader for a MongoDB collection
func CreateBatch[T any](coll string) dataloader.BatchFunc {
func CreateBatch[T models.Identifiable](coll string) dataloader.BatchFunc {
return func(ctx context.Context, keys dataloader.Keys) []*dataloader.Result {
// Convert all keys to MongoDB ObjectIDs
var objectIDs []primitive.ObjectID
@ -75,12 +74,7 @@ func CreateBatch[T any](coll string) dataloader.BatchFunc {
// Build map of result keyed by ID
objByID := make(map[primitive.ObjectID]T)
for _, item := range data {
val := reflect.ValueOf(item).Elem()
idValue := reflect.Indirect(val).FieldByName("ID").Interface()
if id, ok := idValue.(primitive.ObjectID); ok {
objByID[id] = *item
}
objByID[(*item).GetID()] = *item // dereference pointer
}
// Assemble results in original key order

View File

@ -1,5 +1,4 @@
//go:build tools
// +build tools
//go:build ignore
package main
@ -13,28 +12,31 @@ import (
"github.com/99designs/gqlgen/plugin/modelgen"
)
var modelsWithID []string
func mutateHook(b *modelgen.ModelBuild) *modelgen.ModelBuild {
for _, model := range b.Models {
hasID := false
for _, field := range model.Fields {
if field.Name == "id" {
field.Tag += ` bson:"_id,omitempty"`
field.Tag = `json:"id,omitempty" bson:"_id,omitempty"`
hasID = true
} else {
if strings.HasPrefix(field.Description, "#bson:") {
command := strings.TrimPrefix(field.Description, "#bson:")
switch command {
case "ignore":
if strings.TrimSpace(command) == "ignore" {
field.Tag = strings.TrimSuffix(field.Tag, `"`) + `,omitempty" bson:"-"`
}
} else {
field.Tag = strings.TrimSuffix(field.Tag, `"`) + `" bson:"` + field.Name + `,omitempty"`
}
}
}
if hasID {
modelsWithID = append(modelsWithID, model.Name)
}
}
return b
@ -53,6 +55,23 @@ func main() {
err = api.Generate(cfg, api.ReplacePlugin(&p))
// f, err := os.Create("models/getid_gen.go")
// if err != nil {
// fmt.Fprintln(os.Stderr, "❌ failed to create getid_gen.go:", err)
// os.Exit(4)
// }
// defer f.Close()
// f.WriteString("// Code generated by gqlgen. DO NOT EDIT.\n\n")
// f.WriteString("package models\n\n")
// f.WriteString("import \"go.mongodb.org/mongo-driver/bson/primitive\"\n\n")
// for _, model := range modelsWithID {
// f.WriteString(fmt.Sprintf("func (m *%s) GetID() primitive.ObjectID {\n", model))
// f.WriteString(" return m.ID\n")
// f.WriteString("}\n\n")
// }
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(3)

View File

@ -13,10 +13,10 @@ import (
"sync/atomic"
"time"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/introspection"
"git.farahty.com/nimer/go-mongo/app"
"git.farahty.com/nimer/go-mongo/models"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/introspection"
gqlparser "github.com/vektah/gqlparser/v2"
"github.com/vektah/gqlparser/v2/ast"
"go.mongodb.org/mongo-driver/bson/primitive"
@ -867,7 +867,7 @@ func (ec *executionContext) field_Mutation_createCategory_argsInput(
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("input"))
if tmp, ok := rawArgs["input"]; ok {
return ec.unmarshalNCreateCategoryInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCreateCategoryInput(ctx, tmp)
return ec.unmarshalNCreateCategoryInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCreateCategoryInput(ctx, tmp)
}
var zeroVal models.CreateCategoryInput
@ -895,7 +895,7 @@ func (ec *executionContext) field_Mutation_createTodo_argsInput(
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("input"))
if tmp, ok := rawArgs["input"]; ok {
return ec.unmarshalNCreateTodoInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCreateTodoInput(ctx, tmp)
return ec.unmarshalNCreateTodoInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCreateTodoInput(ctx, tmp)
}
var zeroVal models.CreateTodoInput
@ -923,7 +923,7 @@ func (ec *executionContext) field_Mutation_createUser_argsInput(
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("input"))
if tmp, ok := rawArgs["input"]; ok {
return ec.unmarshalNCreateUserInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCreateUserInput(ctx, tmp)
return ec.unmarshalNCreateUserInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCreateUserInput(ctx, tmp)
}
var zeroVal models.CreateUserInput
@ -951,7 +951,7 @@ func (ec *executionContext) field_Mutation_login_argsInput(
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("input"))
if tmp, ok := rawArgs["input"]; ok {
return ec.unmarshalNLoginInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐLoginInput(ctx, tmp)
return ec.unmarshalNLoginInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐLoginInput(ctx, tmp)
}
var zeroVal models.LoginInput
@ -1234,7 +1234,7 @@ func (ec *executionContext) _Category_title(ctx context.Context, field graphql.C
}
res := resTmp.([]*models.Translated)
fc.Result = res
return ec.marshalNTranslated2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx, field.Selections, res)
return ec.marshalNTranslated2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Category_title(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -1283,7 +1283,7 @@ func (ec *executionContext) _Category_body(ctx context.Context, field graphql.Co
}
res := resTmp.([]*models.Translated)
fc.Result = res
return ec.marshalOTranslated2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx, field.Selections, res)
return ec.marshalOTranslated2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Category_body(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -1332,7 +1332,7 @@ func (ec *executionContext) _Category_parent(ctx context.Context, field graphql.
}
res := resTmp.(*models.Category)
fc.Result = res
return ec.marshalOCategory2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
return ec.marshalOCategory2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Category_parent(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -1533,7 +1533,7 @@ func (ec *executionContext) _Category_createdBy(ctx context.Context, field graph
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalNUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalNUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Category_createdBy(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -1639,7 +1639,7 @@ func (ec *executionContext) _Category_updatedBy(ctx context.Context, field graph
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalNUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalNUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Category_updatedBy(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -1742,7 +1742,7 @@ func (ec *executionContext) _Category_owner(ctx context.Context, field graphql.C
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalOUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalOUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Category_owner(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -1848,7 +1848,7 @@ func (ec *executionContext) _LoginResponse_user(ctx context.Context, field graph
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalNUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalNUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_LoginResponse_user(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -1998,7 +1998,7 @@ func (ec *executionContext) _Mutation_login(ctx context.Context, field graphql.C
}
res := resTmp.(*models.LoginResponse)
fc.Result = res
return ec.marshalNLoginResponse2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐLoginResponse(ctx, field.Selections, res)
return ec.marshalNLoginResponse2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐLoginResponse(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Mutation_login(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2061,7 +2061,7 @@ func (ec *executionContext) _Mutation_createCategory(ctx context.Context, field
}
res := resTmp.(*models.Category)
fc.Result = res
return ec.marshalNCategory2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
return ec.marshalNCategory2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2141,7 +2141,7 @@ func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field grap
}
res := resTmp.(*models.Todo)
fc.Result = res
return ec.marshalOTodo2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res)
return ec.marshalOTodo2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Mutation_createTodo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2217,7 +2217,7 @@ func (ec *executionContext) _Mutation_createUser(ctx context.Context, field grap
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalOUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalOUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Mutation_createUser(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2290,7 +2290,7 @@ func (ec *executionContext) _Query_categories(ctx context.Context, field graphql
}
res := resTmp.([]*models.Category)
fc.Result = res
return ec.marshalNCategory2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
return ec.marshalNCategory2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_categories(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2362,7 +2362,7 @@ func (ec *executionContext) _Query_category(ctx context.Context, field graphql.C
}
res := resTmp.(*models.Category)
fc.Result = res
return ec.marshalNCategory2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
return ec.marshalNCategory2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_category(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2442,7 +2442,7 @@ func (ec *executionContext) _Query_todos(ctx context.Context, field graphql.Coll
}
res := resTmp.([]*models.Todo)
fc.Result = res
return ec.marshalOTodo2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res)
return ec.marshalOTodo2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_todos(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2507,7 +2507,7 @@ func (ec *executionContext) _Query_todo(ctx context.Context, field graphql.Colle
}
res := resTmp.(*models.Todo)
fc.Result = res
return ec.marshalOTodo2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res)
return ec.marshalOTodo2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_todo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2583,7 +2583,7 @@ func (ec *executionContext) _Query_users(ctx context.Context, field graphql.Coll
}
res := resTmp.([]*models.User)
fc.Result = res
return ec.marshalOUser2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalOUser2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_users(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2781,7 +2781,7 @@ func (ec *executionContext) _Subscription_onTodo(ctx context.Context, field grap
w.Write([]byte{'{'})
graphql.MarshalString(field.Alias).MarshalGQL(w)
w.Write([]byte{':'})
ec.marshalOTodo2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res).MarshalGQL(w)
ec.marshalOTodo2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTodo(ctx, field.Selections, res).MarshalGQL(w)
w.Write([]byte{'}'})
})
case <-ctx.Done():
@ -3069,7 +3069,7 @@ func (ec *executionContext) _Todo_createdBy(ctx context.Context, field graphql.C
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalNUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalNUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Todo_createdBy(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -3175,7 +3175,7 @@ func (ec *executionContext) _Todo_updatedBy(ctx context.Context, field graphql.C
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalNUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalNUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Todo_updatedBy(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -3278,7 +3278,7 @@ func (ec *executionContext) _Todo_owner(ctx context.Context, field graphql.Colle
}
res := resTmp.(*models.User)
fc.Result = res
return ec.marshalOUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
return ec.marshalOUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Todo_owner(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -5786,14 +5786,14 @@ func (ec *executionContext) unmarshalInputCreateCategoryInput(ctx context.Contex
switch k {
case "title":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title"))
data, err := ec.unmarshalNTranslatedInput2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInputᚄ(ctx, v)
data, err := ec.unmarshalNTranslatedInput2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInputᚄ(ctx, v)
if err != nil {
return it, err
}
it.Title = data
case "body":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("body"))
data, err := ec.unmarshalOTranslatedInput2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx, v)
data, err := ec.unmarshalOTranslatedInput2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx, v)
if err != nil {
return it, err
}
@ -5879,7 +5879,7 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o
it.Phone = data
case "status":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("status"))
data, err := ec.unmarshalOStatus2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐStatus(ctx, v)
data, err := ec.unmarshalOStatus2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐStatus(ctx, v)
if err != nil {
return it, err
}
@ -7155,11 +7155,11 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se
return res
}
func (ec *executionContext) marshalNCategory2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v models.Category) graphql.Marshaler {
func (ec *executionContext) marshalNCategory2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v models.Category) graphql.Marshaler {
return ec._Category(ctx, sel, &v)
}
func (ec *executionContext) marshalNCategory2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v []*models.Category) graphql.Marshaler {
func (ec *executionContext) marshalNCategory2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v []*models.Category) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
@ -7183,7 +7183,7 @@ func (ec *executionContext) marshalNCategory2ᚕᚖgithubᚗcomᚋfarahtyᚋgo
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalOCategory2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx, sel, v[i])
ret[i] = ec.marshalOCategory2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx, sel, v[i])
}
if isLen1 {
f(i)
@ -7197,7 +7197,7 @@ func (ec *executionContext) marshalNCategory2ᚕᚖgithubᚗcomᚋfarahtyᚋgo
return ret
}
func (ec *executionContext) marshalNCategory2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v *models.Category) graphql.Marshaler {
func (ec *executionContext) marshalNCategory2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v *models.Category) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@ -7207,17 +7207,17 @@ func (ec *executionContext) marshalNCategory2ᚖgithubᚗcomᚋfarahtyᚋgoᚑmo
return ec._Category(ctx, sel, v)
}
func (ec *executionContext) unmarshalNCreateCategoryInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCreateCategoryInput(ctx context.Context, v any) (models.CreateCategoryInput, error) {
func (ec *executionContext) unmarshalNCreateCategoryInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCreateCategoryInput(ctx context.Context, v any) (models.CreateCategoryInput, error) {
res, err := ec.unmarshalInputCreateCategoryInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) unmarshalNCreateTodoInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCreateTodoInput(ctx context.Context, v any) (models.CreateTodoInput, error) {
func (ec *executionContext) unmarshalNCreateTodoInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCreateTodoInput(ctx context.Context, v any) (models.CreateTodoInput, error) {
res, err := ec.unmarshalInputCreateTodoInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) unmarshalNCreateUserInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCreateUserInput(ctx context.Context, v any) (models.CreateUserInput, error) {
func (ec *executionContext) unmarshalNCreateUserInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCreateUserInput(ctx context.Context, v any) (models.CreateUserInput, error) {
res, err := ec.unmarshalInputCreateUserInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}
@ -7238,16 +7238,16 @@ func (ec *executionContext) marshalNID2goᚗmongodbᚗorgᚋmongoᚑdriverᚋbso
return res
}
func (ec *executionContext) unmarshalNLoginInput2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐLoginInput(ctx context.Context, v any) (models.LoginInput, error) {
func (ec *executionContext) unmarshalNLoginInput2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐLoginInput(ctx context.Context, v any) (models.LoginInput, error) {
res, err := ec.unmarshalInputLoginInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNLoginResponse2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v models.LoginResponse) graphql.Marshaler {
func (ec *executionContext) marshalNLoginResponse2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v models.LoginResponse) graphql.Marshaler {
return ec._LoginResponse(ctx, sel, &v)
}
func (ec *executionContext) marshalNLoginResponse2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v *models.LoginResponse) graphql.Marshaler {
func (ec *executionContext) marshalNLoginResponse2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v *models.LoginResponse) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@ -7289,7 +7289,7 @@ func (ec *executionContext) marshalNTime2timeᚐTime(ctx context.Context, sel as
return res
}
func (ec *executionContext) marshalNTranslated2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Translated) graphql.Marshaler {
func (ec *executionContext) marshalNTranslated2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Translated) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
@ -7313,7 +7313,7 @@ func (ec *executionContext) marshalNTranslated2ᚕᚖgithubᚗcomᚋfarahtyᚋgo
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalNTranslated2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslated(ctx, sel, v[i])
ret[i] = ec.marshalNTranslated2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslated(ctx, sel, v[i])
}
if isLen1 {
f(i)
@ -7333,7 +7333,7 @@ func (ec *executionContext) marshalNTranslated2ᚕᚖgithubᚗcomᚋfarahtyᚋgo
return ret
}
func (ec *executionContext) marshalNTranslated2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslated(ctx context.Context, sel ast.SelectionSet, v *models.Translated) graphql.Marshaler {
func (ec *executionContext) marshalNTranslated2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslated(ctx context.Context, sel ast.SelectionSet, v *models.Translated) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@ -7343,14 +7343,14 @@ func (ec *executionContext) marshalNTranslated2ᚖgithubᚗcomᚋfarahtyᚋgoᚑ
return ec._Translated(ctx, sel, v)
}
func (ec *executionContext) unmarshalNTranslatedInput2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInputᚄ(ctx context.Context, v any) ([]*models.TranslatedInput, error) {
func (ec *executionContext) unmarshalNTranslatedInput2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInputᚄ(ctx context.Context, v any) ([]*models.TranslatedInput, error) {
var vSlice []any
vSlice = graphql.CoerceList(v)
var err error
res := make([]*models.TranslatedInput, len(vSlice))
for i := range vSlice {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i))
res[i], err = ec.unmarshalNTranslatedInput2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx, vSlice[i])
res[i], err = ec.unmarshalNTranslatedInput2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx, vSlice[i])
if err != nil {
return nil, err
}
@ -7358,16 +7358,16 @@ func (ec *executionContext) unmarshalNTranslatedInput2ᚕᚖgithubᚗcomᚋfarah
return res, nil
}
func (ec *executionContext) unmarshalNTranslatedInput2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx context.Context, v any) (*models.TranslatedInput, error) {
func (ec *executionContext) unmarshalNTranslatedInput2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx context.Context, v any) (*models.TranslatedInput, error) {
res, err := ec.unmarshalInputTranslatedInput(ctx, v)
return &res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNUser2githubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v models.User) graphql.Marshaler {
func (ec *executionContext) marshalNUser2gitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v models.User) graphql.Marshaler {
return ec._User(ctx, sel, &v)
}
func (ec *executionContext) marshalNUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v *models.User) graphql.Marshaler {
func (ec *executionContext) marshalNUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v *models.User) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@ -7660,7 +7660,7 @@ func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast
return res
}
func (ec *executionContext) marshalOCategory2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v *models.Category) graphql.Marshaler {
func (ec *executionContext) marshalOCategory2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐCategory(ctx context.Context, sel ast.SelectionSet, v *models.Category) graphql.Marshaler {
if v == nil {
return graphql.Null
}
@ -7685,7 +7685,7 @@ func (ec *executionContext) marshalOID2ᚖgoᚗmongodbᚗorgᚋmongoᚑdriverᚋ
return res
}
func (ec *executionContext) unmarshalOStatus2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐStatus(ctx context.Context, v any) (*models.Status, error) {
func (ec *executionContext) unmarshalOStatus2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐStatus(ctx context.Context, v any) (*models.Status, error) {
if v == nil {
return nil, nil
}
@ -7694,7 +7694,7 @@ func (ec *executionContext) unmarshalOStatus2ᚖgithubᚗcomᚋfarahtyᚋgoᚑmo
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalOStatus2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐStatus(ctx context.Context, sel ast.SelectionSet, v *models.Status) graphql.Marshaler {
func (ec *executionContext) marshalOStatus2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐStatus(ctx context.Context, sel ast.SelectionSet, v *models.Status) graphql.Marshaler {
if v == nil {
return graphql.Null
}
@ -7719,7 +7719,7 @@ func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel as
return res
}
func (ec *executionContext) marshalOTodo2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTodo(ctx context.Context, sel ast.SelectionSet, v []*models.Todo) graphql.Marshaler {
func (ec *executionContext) marshalOTodo2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTodo(ctx context.Context, sel ast.SelectionSet, v []*models.Todo) graphql.Marshaler {
if v == nil {
return graphql.Null
}
@ -7746,7 +7746,7 @@ func (ec *executionContext) marshalOTodo2ᚕᚖgithubᚗcomᚋfarahtyᚋgoᚑmon
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalOTodo2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTodo(ctx, sel, v[i])
ret[i] = ec.marshalOTodo2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTodo(ctx, sel, v[i])
}
if isLen1 {
f(i)
@ -7760,14 +7760,14 @@ func (ec *executionContext) marshalOTodo2ᚕᚖgithubᚗcomᚋfarahtyᚋgoᚑmon
return ret
}
func (ec *executionContext) marshalOTodo2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTodo(ctx context.Context, sel ast.SelectionSet, v *models.Todo) graphql.Marshaler {
func (ec *executionContext) marshalOTodo2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTodo(ctx context.Context, sel ast.SelectionSet, v *models.Todo) graphql.Marshaler {
if v == nil {
return graphql.Null
}
return ec._Todo(ctx, sel, v)
}
func (ec *executionContext) marshalOTranslated2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Translated) graphql.Marshaler {
func (ec *executionContext) marshalOTranslated2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Translated) graphql.Marshaler {
if v == nil {
return graphql.Null
}
@ -7794,7 +7794,7 @@ func (ec *executionContext) marshalOTranslated2ᚕᚖgithubᚗcomᚋfarahtyᚋgo
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalNTranslated2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslated(ctx, sel, v[i])
ret[i] = ec.marshalNTranslated2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslated(ctx, sel, v[i])
}
if isLen1 {
f(i)
@ -7814,7 +7814,7 @@ func (ec *executionContext) marshalOTranslated2ᚕᚖgithubᚗcomᚋfarahtyᚋgo
return ret
}
func (ec *executionContext) unmarshalOTranslatedInput2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx context.Context, v any) ([]*models.TranslatedInput, error) {
func (ec *executionContext) unmarshalOTranslatedInput2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx context.Context, v any) ([]*models.TranslatedInput, error) {
if v == nil {
return nil, nil
}
@ -7824,7 +7824,7 @@ func (ec *executionContext) unmarshalOTranslatedInput2ᚕᚖgithubᚗcomᚋfarah
res := make([]*models.TranslatedInput, len(vSlice))
for i := range vSlice {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i))
res[i], err = ec.unmarshalOTranslatedInput2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx, vSlice[i])
res[i], err = ec.unmarshalOTranslatedInput2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx, vSlice[i])
if err != nil {
return nil, err
}
@ -7832,7 +7832,7 @@ func (ec *executionContext) unmarshalOTranslatedInput2ᚕᚖgithubᚗcomᚋfarah
return res, nil
}
func (ec *executionContext) unmarshalOTranslatedInput2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx context.Context, v any) (*models.TranslatedInput, error) {
func (ec *executionContext) unmarshalOTranslatedInput2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐTranslatedInput(ctx context.Context, v any) (*models.TranslatedInput, error) {
if v == nil {
return nil, nil
}
@ -7840,7 +7840,7 @@ func (ec *executionContext) unmarshalOTranslatedInput2ᚖgithubᚗcomᚋfarahty
return &res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalOUser2ᚕᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v []*models.User) graphql.Marshaler {
func (ec *executionContext) marshalOUser2ᚕᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v []*models.User) graphql.Marshaler {
if v == nil {
return graphql.Null
}
@ -7867,7 +7867,7 @@ func (ec *executionContext) marshalOUser2ᚕᚖgithubᚗcomᚋfarahtyᚋgoᚑmon
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalOUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx, sel, v[i])
ret[i] = ec.marshalOUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx, sel, v[i])
}
if isLen1 {
f(i)
@ -7881,7 +7881,7 @@ func (ec *executionContext) marshalOUser2ᚕᚖgithubᚗcomᚋfarahtyᚋgoᚑmon
return ret
}
func (ec *executionContext) marshalOUser2ᚖgithubcomᚋfarahtyᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v *models.User) graphql.Marshaler {
func (ec *executionContext) marshalOUser2ᚖgitᚗfarahtyᚗcomᚋnimerᚋgoᚑmongoᚋmodelsᚐUser(ctx context.Context, sel ast.SelectionSet, v *models.User) graphql.Marshaler {
if v == nil {
return graphql.Null
}

View File

@ -17,7 +17,7 @@ resolver:
package: resolvers
autobind:
- "github.com/farahty/go-mongo/models"
- "git.farahty.com/nimer/go-mongo/models"
# This section declares type mapping between the GraphQL and go type systems
#
@ -27,7 +27,7 @@ autobind:
models:
ID:
model:
- github.com/farahty/go-mongo/app.ObjectID
- git.farahty.com/nimer/go-mongo/app.ObjectID
- github.com/99designs/gqlgen/graphql.ID
Int:
model:

View File

@ -3,7 +3,7 @@ package models
import "go.mongodb.org/mongo-driver/bson/primitive"
type Identifiable interface {
getId() primitive.ObjectID
GetID() primitive.ObjectID
}
type Validate interface {

View File

@ -23,7 +23,7 @@ type Base interface {
}
type Category struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
Title []*Translated `json:"title" bson:"title,omitempty"`
Body []*Translated `json:"body,omitempty" bson:"body,omitempty"`
// #bson:ignore
@ -89,7 +89,7 @@ type Subscription struct {
}
type Todo struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
Title *string `json:"title,omitempty" bson:"title,omitempty"`
Completed *bool `json:"completed,omitempty" bson:"completed,omitempty"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt,omitempty"`
@ -126,7 +126,7 @@ type TranslatedInput struct {
}
type User struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
Phone *string `json:"phone,omitempty" bson:"phone,omitempty"`
Email *string `json:"email,omitempty" bson:"email,omitempty"`
Type *string `json:"type,omitempty" bson:"type,omitempty"`

View File

@ -15,7 +15,7 @@ func (u *User) CheckPassword(password string) bool {
return err == nil
}
func (u User) getId() primitive.ObjectID {
func (u User) GetID() primitive.ObjectID {
return u.ID
}

View File

@ -1,3 +1,5 @@
//go:generate go run generate.go
package resolvers
import (