Unable to add Union to enum when enum option/variant takes a string
Expected Behavior
Union should work on String types like it does for defined structs
Steps to Reproduce the Problem
#[derive(SimpleObject, Clone, Debug, PartialEq)]
pub struct DateResponse {
pub mask: u32,
pub date: String,
}
#[derive(SimpleObject, Clone, Debug, PartialEq)]
pub struct Contact {
pub id: ID,
pub first_name: String,
}
#[derive(PartialEq, Union)]
pub enum ResponseValue {
Value(String),
Date(DateResponse),
Contact(Contact),
}
With the code snippet above, add Union to to ResponseValue causes compilation error and as far as I can tell it's as a result of Value(String
async_graphql::ObjectType` is not implemented for `std::string::String`
transformer_1 | | required by `agraphql::schemas::_::{closure#0}::AmbiguousIfMoreThanOne::some_item`
transformer_1 | |
transformer_1 | = note: required because of the requirements on the impl of `graphql::schemas::_::{closure#0}::AmbiguousIfMoreThanOne<graphql::schemas::_::{closure#0}::Token>` for `std::string::String`
transformer_1 | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
transformer_1 |
transformer_1 | error[E0599]: the method `collect_all_fields` exists for reference `&std::string::String`, but its trait bounds were not satisfied
transformer_1 | --> src/graphql/schemas.rs:80:59
transformer_1 | |
transformer_1 | 80 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Union)]
transformer_1 | | ^^^^^ method cannot be called on `&std::string::String` due to unsatisfied trait bounds
transformer_1 | |
transformer_1 | = note: the following trait bounds were not satisfied:
transformer_1 | `std::string::String: async_graphql::ContainerType`
transformer_1 | which is required by `&std::string::String: async_graphql::ContainerType`
transformer_1 | = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
transformer_1 |
transformer_1 | error: aborting due to 2 previous errors
transformer_1 |
transformer_1 | Some errors have detailed explanations: E0277, E0599.
transformer_1 | For more information about an error, try `rustc --explain E0277`.
Specifications
- Version: async_graphql v2.0 (Rust - 2018)
- Platform: Docker
Type Validation
Union types have the potential to be invalid if incorrectly defined.
A Union type must include one or more unique member types. The member types of a Union type must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.
https://spec.graphql.org/June2018/#sec-Unions
Gotcha @sunli829 Thanks for the clarification