"""GraphQL router connector.""" from typing import Any from gql import Client from gql import gql as gql_query from gql.transport.requests import RequestsHTTPTransport import config __all__ = ['execute_query'] DEFAULT_HEADERS: dict[str, str] = { 'ApolloGraphql-Client-Name': config.APPLICATION_NAME, 'ApolloGraphql-Client-Version': '1', 'Orchard-Identity-Id': '8955b4aa-2ad0-4b0b-a2ea-6f070554d6d0', 'Orchard-Profile-Type': 'SettingsProfile', 'Orchard-Profile-Id': '69573', } def execute_query( query_string: str, params: dict[str, Any] | None = None, headers: dict[str, str] | None = None ) -> dict[str, Any]: """Format and send request to graphql-router. Args: query_string (str): graphql formatted request body params (dict): parameters to inject into body headers (dict): HTTP headers for request Returns: dict: response directly from graphql-router """ headers = headers or {} params = params or {} transport = RequestsHTTPTransport( url=config.GRAPHQL_URL, use_json=True, headers=dict(DEFAULT_HEADERS, **headers), verify=True, retries=3 ) client = Client( transport=transport, fetch_schema_from_transport=False, ) query_string = ' '.join(query_string.split()).replace('\n', '') query = gql_query(query_string) return client.execute(query, variable_values=params)