github.com/maeglindeveloper/gqlgen@v0.13.1-0.20210413081235-57808b12a0a0/example/type-system-extension/models_gen.go (about) 1 // Code generated by github.com/99designs/gqlgen, DO NOT EDIT. 2 3 package type_system_extension 4 5 import ( 6 "fmt" 7 "io" 8 "strconv" 9 ) 10 11 type Data interface { 12 IsData() 13 } 14 15 type Node interface { 16 IsNode() 17 } 18 19 type Todo struct { 20 ID string `json:"id"` 21 Text string `json:"text"` 22 State State `json:"state"` 23 Verified bool `json:"verified"` 24 } 25 26 func (Todo) IsNode() {} 27 func (Todo) IsData() {} 28 29 type TodoInput struct { 30 Text string `json:"text"` 31 } 32 33 type State string 34 35 const ( 36 StateNotYet State = "NOT_YET" 37 StateDone State = "DONE" 38 ) 39 40 var AllState = []State{ 41 StateNotYet, 42 StateDone, 43 } 44 45 func (e State) IsValid() bool { 46 switch e { 47 case StateNotYet, StateDone: 48 return true 49 } 50 return false 51 } 52 53 func (e State) String() string { 54 return string(e) 55 } 56 57 func (e *State) UnmarshalGQL(v interface{}) error { 58 str, ok := v.(string) 59 if !ok { 60 return fmt.Errorf("enums must be strings") 61 } 62 63 *e = State(str) 64 if !e.IsValid() { 65 return fmt.Errorf("%s is not a valid State", str) 66 } 67 return nil 68 } 69 70 func (e State) MarshalGQL(w io.Writer) { 71 fmt.Fprint(w, strconv.Quote(e.String())) 72 }