From 9f6c39e5ac5216b1c9aed673c9c9672aac6bc12c Mon Sep 17 00:00:00 2001 From: madipo2611 Date: Wed, 6 Aug 2025 22:49:09 +0300 Subject: [PATCH] =?UTF-8?q?v0.0.14=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20query=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B2=D1=81=D0=B5=D1=85=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D1=82=D0=B0,=20=D1=82=D0=B0=D0=BA=D0=B6?= =?UTF-8?q?=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D1=85=D0=B5=D0=BC=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?,=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D1=81=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B5=D0=B2=20=D0=BE=D0=BD=20=D0=BE=D1=82?= =?UTF-8?q?=D0=B4=D0=B0=D0=B5=D1=82=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B2=D0=BE=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/http/graph/generated.go | 160 +++++++++++++++++++++++++++++ internal/http/graph/schema.graphql | 1 + 2 files changed, 161 insertions(+) diff --git a/internal/http/graph/generated.go b/internal/http/graph/generated.go index 3d34ffb..420cbd0 100644 --- a/internal/http/graph/generated.go +++ b/internal/http/graph/generated.go @@ -130,6 +130,7 @@ type ComplexityRoot struct { } Query struct { + Comments func(childComplexity int, postID int) int GetChatHistory func(childComplexity int, userID int) int GetUserChats func(childComplexity int) int Me func(childComplexity int) int @@ -228,6 +229,7 @@ type QueryResolver interface { GetChatHistory(ctx context.Context, userID int) ([]*domain.Message, error) GetUserChats(ctx context.Context) ([]*ChatSession, error) MySessions(ctx context.Context) ([]*domain.Session, error) + Comments(ctx context.Context, postID int) ([]*domain.Comment, error) } type SessionResolver interface { StartedAt(ctx context.Context, obj *domain.Session) (string, error) @@ -697,6 +699,18 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.complexity.Post.UpdatedAt(childComplexity), true + case "Query.comments": + if e.complexity.Query.Comments == nil { + break + } + + args, err := ec.field_Query_comments_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Comments(childComplexity, args["postID"].(int)), true + case "Query.getChatHistory": if e.complexity.Query.GetChatHistory == nil { break @@ -1268,6 +1282,17 @@ func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Query_comments_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := processArgField(ctx, rawArgs, "postID", ec.unmarshalNInt2int) + if err != nil { + return nil, err + } + args["postID"] = arg0 + return args, nil +} + func (ec *executionContext) field_Query_getChatHistory_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -4565,6 +4590,75 @@ func (ec *executionContext) fieldContext_Query_mySessions(_ context.Context, fie return fc, nil } +func (ec *executionContext) _Query_comments(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_comments(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) (any, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Comments(rctx, fc.Args["postID"].(int)) + }) + 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.([]*domain.Comment) + fc.Result = res + return ec.marshalNComment2ᚕᚖtailly_back_v2ᚋinternalᚋdomainᚐCommentᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_comments(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + 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_Comment_id(ctx, field) + case "content": + return ec.fieldContext_Comment_content(ctx, field) + case "post": + return ec.fieldContext_Comment_post(ctx, field) + case "author": + return ec.fieldContext_Comment_author(ctx, field) + case "createdAt": + return ec.fieldContext_Comment_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Comment_updatedAt(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Comment", 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_Query_comments_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Query___type(ctx, field) if err != nil { @@ -8846,6 +8940,28 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "comments": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_comments(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "__type": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -9708,6 +9824,50 @@ func (ec *executionContext) marshalNComment2tailly_back_v2ᚋinternalᚋdomain return ec._Comment(ctx, sel, &v) } +func (ec *executionContext) marshalNComment2ᚕᚖtailly_back_v2ᚋinternalᚋdomainᚐCommentᚄ(ctx context.Context, sel ast.SelectionSet, v []*domain.Comment) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNComment2ᚖtailly_back_v2ᚋinternalᚋdomainᚐComment(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + func (ec *executionContext) marshalNComment2ᚖtailly_back_v2ᚋinternalᚋdomainᚐComment(ctx context.Context, sel ast.SelectionSet, v *domain.Comment) graphql.Marshaler { if v == nil { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { diff --git a/internal/http/graph/schema.graphql b/internal/http/graph/schema.graphql index ff588ca..24cc874 100644 --- a/internal/http/graph/schema.graphql +++ b/internal/http/graph/schema.graphql @@ -103,6 +103,7 @@ type Query { getChatHistory(userId: Int!): [Message!]! getUserChats: [ChatSession!]! mySessions: [Session!]! + comments(postID: Int!): [Comment!]! } # Мутации (изменение данных)