Dicussion: Support mutations in graphene-sqlalchemy
See original GitHub issueThis is going to be a discussion thread to debate whether it is good to implement mutations in graphene-sqlalchemy. There is definitely a scope for this feature and I think it’s useful, so the real question is more towards how to implement it.
We can probably start with creating objects and then later expand to updating the various attributes.
There are discussions around this topic in https://github.com/graphql-python/graphene-sqlalchemy/pull/213 as well as https://github.com/graphql-python/graphene-sqlalchemy/issues/29. I’ll copy the relevant items here so that we won’t have to repeat them again.
Points to note:
- Have a class named
SQLAlchemyInputObjectType
and have model and exclude_fields as meta properties.
class CreateUser(SQLAlchemyInputObjectType):
class Meta:
exclude_fields = ('id', )
model = UserModel
-
No need to worry about hybrid or composite columns as they are basically created from other columns. So, we just need a mechanism to just accept the fields. So, a function named
construct_fields_for_input
. -
How to handle relationships ? Since we are creating row entries for the table, we can probably accept
id
of the related table entry and convert it to the database id.
@jnak thoughts ?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:7 (1 by maintainers)
It’s beyond obvious that this is useful, it’s basically required for anyone to seriously use graphene-sqlalchemy in a complex project. I’ve been using this in my fork for about 2 years now. It’s not pretty because I mostly copy pasted stuff from the library code for creating these objects with a few changes, but it gets the job done.
You can use it like this, very easy: (in the Meta class set create=True for creation, delete=True for deletion. Setting neither will update)
Any news on this?