v0.0.14 Добавлен query получения всех комментариев поста, также изменена схема получения постов, вместо списка комментариев он отдает количество комментариев
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6107beece9
commit
9f6c39e5ac
@ -130,6 +130,7 @@ type ComplexityRoot struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Query struct {
|
Query struct {
|
||||||
|
Comments func(childComplexity int, postID int) int
|
||||||
GetChatHistory func(childComplexity int, userID int) int
|
GetChatHistory func(childComplexity int, userID int) int
|
||||||
GetUserChats func(childComplexity int) int
|
GetUserChats func(childComplexity int) int
|
||||||
Me 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)
|
GetChatHistory(ctx context.Context, userID int) ([]*domain.Message, error)
|
||||||
GetUserChats(ctx context.Context) ([]*ChatSession, error)
|
GetUserChats(ctx context.Context) ([]*ChatSession, error)
|
||||||
MySessions(ctx context.Context) ([]*domain.Session, error)
|
MySessions(ctx context.Context) ([]*domain.Session, error)
|
||||||
|
Comments(ctx context.Context, postID int) ([]*domain.Comment, error)
|
||||||
}
|
}
|
||||||
type SessionResolver interface {
|
type SessionResolver interface {
|
||||||
StartedAt(ctx context.Context, obj *domain.Session) (string, error)
|
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
|
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":
|
case "Query.getChatHistory":
|
||||||
if e.complexity.Query.GetChatHistory == nil {
|
if e.complexity.Query.GetChatHistory == nil {
|
||||||
break
|
break
|
||||||
@ -1268,6 +1282,17 @@ func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs
|
|||||||
return args, nil
|
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) {
|
func (ec *executionContext) field_Query_getChatHistory_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||||
var err error
|
var err error
|
||||||
args := map[string]any{}
|
args := map[string]any{}
|
||||||
@ -4565,6 +4590,75 @@ func (ec *executionContext) fieldContext_Query_mySessions(_ context.Context, fie
|
|||||||
return fc, nil
|
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) {
|
func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||||
fc, err := ec.fieldContext_Query___type(ctx, field)
|
fc, err := ec.fieldContext_Query___type(ctx, field)
|
||||||
if err != nil {
|
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) })
|
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) })
|
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })
|
||||||
case "__type":
|
case "__type":
|
||||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
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)
|
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 {
|
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 v == nil {
|
||||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||||
|
|||||||
@ -103,6 +103,7 @@ type Query {
|
|||||||
getChatHistory(userId: Int!): [Message!]!
|
getChatHistory(userId: Int!): [Message!]!
|
||||||
getUserChats: [ChatSession!]!
|
getUserChats: [ChatSession!]!
|
||||||
mySessions: [Session!]!
|
mySessions: [Session!]!
|
||||||
|
comments(postID: Int!): [Comment!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
# Мутации (изменение данных)
|
# Мутации (изменение данных)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user