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.
 
 

53 lines
1.4 KiB

package models
import (
"errors"
"fmt"
"io"
)
// StoryCategory represents the category of a story.
type StoryCategory string
const (
// StoryCategoryInfo is a story category, see GraphQL documentation.
StoryCategoryInfo StoryCategory = "Info"
// StoryCategoryNews is a story category, see GraphQL documentation.
StoryCategoryNews StoryCategory = "News"
// StoryCategoryDocument is a story category, see GraphQL documentation.
StoryCategoryDocument StoryCategory = "Document"
// StoryCategoryBackground is a story category, see GraphQL documentation.
StoryCategoryBackground StoryCategory = "Background"
// StoryCategoryStory is a story category, see GraphQL documentation.
StoryCategoryStory StoryCategory = "Story"
)
// IsValid returns whether the category is one of the valid values.
func (e *StoryCategory) IsValid() bool {
switch *e {
case StoryCategoryInfo, StoryCategoryNews, StoryCategoryDocument, StoryCategoryBackground, StoryCategoryStory:
return true
default:
return false
}
}
// UnmarshalGQL unmarshals
func (e *StoryCategory) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return errors.New("enums must be strings")
}
*e = StoryCategory(str)
if !e.IsValid() {
return fmt.Errorf("\"%s\" is not a valid StoryCategory", str)
}
return nil
}
// MarshalGQL turns it into a JSON string
func (e StoryCategory) MarshalGQL(w io.Writer) {
fmt.Fprint(w, "\""+string(e)+"\"")
}