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.

43 lines
1.2 KiB

  1. package models
  2. import (
  3. "fmt"
  4. "io"
  5. )
  6. // StoryCategory represents the category of a story.
  7. type StoryCategory string
  8. const (
  9. // StoryCategoryInfo is a story category, see GraphQL documentation.
  10. StoryCategoryInfo StoryCategory = "Info"
  11. // StoryCategoryNews is a story category, see GraphQL documentation.
  12. StoryCategoryNews StoryCategory = "News"
  13. // StoryCategoryDocument is a story category, see GraphQL documentation.
  14. StoryCategoryDocument StoryCategory = "Document"
  15. // StoryCategoryBackground is a story category, see GraphQL documentation.
  16. StoryCategoryBackground StoryCategory = "Background"
  17. // StoryCategoryStory is a story category, see GraphQL documentation.
  18. StoryCategoryStory StoryCategory = "Story"
  19. )
  20. // UnmarshalGQL unmarshals
  21. func (e *StoryCategory) UnmarshalGQL(v interface{}) error {
  22. str, ok := v.(string)
  23. if !ok {
  24. return fmt.Errorf("enums must be strings")
  25. }
  26. *e = StoryCategory(str)
  27. switch *e {
  28. case StoryCategoryInfo, StoryCategoryNews, StoryCategoryDocument, StoryCategoryBackground, StoryCategoryStory:
  29. return nil
  30. default:
  31. return fmt.Errorf("%s is not a valid StoryCategory", str)
  32. }
  33. }
  34. // MarshalGQL turns it into a JSON string
  35. func (e StoryCategory) MarshalGQL(w io.Writer) {
  36. fmt.Fprint(w, "\""+string(e)+"\"")
  37. }