import graphene from graphene import relay from api.utils import get_object from objectives.models import ObjectiveProgressStatus, Objective from objectives.schema import ObjectiveNode class UpdateObjectiveProgress(relay.ClientIDMutation): class Input: id = graphene.ID(required=True, description="The ID of the objective") done = graphene.Boolean(required=True) errors = graphene.List(graphene.String) objective = graphene.Field(ObjectiveNode) @classmethod def mutate_and_get_payload(cls, root, info, **kwargs): objective_id = kwargs.get('id') done = kwargs.get('done') objective = get_object(Objective, objective_id) # info.context.user = django user objective_progress, created = ObjectiveProgressStatus.objects.get_or_create( objective=objective, user=info.context.user ) objective_progress.done = done objective_progress.save() return cls(objective=objective) class ObjectiveMutations: update_objective_progress = UpdateObjectiveProgress.Field()