-
-
Save holykol/c8056f4bb80c0b17e3478a85cbd27be2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Op int | |
const ( | |
OpNull Op = 0 | |
OpCreate Op = 1 | |
OpModify Op = 2 | |
OpDelete Op = 3 | |
) | |
var OpName = map[int]string{ | |
0: "NULL", | |
1: "CREATE", | |
2: "MODIFY", | |
3: "DELETE", | |
} | |
var OpValue = map[string]int{ | |
"NULL": 0, | |
"CREATE": 1, | |
"MODIFY": 2, | |
"DELETE": 3, | |
} | |
func (e Op) IsValid() bool { | |
switch e { | |
case OpNull, OpCreate, OpModify, OpDelete: | |
return true | |
} | |
return false | |
} | |
func (e Op) String() string { | |
return OpName[int(e)] | |
} | |
func (e *Op) UnmarshalGQL(v interface{}) error { | |
value, ok := v.(int) | |
if !ok { | |
return fmt.Errorf("enums must be integers") | |
} | |
*e = Op(value) | |
if !e.IsValid() { | |
return fmt.Errorf("%v is not a valid Op", value) | |
} | |
return nil | |
} | |
func (e Op) MarshalGQL(w io.Writer) { | |
fmt.Fprint(w, e) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
directive @intEnum on ENUM | |
enum Op @intEnum { | |
NULL | |
CREATE | |
MODIFY | |
DELETE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment