'Generate graphene input types dynamically

I am sure whether this can be achieved or not. It would be very great if someone suggests any alternative to this or any other supporting packages to achieve this.

Below is my code.

class DynamicTypeInput(graphene.InputObjectType):
    object_type = graphene.String()
    object_value = graphene.String(required=False) # Can we make this required=True if object_type == "requesting_value"

class WidgetInput(graphene.InputObjectType):
    title = graphene.String()
    dynamic_object_type = graphene.Argument(DynamicTypeInput, required=True)

I tried using graphene-pydantic for generating graphene models but no use. Its throwing generalized error like TypeError: Input fields cannot be resolved. The input field type must be a GraphQL input type. Is there any way to achieve this with graphene itself?

As of now, I am validating the request once I received it from the user at the service side and am always open to suggestions.



Solution 1:[1]

Try using multi InputObjectType

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jenith S