This commit is contained in:
+12
-2
@@ -19,7 +19,7 @@ func (r *chapterResolver) FictionalDate(ctx context.Context, chapter *models.Cha
|
||||
return &chapter.FictionalDate, nil
|
||||
}
|
||||
|
||||
func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter, limit *int) ([]models.Comment, error) {
|
||||
func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter, limit *int) ([]*models.Comment, error) {
|
||||
limitValue := 0
|
||||
if limit != nil {
|
||||
if *limit < 0 {
|
||||
@@ -33,7 +33,17 @@ func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter,
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return comments.ListChapterID(chapter.ID, limitValue)
|
||||
comments, err := comments.ListChapterID(chapter.ID, limitValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
comments2 := make([]*models.Comment, len(comments))
|
||||
for i, comment := range comments {
|
||||
comments2[i] = &comment
|
||||
}
|
||||
|
||||
return comments2, nil
|
||||
}
|
||||
|
||||
// ChapterResolver is a resolver
|
||||
|
||||
+24
-8
@@ -20,21 +20,37 @@ func (r *logResolver) Channel(ctx context.Context, log *models.Log) (*models.Cha
|
||||
return loader.Channel("name", log.ChannelName)
|
||||
}
|
||||
|
||||
func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]models.Character, error) {
|
||||
func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]*models.Character, error) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
return loader.Characters("id", log.CharacterIDs...)
|
||||
characters, err := loader.Characters("id", log.CharacterIDs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
characters2 := make([]*models.Character, len(characters))
|
||||
for i, character := range characters {
|
||||
characters2[i] = &character
|
||||
}
|
||||
|
||||
return characters2, nil
|
||||
}
|
||||
|
||||
func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]models.Post, error) {
|
||||
return posts.List(&posts.Filter{
|
||||
LogID: &log.ShortID,
|
||||
Kind: kinds,
|
||||
Limit: 0,
|
||||
})
|
||||
func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]*models.Post, error) {
|
||||
posts, err := posts.List(&posts.Filter{LogID: &log.ShortID, Kind: kinds, Limit: 0})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
posts2 := make([]*models.Post, len(posts))
|
||||
for i, post := range posts {
|
||||
posts2[i] = &post
|
||||
}
|
||||
|
||||
return posts2, nil
|
||||
}
|
||||
|
||||
// LogResolver is a resolver
|
||||
|
||||
+12
-2
@@ -19,8 +19,18 @@ func (r *storyResolver) FictionalDate(ctx context.Context, story *models.Story)
|
||||
return &story.FictionalDate, nil
|
||||
}
|
||||
|
||||
func (r *storyResolver) Chapters(ctx context.Context, story *models.Story) ([]models.Chapter, error) {
|
||||
return chapters.ListStoryID(story.ID)
|
||||
func (r *storyResolver) Chapters(ctx context.Context, story *models.Story) ([]*models.Chapter, error) {
|
||||
chapters, err := chapters.ListStoryID(story.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chapters2 := make([]*models.Chapter, len(chapters))
|
||||
for i, chapter := range chapters {
|
||||
chapters2[i] = &chapter
|
||||
}
|
||||
|
||||
return chapters2, nil
|
||||
}
|
||||
|
||||
// StoryResolver is a resolver
|
||||
|
||||
Reference in New Issue
Block a user