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
964 B

  1. package types
  2. import (
  3. "context"
  4. "errors"
  5. "git.aiterp.net/rpdata/api/internal/loader"
  6. "git.aiterp.net/rpdata/api/models"
  7. "git.aiterp.net/rpdata/api/models/posts"
  8. )
  9. type logResolver struct{}
  10. func (r *logResolver) Channel(ctx context.Context, log *models.Log) (models.Channel, error) {
  11. loader := loader.FromContext(ctx)
  12. if loader == nil {
  13. return models.Channel{}, errors.New("no loader")
  14. }
  15. return loader.Channel("name", log.ChannelName)
  16. }
  17. func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]models.Character, error) {
  18. loader := loader.FromContext(ctx)
  19. if loader == nil {
  20. return nil, errors.New("no loader")
  21. }
  22. return loader.Characters("id", log.CharacterIDs...)
  23. }
  24. func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]models.Post, error) {
  25. return posts.List(&posts.Filter{
  26. LogID: &log.ShortID,
  27. Kind: kinds,
  28. Limit: 0,
  29. })
  30. }
  31. // LogResolver is a resolver
  32. var LogResolver logResolver