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.

34 lines
863 B

  1. package queries
  2. import (
  3. "context"
  4. "errors"
  5. "git.aiterp.net/rpdata/api/models"
  6. "git.aiterp.net/rpdata/api/models/posts"
  7. )
  8. func (r *resolver) Post(ctx context.Context, id string) (models.Post, error) {
  9. return posts.FindID(id)
  10. }
  11. func (r *resolver) Posts(ctx context.Context, filter *posts.Filter) ([]models.Post, error) {
  12. // Some sanity checks to avoid querying an insame amount of posts.
  13. if filter == nil {
  14. filter = &posts.Filter{Limit: 256}
  15. } else {
  16. if (filter.Limit <= 0 || filter.Limit > 256) && filter.LogID == nil {
  17. return nil, errors.New("a limit of 0 (no limit) or >256 without a logId is not allowed")
  18. }
  19. if len(filter.Kind) > 32 {
  20. return nil, errors.New("You cannot specify more than 32 kinds")
  21. }
  22. if len(filter.ID) > 32 {
  23. return nil, errors.New("You cannot specify more than 32 IDs")
  24. }
  25. }
  26. return posts.List(filter)
  27. }