Enum with int values #1898
Replies: 13 comments 1 reply
-
Good idea! Like |
Beta Was this translation helpful? Give feedback.
-
This is probably a good use-case for |
Beta Was this translation helpful? Give feedback.
-
The other option would be custom mapping - you'd be opting out of model generation, but you could map the enum however you like |
Beta Was this translation helpful? Give feedback.
-
@lwc How the directive function looks like?
|
Beta Was this translation helpful? Give feedback.
-
Another vote for numeric enums type ItemStatus int
const (
Waiting ItemStatus = iota
Filled
BackOrdered
OrderExceeded
NotOrdered
)
func (s ItemStatus) String() string {
switch s {
case Waiting:
return "Waiting"
case Filled:
return "Filled"
case BackOrdered:
return "Back Ordered"
case OrderExceeded:
return "Order Exceeded"
case NotOrdered:
return "Not Ordered"
default:
return fmt.Sprintf("%d", int(s))
}
} |
Beta Was this translation helpful? Give feedback.
-
It would also be great for a simple permission system, so I could check for |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
@vektah Could you please reopen this issue. Thanks |
Beta Was this translation helpful? Give feedback.
-
@karthikraobr thanks! |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
No stale |
Beta Was this translation helpful? Give feedback.
-
Right now I'm using this fork of enumer which adds GQLGen support via this PR. It may help people :) |
Beta Was this translation helpful? Give feedback.
-
Is there any progress on this? I'm guessing the above solution won't be merged cause it's solution that adds hacky code which only provides int enums instead of abstacting type support. My current work around for people wanting to this (doesnt fully auto-generate) schema.graphqls
run add to YOUR_MODEL_FILE.go
|
Beta Was this translation helpful? Give feedback.
-
Is it possible to generate enum with int values rather than string values? Something that looks like the below code?
Minimal graphql.schema and models to reproduce
Generates
Is there any way to generate int values rather than string values for enums? Perhaps a custom resolver?
Beta Was this translation helpful? Give feedback.
All reactions