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.
 
 

37 lines
1005 B

package types
import (
"context"
"git.aiterp.net/rpdata/api/services"
"git.aiterp.net/rpdata/api/models"
)
type logResolver struct {
logs *services.LogService
characters *services.CharacterService
channels *services.ChannelService
}
func (r *logResolver) Channel(ctx context.Context, log *models.Log) (*models.Channel, error) {
return r.channels.Find(ctx, log.ChannelName)
}
func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]*models.Character, error) {
if len(log.CharacterIDs) == 0 {
return []*models.Character{}, nil
}
return r.characters.List(ctx, models.CharacterFilter{
IDs: log.CharacterIDs,
})
}
func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]*models.Post, error) {
return r.logs.ListPosts(ctx, &models.PostFilter{LogID: &log.ShortID})
}
// LogResolver is a resolver
func LogResolver(s *services.Bundle) *logResolver {
return &logResolver{characters: s.Characters, logs: s.Logs, channels: s.Channels}
}