-
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
InputObjectType with different types of required #961
Comments
Unfortunately, there isn't a clean way to do this in graphene (or any other library that defines a static schema through class attributes like An object like Input is used by Graphene to build a static schema for GraphQL. Having a static schema is super beneficial for tooling and API evolution purposes. The fact that a field is required (or optional) is part of that static schema. Meaning, if something is required on an object, it is required for all instances of that object. The only way to have a field required or not required in different contexts is to create a different object for each context. Your Input example is simple enough that you might be annoyed to have some code duplication but just live with it. If you want to get creative, you might be able to apply metaprogramming to define a factory method to create these similar Input classes but with different name and value for required parameter.
Generally, I would prefer to use a more repetitive, explicit implemention though. Good luck! |
ya see Lee Byron's response to basically the same request in JS. graphql/graphql-js#207 (comment) |
Closing this issue because (until this is defined in the GraphQL spec) it's not going to get implemented in Graphene (sorry 😞 ) |
Hi,
I faced this problem where I had an Update and Create mutations and that's how they work:
Create: Arguments is a
graphene.InputObjectType
where all of them are necessary and returns somethingUpdate: Arguments is a
graphene.InputObjectType
where at least one of them is necessary and returns somethingbecause I did not want to copy paste code like this
I wanted a more cleaner version like this:
I don't know if such thing exists but If I want to this I need a function to check if any of inputs is entered or not, is there a builtin way to this?
The text was updated successfully, but these errors were encountered: