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.

45 lines
974 B

  1. package types
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/repositories"
  5. "git.aiterp.net/rpdata/api/services"
  6. "github.com/globalsign/mgo"
  7. "time"
  8. "git.aiterp.net/rpdata/api/models"
  9. )
  10. type commentResolver struct {
  11. characters *services.CharacterService
  12. }
  13. func (r *commentResolver) Character(ctx context.Context, obj *models.Comment) (*models.Character, error) {
  14. if obj.CharacterID == "" {
  15. return nil, nil
  16. }
  17. character, err := r.characters.Find(ctx, obj.CharacterID)
  18. if err != nil {
  19. if err == repositories.ErrNotFound || err == mgo.ErrNotFound {
  20. return nil, nil
  21. }
  22. return nil, err
  23. }
  24. return character, nil
  25. }
  26. func (r *commentResolver) FictionalDate(ctx context.Context, obj *models.Comment) (*time.Time, error) {
  27. if obj.FictionalDate.IsZero() {
  28. return nil, nil
  29. }
  30. return &obj.FictionalDate, nil
  31. }
  32. // CommentResolver is a resolver
  33. func CommentResolver(s *services.Bundle) *commentResolver {
  34. return &commentResolver{characters: s.Characters}
  35. }