-
Notifications
You must be signed in to change notification settings - Fork 228
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
Generate Input Arguments from SQLAlchemy Class? #112
Comments
I was able to factorize my code a little bit by creating a new class where I define attributes description only once. Then I supply this new class as a parent class of the following classes:
Here is the code: # Create a generic class to mutualize description of people attributes for both queries and mutations
class PeopleAttribute:
name = graphene.String(required=True, description="Name of the person.")
height = graphene.String(default_value="unknown", description="Height of the person.")
mass = graphene.String(default_value="unknown", description="Mass of the person.")
hair_color = graphene.String(default_value="unknown", description="Hair color of the person.")
skin_color = graphene.String(default_value="unknown", description="Skin color of the person.")
eye_color = graphene.String(default_value="unknown", description="Eye color of the person.")
birth_year = graphene.String(default_value="unknown", description="Birth year of the person.")
gender = graphene.String(default_value="unknown", description="Gender of the person.")
planet_id = graphene.ID(default_value="unknown", description="Global Id of the planet from which the person comes from.")
url = graphene.String(default_value="unknown", description="URL of the person in the Star Wars API.")
class People(SQLAlchemyObjectType, PeopleAttribute):
"""People node."""
class Meta:
model = ModelPeople
interfaces = (graphene.relay.Node,)
class CreatePersonInput(graphene.InputObjectType, PeopleAttribute):
"""Arguments to create a person."""
pass
class UpdatePersonInput(graphene.InputObjectType, PeopleAttribute):
"""Arguments to update a person."""
id = graphene.ID(required=True, description="Global Id of the person.") |
Does anyone has a better way of doing this? |
See this also: #29 |
Hello,
Do you know if it's possible to generate input arguments dynamically from the SQLAlchemy class that will be transformed by the mutation?
Example:
My input arguments for a
CreatePerson
mutation look like this:In the meantime, the input arguments for my
UpdatePerson
mutation look like this:Finally, my SQLAlchemy class look like this:
This is all pretty redundant and it would be ideal if we could just reuse the SQLAlchemy class attributes in the
InputObjectType
The text was updated successfully, but these errors were encountered: