I have defined following enum type in my graphql schema
enum TimeUnit {
Day
Week
Month
Year
}
I am using apollo graphql client and generating models which create a java enum like:
public enum TimeUnit {
DAY("Day"),
WEEK("Week"),
MONTH("Month"),
YEAR("Year"),
/**
* Auto generated constant for unknown enum values
*/
$UNKNOWN("$UNKNOWN");
private final String rawValue;
TimeUnit(String rawValue) {
this.rawValue = rawValue;
}
public String rawValue() {
return rawValue;
}
public static TimeUnit safeValueOf(String rawValue) {
for (TimeUnit enumValue : values()) {
if (enumValue.rawValue.equals(rawValue)) {
return enumValue;
}
}
return TimeUnit.$UNKNOWN;
}
}
I would like to code generation to avoid upcasting the enum values. i.e Day –> DAY. I know the raw type is available in this case but still would like to avoid this. Main reason is, we have multiple interfaces for our graphQL server, i.e. apollo client as well as a raw rest based client. We want to avoid clients seeing two different values, i.e. from rest client "Day" whereas from apollo client "DAY".
I will appreciate help from the community. thanks.
I looked at the apollo graphql documentation from code generation but did not find any directive which can disable the enum value upcasting.