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.

41 lines
811 B

  1. package types
  2. import (
  3. "context"
  4. "errors"
  5. "time"
  6. "git.aiterp.net/rpdata/api/internal/loader"
  7. "git.aiterp.net/rpdata/api/models"
  8. )
  9. type commentResolver struct{}
  10. func (r *commentResolver) Character(ctx context.Context, obj *models.Comment) (*models.Character, error) {
  11. if obj.CharacterID == "" {
  12. return nil, nil
  13. }
  14. loader := loader.FromContext(ctx)
  15. if loader == nil {
  16. return nil, errors.New("no loader")
  17. }
  18. character, err := loader.Character("id", obj.CharacterID)
  19. if err != nil {
  20. return nil, err
  21. }
  22. return &character, nil
  23. }
  24. func (r *commentResolver) FictionalDate(ctx context.Context, obj *models.Comment) (*time.Time, error) {
  25. if obj.FictionalDate.IsZero() {
  26. return nil, nil
  27. }
  28. return &obj.FictionalDate, nil
  29. }
  30. // CommentResolver is a resolver
  31. var CommentResolver commentResolver