Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing __typename for types that share a vertex variant is fiddly #348

Open
u9g opened this issue Jul 7, 2023 · 1 comment
Open
Labels
A-adapter Area: plugging data sources into the interpreter C-feature-request Category: request for new future functionality E-medium Call for participation: experience needed to fix: medium / intermediate L-rust Language: affects use cases in the Rust programming language

Comments

@u9g
Copy link
Contributor

u9g commented Jul 7, 2023

Any way we can improve the experience on that with the trustfall derive macro?

@obi1kenobi obi1kenobi changed the title Implementing __typename for types that share a vertex is fiddly Implementing __typename for types that share a vertex variant is fiddly Jul 7, 2023
@obi1kenobi
Copy link
Owner

Perhaps something like:

#[derive(TrustfallEnumVertex)]
pub enum Vertex {
    Span(...),
    Function(...),
    #[covers(JsxAttribute, HrefAttribute, RelAttribute)]
    JsxAttribute(Attribute),
}

where the Attribute value contained in that variant implements a new trait that manually implements typename?

Then the TrustfallEnumVertex-generated typename implementation could be something along the lines of:

match vertex {
    Vertex::Span(..) => "Span",
    Vertex::Function(..) => "Function",
    Vertex::JsxAttribute(attr) => <attr as NewTypenameTrait>.manual_typename(),
}

All names need some bikeshedding, of course. Aiming to show general idea, not commit to names.

@obi1kenobi obi1kenobi added A-adapter Area: plugging data sources into the interpreter C-feature-request Category: request for new future functionality E-medium Call for participation: experience needed to fix: medium / intermediate L-rust Language: affects use cases in the Rust programming language labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-adapter Area: plugging data sources into the interpreter C-feature-request Category: request for new future functionality E-medium Call for participation: experience needed to fix: medium / intermediate L-rust Language: affects use cases in the Rust programming language
Projects
None yet
Development

No branches or pull requests

2 participants