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.

40 lines
847 B

  1. package resolvers
  2. import (
  3. "context"
  4. "errors"
  5. "git.aiterp.net/rpdata/api/models"
  6. "git.aiterp.net/rpdata/api/models/changes"
  7. )
  8. /// Queries
  9. func (r *queryResolver) Changes(ctx context.Context, filter *changes.Filter) ([]*models.Change, error) {
  10. changes, err := changes.List(filter)
  11. if err != nil {
  12. return nil, err
  13. }
  14. changes2 := make([]*models.Change, len(changes))
  15. for i := range changes {
  16. changes2[i] = &changes[i]
  17. }
  18. return changes2, nil
  19. }
  20. /// Subscriptions
  21. func (r *subscriptionResolver) Changes(ctx context.Context, keys []*models.ChangeKey) (<-chan *models.Change, error) {
  22. if len(keys) == 0 {
  23. return nil, errors.New("At least one key is required for a subscription")
  24. }
  25. keys2 := make([]models.ChangeKey, len(keys))
  26. for i := range keys {
  27. keys2[i] = *keys[i]
  28. }
  29. return changes.Subscribe(ctx, keys2, false), nil
  30. }