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

Support derives on enum declarations #139

Open
LucasPickering opened this issue Apr 16, 2021 · 0 comments
Open

Support derives on enum declarations #139

LucasPickering opened this issue Apr 16, 2021 · 0 comments

Comments

@LucasPickering
Copy link

Hey, got another feature request for you. There's a lot of times where I'd like to derive some trait for an enum generated by graphql_schema_from_file. Currently I'm struggling with an enum generated for a union type that I need Clone on. Of course the workaround is to just implement Clone manually, but it definitely would be nice to have a derive. It would also be especially nice to be able to apply other attributes beyond derive to the struct definitions, e.g. serde attributes to customize serialization/deserialization.

I'm not sure what the implementation for this would look like, but I assume on the schema side we would have to define these via a directive. According to the graphql schema spec, directive values can be any type, so I'm thinking maybe a new directive field with a list of strings? Something like this:

type A {}

type B {}

@juniper(attributes: ["derive(Clone, Debug, Serialize)", "serde(tag = "type")"])
union U = A | B

What do you think? If this seems viable and you give me some direction on how to implement it, I can work on the actual code for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant