GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
762 B

  1. package types
  2. import (
  3. "context"
  4. "errors"
  5. "time"
  6. "git.aiterp.net/rpdata/api/models"
  7. "git.aiterp.net/rpdata/api/models/comments"
  8. )
  9. type chapterResolver struct{}
  10. func (r *chapterResolver) FictionalDate(ctx context.Context, chapter *models.Chapter) (*time.Time, error) {
  11. if chapter.FictionalDate.IsZero() {
  12. return nil, nil
  13. }
  14. return &chapter.FictionalDate, nil
  15. }
  16. func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter, limit *int) ([]models.Comment, error) {
  17. limitValue := 0
  18. if limit != nil {
  19. if *limit < 0 {
  20. return nil, errors.New("Limit cannot be negative")
  21. }
  22. limitValue = *limit
  23. }
  24. return comments.ListChapterID(chapter.ID, limitValue)
  25. }
  26. // ChapterResolver is a resolver
  27. var ChapterResolver chapterResolver