I'm struggling to get my Delete operation working. My Create, Read and Update are working fine, but a Delete has nothing to return.
class DeleteEmployeeInput(graphene.InputObjectType):
"""Arguments to delete an employee."""
id = graphene.ID(required=True, description="Global Id of the employee.")
class DeleteEmployee(graphene.Mutation):
"""Delete an employee."""
employee = graphene.Field(
lambda: Employee, description="Employee deleted by this mutation.")
class Arguments:
input = DeleteEmployeeInput(required=True)
def mutate(self, info, input):
data = utils.input_to_dictionary(input)
#data['edited'] = datetime.utcnow()
employee = db_session.query(
EmployeeModel).filter_by(id=data['id'])
employee.delete(data['id'])
db_session.commit()
#employee = db_session.query(
#EmployeeModel).filter_by(id=data['id']).first()
#return DeleteEmployee(employee=employee)
What is the best way to delete an entry? I assume I have to return an OK or an Error.
When I run my mutation:
mutation {
deleteEmployee (input: {
id: "RW1wbG95ZWU6MQ=="
})
}
I get the error Field \"deleteEmployee\" of type \"DeleteEmployee\" must have a sub selection."
Note the commented out lines
return DeleteEmployee(ok=True)
? It returns an new instance of the same class DeleteEmployee? The ok=True is an kwarg that is passed to the constructor of the graphene.Mutation class? – Spellbinder