-
Notifications
You must be signed in to change notification settings - Fork 829
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
Union InputType? #721
Comments
And I think it is a very normal usage.Is there any way to solve it? |
It's currently not possible but there is an ongoing debate in the graphql-js repo about it: graphql/graphql-js#207 I think it's probably more complexity than it's worth and I agree with Lee here: graphql/graphql-js#207 (comment) |
Can anyone advise here?
or
I'd like to have them both as a union type (discriminated on the I have similar use cases at a lot of places throughout the feature I am developing, and I also have looked into graphene-pydantic, hoping to get something done with the Pydantic discriminated Unions but it turns out that graphene-pydantic does not support them yet. (See Here) Has anyone any clue or, idea of another approach to get this done, or achieve a similar result? |
@Dave-Lopper while I can't comment on your exact use case, but judging from your example, this sounds like a great case to have two separate mutations:
However, for complex inputs I'd definitely recommend separate mutations, especially when they're already encapsulated into two separate input types. For a current alternative, you could create a wrapper input providing the types you want to union as optional fields/resolver args: input AddElementInput {
imageInput: ImageElementInput
textInput: TextElementInput
} However, I do not recommend this approach as it dilutes the expressivity of the schema. From the schema it is no longer directly visible if only one of the inputs is allowed, no inputs are allowed, or both inputs are allowed at the same time. This is not a good pattern to follow. In the future, please open up a new issue referencing the issues you already looked up. This is much easier than tracking comments under closed issues. 🙂 |
I have three type.
So I hope that:
the data maybe like:
By the way, why an ObjectType or InputType must have fields?
The text was updated successfully, but these errors were encountered: