Ejemplo n.º 1
0
    def resolve_get_project(self, info, input=None):
        try:
            if input:
                data = input_to_dict(input=input)
                query = Project.query
                for key, value in data.items():
                    query = query.filter(text(f"{key}='{value}'"))

                return query.all()

        except SQLAlchemyError as e:
            print(str(e))
            print(info.path)
Ejemplo n.º 2
0
    def resolve_get_users(self, info, input=None):
        try:
            if not input:
                return User.query.all()

            data = input_to_dict(input=input)

            first_name = data.get("first_name")
            return User.query.filter_by(first_name=first_name).all()

        except SQLAlchemyError as e:
            print(str(e))
            print(info.path)
Ejemplo n.º 3
0
    def mutate(self, info, input):

        data = input_to_dict(input=input)
        project = Project(**data)

        try:
            save_changes(project)

        except SQLAlchemyError as e:
            print(str(e))
            print(info.path)
            db.session.rollback()

        return CreateProject(project=project)
Ejemplo n.º 4
0
    def mutate(self, info, input):

        data = input_to_dict(input=input)
        user = User(**data)

        try:
            save_changes(user)

        except SQLAlchemyError as e:
            print(str(e))
            print(info.path)
            db.session.rollback()

        return CreateUser(user=user)
Ejemplo n.º 5
0
    def mutate(self, info, input):
        if input:
            data = input_to_dict(input=input)
            user_id = data.pop("user_id")

            if not user_id:
                raise Exception("No user_id provided for update.")
            try:
                user = User.query.filter_by(user_id=user_id).first()
                db.session.delete(user)
                db.session.commit()

            except SQLAlchemyError as e:
                print(str(e))
                print(info.path)
                db.session.rollback()

        return DeleteUser(user=user)
Ejemplo n.º 6
0
    def mutate(self, info, input):
        if input:
            data = input_to_dict(input=input)
            user_id = data.pop("user_id")
            if not user_id:
                raise Exception("No user_id provided for update.")
            try:
                user = User.query.filter_by(user_id=user_id).first()
                [setattr(user, key, value) for key, value in data.items()]

                save_changes(user)

            except SQLAlchemyError as e:
                print(str(e))
                print(info.path)
                db.session.rollback()

        return UpdateUser(user=user)
Ejemplo n.º 7
0
    def mutate(self, info, input):
        if input:
            data = input_to_dict(input=input)
            proj_id = data.pop("proj_id")

            if not proj_id:
                raise Exception("No proj_id provided for update.")
            try:
                project = Project.query.filter_by(proj_id=proj_id).first()
                db.session.delete(project)
                db.session.commit()

            except SQLAlchemyError as e:
                print(str(e))
                print(info.path)
                db.session.rollback()

        return DeleteProject(project=project)
Ejemplo n.º 8
0
    def mutate(self, info, input):

        if input:
            data = input_to_dict(input=input)
            proj_id = data.pop("proj_id")
            if not proj_id:
                raise Exception("No proj_id provided for update.")
            try:
                project = Project.query.filter_by(proj_id=proj_id).first()
                [setattr(project, key, value) for key, value in data.items()]

                save_changes(project)

            except SQLAlchemyError as e:
                print(str(e))
                print(info.path)
                db.session.rollback()

        return UpdateProject(project=project)