Django Graphene mutation deletes objects instead of update

There is a such mutation and a pretty simple update function, I expect it will only update one parameter of the object, then saves it. Actually, at the first request, it returns the expected response, but objects delete from DB.

class PortfolioMutation(graphene.Mutation):
    class Arguments:
        portfolio_id = graphene.ID()
        visible = graphene.Boolean()

    portfolio = graphene.Field(PortfolioType)

    @classmethod
    def mutate(cls, root, info, portfolio_id, visible):
        portfolio = Portfolio.objects.get(pk=portfolio_id)
        portfolio.visible = visible
        portfolio.save()
        return PortfolioMutation(portfolio=portfolio)


class UpdatePortfolio(graphene.ObjectType):
    """
    Portfolios mutation
    """

    update_portfolio = PortfolioMutation.Field()


schema = graphene.Schema(query=QueryPortfolios, mutation=UpdatePortfolio)

Exact request

mutation UpdatePortfolio{
  updatePortfolio(portfolioId: 1509, visible: false) {
    portfolio {
      name
      visible
    }
  }  
}

Respnse

{
  "data": {
    "updatePortfolio": {
      "portfolio": {
        "name": "High Yield Corporate Bonds",
        "visible": false
      }
    }
  }
}

Where I messed up?

Back to Top