-
Notifications
You must be signed in to change notification settings - Fork 425
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
Feature Request: Derivable custom input objects #1055
Comments
@ilslv what do you think about this? We have similar problems in our codebase. |
@tyranron sounds like a great idea, until |
@ilslv Allowing enums would be enough! I'm curious how that would look - would the |
@msterny actually I think we can achieve this without any intermediary structs, just using internal machinery. |
@ilslv yep, you're right. Even if input unions will be introduced, it still won't interfere with deriving input objects on enums. So let's add this ability for 0.16 release. |
Rescheduling this to 0.17 |
Is your feature request related to a problem? Please describe.
I want to be able to define a custom GraphQL input object for a struct/enum that cannot support
derive(GraphQLInputObject)
. A clear way of doing this would be to automatically define a conversion between a Juniper-supported GraphQLInputObject and a Rust enum (which can be used to represent a discriminant union).An Example
Given an enum
FooBar
that we want to define as a GraphQL input type:Since GraphQL doesn’t support input unions as of this writing, the GraphQL schema would need to look like this:
This means that we’d need to create a separate FooBarInputObject, and validate/map into FooBar after the input has been parsed.
This works well enough for a very simple case, but we run into issues with reusable and composite input objects. Consider the case where FooBar is part of a struct that we want to define as an input object:
Since FooBar cannot be an input object, neither can FooBarBaz. This would require us to define another struct just to be able to map FooBar. And this issue gets worse every-time we create another higher-level struct - if we want to nest FooBarBaz in another level, we have to create a third new-type!
Describe the solution you'd like
It would be useful to separate a GraphQLInputObject’s schema representation from its form in Rust. One way to do this is to support custom conversions for input types.
We could create a
juniper::ConvertInput
trait that can enable custom type conversions.The text was updated successfully, but these errors were encountered: