You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In previous versions of relay it was possible to define interfaces that defined a String! field, and that field could then be specialized to an enum object the implemented this interface, such that the compiler would treat the specialized value as a sub-type of the String!. For example, I could define this interface:
enum UserStatus {
active
banned
inactive
}
type User implements StatusChangeable {
status: UserStatus!
}
This way any code that used the User type directly could be typed properly to handle the specific values that User supports, while code that cared only about the StatusChangeable didn't have to concern itself with the specialized values.
It would be great if I could define the interface StatusChangeable with either a generic String! status, or even more ideally, with an enum that is a super-set of the specialized enum, such as:
enum AllStatuses {
active
banned
inactive
other
statuses
here
}
Otherwise the only option is to update all the types that implement StatusChangeable to define status as a String! which loses all the specificity and type-safety, or to avoid using an interface which can create a lot of duplicate code that could easily be prevented with an single interface.
(Type::Enum(sub_id), Type::Enum(super_id)) => {
let sub_enum = self.enum_(sub_id);
let super_enum = self.enum_(super_id);
// Ensure all values in the sub enum are present in the super enum
sub_enum.values.iter().all(|sub_value| {
super_enum.values.iter().any(|super_value| super_value.value == sub_value.value)
})
}
If this approach is acceptable I can submit a PR.
The text was updated successfully, but these errors were encountered:
Our goal here should be to match the GraphQL spec, so unless I am misreading the spec (always possible!) I think we'd pass on going back to the old behavior. Let me know if I've missed something.
In previous versions of relay it was possible to define interfaces that defined a
String!
field, and that field could then be specialized to an enum object the implemented this interface, such that the compiler would treat the specialized value as a sub-type of theString!
. For example, I could define this interface:And then use it as follows:
This way any code that used the
User
type directly could be typed properly to handle the specific values thatUser
supports, while code that cared only about theStatusChangeable
didn't have to concern itself with the specialized values.It would be great if I could define the
interface StatusChangeable
with either a genericString!
status, or even more ideally, with an enum that is a super-set of the specialized enum, such as:Otherwise the only option is to update all the types that implement
StatusChangeable
to definestatus
as aString!
which loses all the specificity and type-safety, or to avoid using an interface which can create a lot of duplicate code that could easily be prevented with an single interface.If is_named_type_subtype_of handled the Enum subset scenario, this could be done fairly easily:
If this approach is acceptable I can submit a PR.
The text was updated successfully, but these errors were encountered: