From 0573bb6a96723f6557b3304124c604da9cc36fd4 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Sun, 11 Dec 2022 21:41:17 +0700 Subject: [PATCH] entgql: add example for create edge with mutation input (#416) * entgql: add example for create edge with mutation input Signed-off-by: Giau. Tran Minh * fix: should append instead of replace Signed-off-by: Giau. Tran Minh Signed-off-by: Giau. Tran Minh --- entgql/internal/todo/ent.resolvers.go | 6 + entgql/internal/todo/generated.go | 180 ++++++++++++++++++- entgql/internal/todo/todo.graphql | 5 + entgql/internal/todo/todo.resolvers.go | 22 +++ entgql/internal/todo/todo_test.go | 62 +++++++ entgql/internal/todogotype/ent.resolvers.go | 6 + entgql/internal/todogotype/generated.go | 180 ++++++++++++++++++- entgql/internal/todogotype/todo.resolvers.go | 8 + entgql/internal/todopulid/ent.resolvers.go | 6 + entgql/internal/todopulid/generated.go | 180 ++++++++++++++++++- entgql/internal/todopulid/todo.resolvers.go | 8 + entgql/internal/todouuid/ent.resolvers.go | 6 + entgql/internal/todouuid/generated.go | 180 ++++++++++++++++++- entgql/internal/todouuid/todo.resolvers.go | 8 + 14 files changed, 845 insertions(+), 12 deletions(-) diff --git a/entgql/internal/todo/ent.resolvers.go b/entgql/internal/todo/ent.resolvers.go index c08aa5e5a..01cc22033 100644 --- a/entgql/internal/todo/ent.resolvers.go +++ b/entgql/internal/todo/ent.resolvers.go @@ -60,8 +60,14 @@ func (r *queryResolver) Users(ctx context.Context, after *ent.Cursor, first *int // Query returns QueryResolver implementation. func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } +// CreateCategoryInput returns CreateCategoryInputResolver implementation. +func (r *Resolver) CreateCategoryInput() CreateCategoryInputResolver { + return &createCategoryInputResolver{r} +} + // TodoWhereInput returns TodoWhereInputResolver implementation. func (r *Resolver) TodoWhereInput() TodoWhereInputResolver { return &todoWhereInputResolver{r} } type queryResolver struct{ *Resolver } +type createCategoryInputResolver struct{ *Resolver } type todoWhereInputResolver struct{ *Resolver } diff --git a/entgql/internal/todo/generated.go b/entgql/internal/todo/generated.go index f79e8af63..54771a230 100644 --- a/entgql/internal/todo/generated.go +++ b/entgql/internal/todo/generated.go @@ -44,6 +44,7 @@ type Config struct { type ResolverRoot interface { Mutation() MutationResolver Query() QueryResolver + CreateCategoryInput() CreateCategoryInputResolver TodoWhereInput() TodoWhereInputResolver } @@ -116,8 +117,9 @@ type ComplexityRoot struct { } Mutation struct { - ClearTodos func(childComplexity int) int - CreateTodo func(childComplexity int, input ent.CreateTodoInput) int + ClearTodos func(childComplexity int) int + CreateCategory func(childComplexity int, input ent.CreateCategoryInput) int + CreateTodo func(childComplexity int, input ent.CreateTodoInput) int } PageInfo struct { @@ -184,6 +186,7 @@ type ComplexityRoot struct { } type MutationResolver interface { + CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) ClearTodos(ctx context.Context) (int, error) } @@ -197,6 +200,9 @@ type QueryResolver interface { Ping(ctx context.Context) (string, error) } +type CreateCategoryInputResolver interface { + CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error +} type TodoWhereInputResolver interface { CreatedToday(ctx context.Context, obj *ent.TodoWhereInput, data *bool) error } @@ -464,6 +470,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.ClearTodos(childComplexity), true + case "Mutation.createCategory": + if e.complexity.Mutation.CreateCategory == nil { + break + } + + args, err := ec.field_Mutation_createCategory_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.CreateCategory(childComplexity, args["input"].(ent.CreateCategoryInput)), true + case "Mutation.createTodo": if e.complexity.Mutation.CreateTodo == nil { break @@ -894,6 +912,7 @@ extend type Query { } type Mutation { + createCategory(input: CreateCategoryInput!): Category! createTodo(input: CreateTodoInput!): Todo! clearTodos: Int! } @@ -901,7 +920,10 @@ type Mutation { type Custom { info: String! } -`, BuiltIn: false}, + +extend input CreateCategoryInput { + createTodos: [CreateTodoInput!] +}`, BuiltIn: false}, {Name: "ent.graphql", Input: `directive @goField(forceResolver: Boolean, name: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION directive @goModel(model: String, models: [String!]) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION type BillProduct implements Node { @@ -1779,6 +1801,21 @@ func (ec *executionContext) field_Group_users_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Mutation_createCategory_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 ent.CreateCategoryInput + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCreateCategoryInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -3821,6 +3858,79 @@ func (ec *executionContext) fieldContext_GroupEdge_cursor(ctx context.Context, f return fc, nil } +func (ec *executionContext) _Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createCategory(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().CreateCategory(rctx, fc.Args["input"].(ent.CreateCategoryInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.Category) + fc.Result = res + return ec.marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCategory(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Category_id(ctx, field) + case "text": + return ec.fieldContext_Category_text(ctx, field) + case "status": + return ec.fieldContext_Category_status(ctx, field) + case "config": + return ec.fieldContext_Category_config(ctx, field) + case "duration": + return ec.fieldContext_Category_duration(ctx, field) + case "count": + return ec.fieldContext_Category_count(ctx, field) + case "strings": + return ec.fieldContext_Category_strings(ctx, field) + case "todos": + return ec.fieldContext_Category_todos(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Category", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createCategory_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_createTodo(ctx, field) if err != nil { @@ -8855,6 +8965,17 @@ func (ec *executionContext) unmarshalInputCreateCategoryInput(ctx context.Contex if err != nil { return it, err } + case "createTodos": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createTodos")) + data, err := ec.unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCreateTodoInputᚄ(ctx, v) + if err != nil { + return it, err + } + if err = ec.resolvers.CreateCategoryInput().CreateTodos(ctx, &it, data); err != nil { + return it, err + } } } @@ -10966,6 +11087,15 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") + case "createCategory": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createCategory(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } case "createTodo": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -12001,6 +12131,20 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } +func (ec *executionContext) marshalNCategory2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v ent.Category) graphql.Marshaler { + return ec._Category(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v *ent.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") + } + return graphql.Null + } + return ec._Category(ctx, sel, v) +} + func (ec *executionContext) unmarshalNCategoryConfigInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚋschemaᚋschematypeᚐCategoryConfig(ctx context.Context, v interface{}) (*schematype.CategoryConfig, error) { res, err := ec.unmarshalInputCategoryConfigInput(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) @@ -12037,11 +12181,21 @@ func (ec *executionContext) unmarshalNCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCreateCategoryInput(ctx context.Context, v interface{}) (ent.CreateCategoryInput, error) { + res, err := ec.unmarshalInputCreateCategoryInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreateTodoInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (ent.CreateTodoInput, error) { res, err := ec.unmarshalInputCreateTodoInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (*ent.CreateTodoInput, error) { + res, err := ec.unmarshalInputCreateTodoInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCursor2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCursor(ctx context.Context, v interface{}) (ent.Cursor, error) { var res ent.Cursor err := res.UnmarshalGQL(v) @@ -12844,6 +12998,26 @@ func (ec *executionContext) unmarshalOCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCreateTodoInputᚄ(ctx context.Context, v interface{}) ([]*ent.CreateTodoInput, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*ent.CreateTodoInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCreateTodoInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + func (ec *executionContext) unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚐCursor(ctx context.Context, v interface{}) (*ent.Cursor, error) { if v == nil { return nil, nil diff --git a/entgql/internal/todo/todo.graphql b/entgql/internal/todo/todo.graphql index 34cc6346e..c935d8911 100644 --- a/entgql/internal/todo/todo.graphql +++ b/entgql/internal/todo/todo.graphql @@ -22,6 +22,7 @@ extend type Query { } type Mutation { + createCategory(input: CreateCategoryInput!): Category! createTodo(input: CreateTodoInput!): Todo! clearTodos: Int! } @@ -29,3 +30,7 @@ type Mutation { type Custom { info: String! } + +extend input CreateCategoryInput { + createTodos: [CreateTodoInput!] +} \ No newline at end of file diff --git a/entgql/internal/todo/todo.resolvers.go b/entgql/internal/todo/todo.resolvers.go index 869e0870e..0066f86af 100644 --- a/entgql/internal/todo/todo.resolvers.go +++ b/entgql/internal/todo/todo.resolvers.go @@ -25,6 +25,10 @@ import ( "entgo.io/contrib/entgql/internal/todo/ent/todo" ) +func (r *mutationResolver) CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) { + return ent.FromContext(ctx).Category.Create().SetInput(input).Save(ctx) +} + func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) { return ent.FromContext(ctx).Todo. Create(). @@ -43,6 +47,24 @@ func (r *queryResolver) Ping(ctx context.Context) (string, error) { return "pong", nil } +func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { + e := ent.FromContext(ctx) + builders := make([]*ent.TodoCreate, len(data)) + for i, input := range data { + builders[i] = e.Todo.Create().SetInput(*input) + } + todos, err := e.Todo.CreateBulk(builders...).Save(ctx) + if err != nil { + return err + } + ids := make([]int, len(todos)) + for i := range todos { + ids[i] = todos[i].ID + } + obj.TodoIDs = append(obj.TodoIDs, ids...) + return nil +} + func (r *todoWhereInputResolver) CreatedToday(ctx context.Context, obj *ent.TodoWhereInput, data *bool) error { if data == nil { return nil diff --git a/entgql/internal/todo/todo_test.go b/entgql/internal/todo/todo_test.go index 20c9ec2cf..ddc9df147 100644 --- a/entgql/internal/todo/todo_test.go +++ b/entgql/internal/todo/todo_test.go @@ -1812,3 +1812,65 @@ func TestEdgesFiltering(t *testing.T) { require.Equal(t, "t1.1", n.Edges[0].Node.Text) }) } + +func TestMutation_CreateCategory(t *testing.T) { + drv, err := sql.Open(dialect.SQLite, fmt.Sprintf("file:%s?mode=memory&cache=shared&_fk=1", t.Name())) + require.NoError(t, err) + count := &queryCount{Driver: drv} + ec := enttest.NewClient(t, + enttest.WithOptions(ent.Driver(count)), + enttest.WithMigrateOptions(migrate.WithGlobalUniqueID(true)), + ) + srv := handler.NewDefaultServer(gen.NewSchema(ec)) + srv.Use(entgql.Transactioner{TxOpener: ec}) + gqlc := client.New(srv) + + // Create a category. + var rsp struct { + CreateCategory struct { + ID string + Text string + Status string + Todos struct { + TotalCount int + Edges []struct { + Node struct { + Text string + Status string + } + } + } + } + } + err = gqlc.Post(` + mutation createCategory { + createCategory(input: { + text: "cate1" + status: ENABLED + createTodos: [ + { status: IN_PROGRESS, text: "c1.t1" }, + { status: IN_PROGRESS, text: "c1.t2" } + ] + }) { + id + text + status + todos { + totalCount + edges { + node { + text + status + } + } + } + } + } + `, &rsp) + require.NoError(t, err) + + require.Equal(t, 2, rsp.CreateCategory.Todos.TotalCount) + n := rsp.CreateCategory.Todos + require.Equal(t, "c1.t1", n.Edges[0].Node.Text) + require.Equal(t, "c1.t2", n.Edges[1].Node.Text) +} diff --git a/entgql/internal/todogotype/ent.resolvers.go b/entgql/internal/todogotype/ent.resolvers.go index d0ffb7a3c..524c17f92 100644 --- a/entgql/internal/todogotype/ent.resolvers.go +++ b/entgql/internal/todogotype/ent.resolvers.go @@ -94,6 +94,11 @@ func (r *Resolver) Todo() TodoResolver { return &todoResolver{r} } // User returns UserResolver implementation. func (r *Resolver) User() UserResolver { return &userResolver{r} } +// CreateCategoryInput returns CreateCategoryInputResolver implementation. +func (r *Resolver) CreateCategoryInput() CreateCategoryInputResolver { + return &createCategoryInputResolver{r} +} + // CreateTodoInput returns CreateTodoInputResolver implementation. func (r *Resolver) CreateTodoInput() CreateTodoInputResolver { return &createTodoInputResolver{r} } @@ -106,6 +111,7 @@ func (r *Resolver) UpdateTodoInput() UpdateTodoInputResolver { return &updateTod type queryResolver struct{ *Resolver } type todoResolver struct{ *Resolver } type userResolver struct{ *Resolver } +type createCategoryInputResolver struct{ *Resolver } type createTodoInputResolver struct{ *Resolver } type todoWhereInputResolver struct{ *Resolver } type updateTodoInputResolver struct{ *Resolver } diff --git a/entgql/internal/todogotype/generated.go b/entgql/internal/todogotype/generated.go index b73f0f1b1..0e3c1a2a3 100644 --- a/entgql/internal/todogotype/generated.go +++ b/entgql/internal/todogotype/generated.go @@ -47,6 +47,7 @@ type ResolverRoot interface { Query() QueryResolver Todo() TodoResolver User() UserResolver + CreateCategoryInput() CreateCategoryInputResolver CreateTodoInput() CreateTodoInputResolver TodoWhereInput() TodoWhereInputResolver UpdateTodoInput() UpdateTodoInputResolver @@ -121,8 +122,9 @@ type ComplexityRoot struct { } Mutation struct { - ClearTodos func(childComplexity int) int - CreateTodo func(childComplexity int, input ent.CreateTodoInput) int + ClearTodos func(childComplexity int) int + CreateCategory func(childComplexity int, input ent.CreateCategoryInput) int + CreateTodo func(childComplexity int, input ent.CreateTodoInput) int } PageInfo struct { @@ -189,6 +191,7 @@ type ComplexityRoot struct { } type MutationResolver interface { + CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) ClearTodos(ctx context.Context) (int, error) } @@ -209,6 +212,9 @@ type UserResolver interface { Friendships(ctx context.Context, obj *ent.User, after *ent.Cursor, first *int, before *ent.Cursor, last *int, where *ent.FriendshipWhereInput) (*ent.FriendshipConnection, error) } +type CreateCategoryInputResolver interface { + CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error +} type CreateTodoInputResolver interface { Status(ctx context.Context, obj *ent.CreateTodoInput, data todo.Status) error } @@ -487,6 +493,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.ClearTodos(childComplexity), true + case "Mutation.createCategory": + if e.complexity.Mutation.CreateCategory == nil { + break + } + + args, err := ec.field_Mutation_createCategory_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.CreateCategory(childComplexity, args["input"].(ent.CreateCategoryInput)), true + case "Mutation.createTodo": if e.complexity.Mutation.CreateTodo == nil { break @@ -917,6 +935,7 @@ extend type Query { } type Mutation { + createCategory(input: CreateCategoryInput!): Category! createTodo(input: CreateTodoInput!): Todo! clearTodos: Int! } @@ -924,7 +943,10 @@ type Mutation { type Custom { info: String! } -`, BuiltIn: false}, + +extend input CreateCategoryInput { + createTodos: [CreateTodoInput!] +}`, BuiltIn: false}, {Name: "../todo/ent.graphql", Input: `directive @goField(forceResolver: Boolean, name: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION directive @goModel(model: String, models: [String!]) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION type BillProduct implements Node { @@ -1802,6 +1824,21 @@ func (ec *executionContext) field_Group_users_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Mutation_createCategory_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 ent.CreateCategoryInput + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCreateCategoryInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -3844,6 +3881,79 @@ func (ec *executionContext) fieldContext_GroupEdge_cursor(ctx context.Context, f return fc, nil } +func (ec *executionContext) _Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createCategory(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().CreateCategory(rctx, fc.Args["input"].(ent.CreateCategoryInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.Category) + fc.Result = res + return ec.marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCategory(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Category_id(ctx, field) + case "text": + return ec.fieldContext_Category_text(ctx, field) + case "status": + return ec.fieldContext_Category_status(ctx, field) + case "config": + return ec.fieldContext_Category_config(ctx, field) + case "duration": + return ec.fieldContext_Category_duration(ctx, field) + case "count": + return ec.fieldContext_Category_count(ctx, field) + case "strings": + return ec.fieldContext_Category_strings(ctx, field) + case "todos": + return ec.fieldContext_Category_todos(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Category", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createCategory_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_createTodo(ctx, field) if err != nil { @@ -8878,6 +8988,17 @@ func (ec *executionContext) unmarshalInputCreateCategoryInput(ctx context.Contex if err != nil { return it, err } + case "createTodos": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createTodos")) + data, err := ec.unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCreateTodoInputᚄ(ctx, v) + if err != nil { + return it, err + } + if err = ec.resolvers.CreateCategoryInput().CreateTodos(ctx, &it, data); err != nil { + return it, err + } } } @@ -11007,6 +11128,15 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") + case "createCategory": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createCategory(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } case "createTodo": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -12055,6 +12185,20 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } +func (ec *executionContext) marshalNCategory2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v ent.Category) graphql.Marshaler { + return ec._Category(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v *ent.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") + } + return graphql.Null + } + return ec._Category(ctx, sel, v) +} + func (ec *executionContext) unmarshalNCategoryConfigInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚋschemaᚋschematypeᚐCategoryConfig(ctx context.Context, v interface{}) (*schematype.CategoryConfig, error) { res, err := ec.unmarshalInputCategoryConfigInput(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) @@ -12091,11 +12235,21 @@ func (ec *executionContext) unmarshalNCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCreateCategoryInput(ctx context.Context, v interface{}) (ent.CreateCategoryInput, error) { + res, err := ec.unmarshalInputCreateCategoryInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreateTodoInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (ent.CreateTodoInput, error) { res, err := ec.unmarshalInputCreateTodoInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (*ent.CreateTodoInput, error) { + res, err := ec.unmarshalInputCreateTodoInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCursor2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCursor(ctx context.Context, v interface{}) (ent.Cursor, error) { var res ent.Cursor err := res.UnmarshalGQL(v) @@ -12912,6 +13066,26 @@ func (ec *executionContext) unmarshalOCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCreateTodoInputᚄ(ctx context.Context, v interface{}) ([]*ent.CreateTodoInput, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*ent.CreateTodoInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCreateTodoInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + func (ec *executionContext) unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodogotypeᚋentᚐCursor(ctx context.Context, v interface{}) (*ent.Cursor, error) { if v == nil { return nil, nil diff --git a/entgql/internal/todogotype/todo.resolvers.go b/entgql/internal/todogotype/todo.resolvers.go index 6b1b66ba2..28a59f60b 100644 --- a/entgql/internal/todogotype/todo.resolvers.go +++ b/entgql/internal/todogotype/todo.resolvers.go @@ -24,6 +24,10 @@ import ( "entgo.io/contrib/entgql/internal/todogotype/ent" ) +func (r *mutationResolver) CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) { + panic(fmt.Errorf("not implemented")) +} + func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) { panic(fmt.Errorf("not implemented")) } @@ -36,6 +40,10 @@ func (r *queryResolver) Ping(ctx context.Context) (string, error) { panic(fmt.Errorf("not implemented")) } +func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { + panic(fmt.Errorf("not implemented")) +} + func (r *todoWhereInputResolver) CreatedToday(ctx context.Context, obj *ent.TodoWhereInput, data *bool) error { panic(fmt.Errorf("not implemented")) } diff --git a/entgql/internal/todopulid/ent.resolvers.go b/entgql/internal/todopulid/ent.resolvers.go index f65687050..da55825dd 100644 --- a/entgql/internal/todopulid/ent.resolvers.go +++ b/entgql/internal/todopulid/ent.resolvers.go @@ -105,6 +105,11 @@ func (r *Resolver) Todo() TodoResolver { return &todoResolver{r} } // User returns UserResolver implementation. func (r *Resolver) User() UserResolver { return &userResolver{r} } +// CreateCategoryInput returns CreateCategoryInputResolver implementation. +func (r *Resolver) CreateCategoryInput() CreateCategoryInputResolver { + return &createCategoryInputResolver{r} +} + // CreateTodoInput returns CreateTodoInputResolver implementation. func (r *Resolver) CreateTodoInput() CreateTodoInputResolver { return &createTodoInputResolver{r} } @@ -117,6 +122,7 @@ func (r *Resolver) UpdateTodoInput() UpdateTodoInputResolver { return &updateTod type queryResolver struct{ *Resolver } type todoResolver struct{ *Resolver } type userResolver struct{ *Resolver } +type createCategoryInputResolver struct{ *Resolver } type createTodoInputResolver struct{ *Resolver } type todoWhereInputResolver struct{ *Resolver } type updateTodoInputResolver struct{ *Resolver } diff --git a/entgql/internal/todopulid/generated.go b/entgql/internal/todopulid/generated.go index 2a83dc784..cd6cc30d9 100644 --- a/entgql/internal/todopulid/generated.go +++ b/entgql/internal/todopulid/generated.go @@ -47,6 +47,7 @@ type ResolverRoot interface { Query() QueryResolver Todo() TodoResolver User() UserResolver + CreateCategoryInput() CreateCategoryInputResolver CreateTodoInput() CreateTodoInputResolver TodoWhereInput() TodoWhereInputResolver UpdateTodoInput() UpdateTodoInputResolver @@ -121,8 +122,9 @@ type ComplexityRoot struct { } Mutation struct { - ClearTodos func(childComplexity int) int - CreateTodo func(childComplexity int, input ent.CreateTodoInput) int + ClearTodos func(childComplexity int) int + CreateCategory func(childComplexity int, input ent.CreateCategoryInput) int + CreateTodo func(childComplexity int, input ent.CreateTodoInput) int } PageInfo struct { @@ -189,6 +191,7 @@ type ComplexityRoot struct { } type MutationResolver interface { + CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) ClearTodos(ctx context.Context) (int, error) } @@ -209,6 +212,9 @@ type UserResolver interface { Friendships(ctx context.Context, obj *ent.User, after *ent.Cursor, first *int, before *ent.Cursor, last *int, where *ent.FriendshipWhereInput) (*ent.FriendshipConnection, error) } +type CreateCategoryInputResolver interface { + CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error +} type CreateTodoInputResolver interface { Status(ctx context.Context, obj *ent.CreateTodoInput, data todo.Status) error } @@ -487,6 +493,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.ClearTodos(childComplexity), true + case "Mutation.createCategory": + if e.complexity.Mutation.CreateCategory == nil { + break + } + + args, err := ec.field_Mutation_createCategory_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.CreateCategory(childComplexity, args["input"].(ent.CreateCategoryInput)), true + case "Mutation.createTodo": if e.complexity.Mutation.CreateTodo == nil { break @@ -917,6 +935,7 @@ extend type Query { } type Mutation { + createCategory(input: CreateCategoryInput!): Category! createTodo(input: CreateTodoInput!): Todo! clearTodos: Int! } @@ -924,7 +943,10 @@ type Mutation { type Custom { info: String! } -`, BuiltIn: false}, + +extend input CreateCategoryInput { + createTodos: [CreateTodoInput!] +}`, BuiltIn: false}, {Name: "../todo/ent.graphql", Input: `directive @goField(forceResolver: Boolean, name: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION directive @goModel(model: String, models: [String!]) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION type BillProduct implements Node { @@ -1802,6 +1824,21 @@ func (ec *executionContext) field_Group_users_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Mutation_createCategory_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 ent.CreateCategoryInput + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCreateCategoryInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -3844,6 +3881,79 @@ func (ec *executionContext) fieldContext_GroupEdge_cursor(ctx context.Context, f return fc, nil } +func (ec *executionContext) _Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createCategory(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().CreateCategory(rctx, fc.Args["input"].(ent.CreateCategoryInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.Category) + fc.Result = res + return ec.marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCategory(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Category_id(ctx, field) + case "text": + return ec.fieldContext_Category_text(ctx, field) + case "status": + return ec.fieldContext_Category_status(ctx, field) + case "config": + return ec.fieldContext_Category_config(ctx, field) + case "duration": + return ec.fieldContext_Category_duration(ctx, field) + case "count": + return ec.fieldContext_Category_count(ctx, field) + case "strings": + return ec.fieldContext_Category_strings(ctx, field) + case "todos": + return ec.fieldContext_Category_todos(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Category", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createCategory_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_createTodo(ctx, field) if err != nil { @@ -8878,6 +8988,17 @@ func (ec *executionContext) unmarshalInputCreateCategoryInput(ctx context.Contex if err != nil { return it, err } + case "createTodos": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createTodos")) + data, err := ec.unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCreateTodoInputᚄ(ctx, v) + if err != nil { + return it, err + } + if err = ec.resolvers.CreateCategoryInput().CreateTodos(ctx, &it, data); err != nil { + return it, err + } } } @@ -11007,6 +11128,15 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") + case "createCategory": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createCategory(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } case "createTodo": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -12055,6 +12185,20 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } +func (ec *executionContext) marshalNCategory2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v ent.Category) graphql.Marshaler { + return ec._Category(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v *ent.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") + } + return graphql.Null + } + return ec._Category(ctx, sel, v) +} + func (ec *executionContext) unmarshalNCategoryConfigInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚋschemaᚋschematypeᚐCategoryConfig(ctx context.Context, v interface{}) (*schematype.CategoryConfig, error) { res, err := ec.unmarshalInputCategoryConfigInput(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) @@ -12091,11 +12235,21 @@ func (ec *executionContext) unmarshalNCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCreateCategoryInput(ctx context.Context, v interface{}) (ent.CreateCategoryInput, error) { + res, err := ec.unmarshalInputCreateCategoryInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreateTodoInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (ent.CreateTodoInput, error) { res, err := ec.unmarshalInputCreateTodoInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (*ent.CreateTodoInput, error) { + res, err := ec.unmarshalInputCreateTodoInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCursor2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCursor(ctx context.Context, v interface{}) (ent.Cursor, error) { var res ent.Cursor err := res.UnmarshalGQL(v) @@ -12897,6 +13051,26 @@ func (ec *executionContext) unmarshalOCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCreateTodoInputᚄ(ctx context.Context, v interface{}) ([]*ent.CreateTodoInput, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*ent.CreateTodoInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCreateTodoInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + func (ec *executionContext) unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodopulidᚋentᚐCursor(ctx context.Context, v interface{}) (*ent.Cursor, error) { if v == nil { return nil, nil diff --git a/entgql/internal/todopulid/todo.resolvers.go b/entgql/internal/todopulid/todo.resolvers.go index 001432144..4830c003d 100644 --- a/entgql/internal/todopulid/todo.resolvers.go +++ b/entgql/internal/todopulid/todo.resolvers.go @@ -26,6 +26,10 @@ import ( "entgo.io/contrib/entgql/internal/todopulid/ent/todo" ) +func (r *mutationResolver) CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) { + panic(fmt.Errorf("not implemented")) +} + func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) { return ent.FromContext(ctx).Todo. Create(). @@ -44,6 +48,10 @@ func (r *queryResolver) Ping(ctx context.Context) (string, error) { panic(fmt.Errorf("not implemented")) } +func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { + panic(fmt.Errorf("not implemented")) +} + func (r *todoWhereInputResolver) CreatedToday(ctx context.Context, obj *ent.TodoWhereInput, data *bool) error { if data == nil { return nil diff --git a/entgql/internal/todouuid/ent.resolvers.go b/entgql/internal/todouuid/ent.resolvers.go index b17ef29c8..35f286285 100644 --- a/entgql/internal/todouuid/ent.resolvers.go +++ b/entgql/internal/todouuid/ent.resolvers.go @@ -105,6 +105,11 @@ func (r *Resolver) Todo() TodoResolver { return &todoResolver{r} } // User returns UserResolver implementation. func (r *Resolver) User() UserResolver { return &userResolver{r} } +// CreateCategoryInput returns CreateCategoryInputResolver implementation. +func (r *Resolver) CreateCategoryInput() CreateCategoryInputResolver { + return &createCategoryInputResolver{r} +} + // CreateTodoInput returns CreateTodoInputResolver implementation. func (r *Resolver) CreateTodoInput() CreateTodoInputResolver { return &createTodoInputResolver{r} } @@ -117,6 +122,7 @@ func (r *Resolver) UpdateTodoInput() UpdateTodoInputResolver { return &updateTod type queryResolver struct{ *Resolver } type todoResolver struct{ *Resolver } type userResolver struct{ *Resolver } +type createCategoryInputResolver struct{ *Resolver } type createTodoInputResolver struct{ *Resolver } type todoWhereInputResolver struct{ *Resolver } type updateTodoInputResolver struct{ *Resolver } diff --git a/entgql/internal/todouuid/generated.go b/entgql/internal/todouuid/generated.go index 857f9d1a1..e8e573dfe 100644 --- a/entgql/internal/todouuid/generated.go +++ b/entgql/internal/todouuid/generated.go @@ -48,6 +48,7 @@ type ResolverRoot interface { Query() QueryResolver Todo() TodoResolver User() UserResolver + CreateCategoryInput() CreateCategoryInputResolver CreateTodoInput() CreateTodoInputResolver TodoWhereInput() TodoWhereInputResolver UpdateTodoInput() UpdateTodoInputResolver @@ -122,8 +123,9 @@ type ComplexityRoot struct { } Mutation struct { - ClearTodos func(childComplexity int) int - CreateTodo func(childComplexity int, input ent.CreateTodoInput) int + ClearTodos func(childComplexity int) int + CreateCategory func(childComplexity int, input ent.CreateCategoryInput) int + CreateTodo func(childComplexity int, input ent.CreateTodoInput) int } PageInfo struct { @@ -190,6 +192,7 @@ type ComplexityRoot struct { } type MutationResolver interface { + CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) ClearTodos(ctx context.Context) (int, error) } @@ -210,6 +213,9 @@ type UserResolver interface { Friendships(ctx context.Context, obj *ent.User, after *ent.Cursor, first *int, before *ent.Cursor, last *int, where *ent.FriendshipWhereInput) (*ent.FriendshipConnection, error) } +type CreateCategoryInputResolver interface { + CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error +} type CreateTodoInputResolver interface { Status(ctx context.Context, obj *ent.CreateTodoInput, data todo.Status) error } @@ -488,6 +494,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.ClearTodos(childComplexity), true + case "Mutation.createCategory": + if e.complexity.Mutation.CreateCategory == nil { + break + } + + args, err := ec.field_Mutation_createCategory_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.CreateCategory(childComplexity, args["input"].(ent.CreateCategoryInput)), true + case "Mutation.createTodo": if e.complexity.Mutation.CreateTodo == nil { break @@ -918,6 +936,7 @@ extend type Query { } type Mutation { + createCategory(input: CreateCategoryInput!): Category! createTodo(input: CreateTodoInput!): Todo! clearTodos: Int! } @@ -925,7 +944,10 @@ type Mutation { type Custom { info: String! } -`, BuiltIn: false}, + +extend input CreateCategoryInput { + createTodos: [CreateTodoInput!] +}`, BuiltIn: false}, {Name: "../todo/ent.graphql", Input: `directive @goField(forceResolver: Boolean, name: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION directive @goModel(model: String, models: [String!]) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION type BillProduct implements Node { @@ -1803,6 +1825,21 @@ func (ec *executionContext) field_Group_users_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Mutation_createCategory_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 ent.CreateCategoryInput + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCreateCategoryInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -3845,6 +3882,79 @@ func (ec *executionContext) fieldContext_GroupEdge_cursor(ctx context.Context, f return fc, nil } +func (ec *executionContext) _Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createCategory(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().CreateCategory(rctx, fc.Args["input"].(ent.CreateCategoryInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*ent.Category) + fc.Result = res + return ec.marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCategory(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_createCategory(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Category_id(ctx, field) + case "text": + return ec.fieldContext_Category_text(ctx, field) + case "status": + return ec.fieldContext_Category_status(ctx, field) + case "config": + return ec.fieldContext_Category_config(ctx, field) + case "duration": + return ec.fieldContext_Category_duration(ctx, field) + case "count": + return ec.fieldContext_Category_count(ctx, field) + case "strings": + return ec.fieldContext_Category_strings(ctx, field) + case "todos": + return ec.fieldContext_Category_todos(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Category", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createCategory_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_createTodo(ctx, field) if err != nil { @@ -8879,6 +8989,17 @@ func (ec *executionContext) unmarshalInputCreateCategoryInput(ctx context.Contex if err != nil { return it, err } + case "createTodos": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createTodos")) + data, err := ec.unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCreateTodoInputᚄ(ctx, v) + if err != nil { + return it, err + } + if err = ec.resolvers.CreateCategoryInput().CreateTodos(ctx, &it, data); err != nil { + return it, err + } } } @@ -11008,6 +11129,15 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") + case "createCategory": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createCategory(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } case "createTodo": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -12056,6 +12186,20 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } +func (ec *executionContext) marshalNCategory2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v ent.Category) graphql.Marshaler { + return ec._Category(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCategory2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCategory(ctx context.Context, sel ast.SelectionSet, v *ent.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") + } + return graphql.Null + } + return ec._Category(ctx, sel, v) +} + func (ec *executionContext) unmarshalNCategoryConfigInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodoᚋentᚋschemaᚋschematypeᚐCategoryConfig(ctx context.Context, v interface{}) (*schematype.CategoryConfig, error) { res, err := ec.unmarshalInputCategoryConfigInput(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) @@ -12092,11 +12236,21 @@ func (ec *executionContext) unmarshalNCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateCategoryInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCreateCategoryInput(ctx context.Context, v interface{}) (ent.CreateCategoryInput, error) { + res, err := ec.unmarshalInputCreateCategoryInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreateTodoInput2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (ent.CreateTodoInput, error) { res, err := ec.unmarshalInputCreateTodoInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCreateTodoInput(ctx context.Context, v interface{}) (*ent.CreateTodoInput, error) { + res, err := ec.unmarshalInputCreateTodoInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCursor2entgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCursor(ctx context.Context, v interface{}) (ent.Cursor, error) { var res ent.Cursor err := res.UnmarshalGQL(v) @@ -12903,6 +13057,26 @@ func (ec *executionContext) unmarshalOCategoryWhereInput2ᚖentgoᚗioᚋcontrib return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOCreateTodoInput2ᚕᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCreateTodoInputᚄ(ctx context.Context, v interface{}) ([]*ent.CreateTodoInput, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*ent.CreateTodoInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNCreateTodoInput2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCreateTodoInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + func (ec *executionContext) unmarshalOCursor2ᚖentgoᚗioᚋcontribᚋentgqlᚋinternalᚋtodouuidᚋentᚐCursor(ctx context.Context, v interface{}) (*ent.Cursor, error) { if v == nil { return nil, nil diff --git a/entgql/internal/todouuid/todo.resolvers.go b/entgql/internal/todouuid/todo.resolvers.go index c15cf9aa2..3b67dd138 100644 --- a/entgql/internal/todouuid/todo.resolvers.go +++ b/entgql/internal/todouuid/todo.resolvers.go @@ -26,6 +26,10 @@ import ( "entgo.io/contrib/entgql/internal/todouuid/ent/todo" ) +func (r *mutationResolver) CreateCategory(ctx context.Context, input ent.CreateCategoryInput) (*ent.Category, error) { + panic(fmt.Errorf("not implemented")) +} + func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) { return ent.FromContext(ctx).Todo. Create(). @@ -44,6 +48,10 @@ func (r *queryResolver) Ping(ctx context.Context) (string, error) { panic(fmt.Errorf("not implemented")) } +func (r *createCategoryInputResolver) CreateTodos(ctx context.Context, obj *ent.CreateCategoryInput, data []*ent.CreateTodoInput) error { + panic(fmt.Errorf("not implemented")) +} + func (r *todoWhereInputResolver) CreatedToday(ctx context.Context, obj *ent.TodoWhereInput, data *bool) error { if data == nil { return nil