ozon-task/graph/mutation.resolvers.go
erius e0aa12b126 Separated graphql schema into multiple files and moved them to graph/schema dir, update the gqlgen.yml accordingly
Removed unnecesary bindings for ID and Int in gqlgen.yml
Minor changes to Makefile docker-clean target
Reduced docker-compose postgres healthcheck interval for faster local db connections
Added pagination to graphql schema, the paginated queries are WIP
Removed unneeded fields from the model structs
Added allowComment check when adding comments
Switched gorm logger to Info mode
App now panics if the specified APP_STORAGE in env doesn't exist
Reworked database methods, still barely working and are WIP
2024-06-26 04:45:04 +03:00

38 lines
1.3 KiB
Go

package graph
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.49
import (
"context"
"fmt"
"git.obamna.ru/erius/ozon-task/graph/model"
)
// AddPost is the resolver for the add_post field.
func (r *mutationResolver) AddPost(ctx context.Context, input model.PostInput) (*model.AddResult, error) {
return r.Storage.AddPost(&input)
}
// AddComment is the resolver for the add_comment field.
func (r *mutationResolver) AddComment(ctx context.Context, input model.CommentInput) (*model.AddResult, error) {
if len(input.Contents) > model.CommentLengthLimit {
return nil, fmt.Errorf("exceeded max comment length of %d chars", model.CommentLengthLimit)
}
switch {
case input.ParentPostID != nil:
return r.Storage.AddCommentToPost(&input)
case input.ParentCommentID != nil:
return r.Storage.AddReplyToComment(&input)
default:
return nil, fmt.Errorf("parent post or parent comment ids weren't specified")
}
}
// Mutation returns MutationResolver implementation.
func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
type mutationResolver struct{ *Resolver }