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

package types
import (
"context"
"git.aiterp.net/rpdata/api/repositories"
"git.aiterp.net/rpdata/api/services"
"github.com/globalsign/mgo"
"time"
"git.aiterp.net/rpdata/api/models"
)
type commentResolver struct {
characters *services.CharacterService
}
func (r *commentResolver) Character(ctx context.Context, obj *models.Comment) (*models.Character, error) {
if obj.CharacterID == "" {
return nil, nil
}
character, err := r.characters.Find(ctx, obj.CharacterID)
if err != nil {
if err == repositories.ErrNotFound || err == mgo.ErrNotFound {
return nil, nil
}
return nil, err
}
return character, nil
}
func (r *commentResolver) FictionalDate(ctx context.Context, obj *models.Comment) (*time.Time, error) {
if obj.FictionalDate.IsZero() {
return nil, nil
}
return &obj.FictionalDate, nil
}
// CommentResolver is a resolver
func CommentResolver(s *services.Bundle) *commentResolver {
return &commentResolver{characters: s.Characters}
}