from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

transport = AIOHTTPTransport(url="https://gql.ivazh.ru/graphql/")
service = 'pdim'


def get_classifier():
    client = Client(transport=transport, fetch_schema_from_transport=True, execute_timeout=None)
    query = gql(
        """
            query getClassifier($name: String!) {
              getClassifier(name: $name)
            }
        """
    )
    result = client.execute(query, variable_values={"name": service}, )
    return result['getClassifier']


def get_catalog():
    client = Client(transport=transport, fetch_schema_from_transport=True, execute_timeout=None)
    query = gql(
        """
            query getCatalog($name: String!) {
              getCatalog(name: $name)
            }
        """
    )
    result = client.execute(query, variable_values={"name": service})
    return result['getCatalog']


def get_object(oid: str):
    client = Client(transport=transport, fetch_schema_from_transport=True, execute_timeout=None)
    query = gql(
        """
            query getObjects($oid: String!, $name: String!) {
              getObject(name: $name, oid: $oid)
            }
        """
    )
    params = {'oid': oid, 'name': service}
    result = client.execute(query, variable_values=params)
    return result['getObject']
