from flask import Blueprint, request,jsonify
from configs.connections import connect_graph
from configs.result import success, failed
# 创建蓝图，每个接口前加上一个resume，便可请求到本页的接口
resume = Blueprint('resume', __name__)


@resume.route('/search/graph', methods=['POST'])
def search_graph():
    try:
        # 传入请求参数
        receiver = request.get_json()
        data = receiver['data']
        check_query = """
                SHOW INDEXES YIELD name WHERE name = 'dataops' RETURN count(name) AS count
                """
        result = connect_graph.run(check_query).data()
        res = success('', "success")
        return jsonify(res)
    except Exception as e:
        res = failed({}, {"error": f"{e}"})
        return jsonify(res)