""" Healthie GraphQL client service. Provides authenticated GraphQL queries/mutations against the Healthie API. Returns parsed JSON responses. Only the generic query() entry point is used in-repo (intake webhook consumers); form-management/upload helpers that lived here had no call sites and were removed — intake_app has its own client for the FastAPI-side flows. """ import os from typing import Any import requests class HealthieClient: """Healthie GraphQL API client.""" def __init__(self, api_key: str | None = None, base_url: str | None = None): self.api_key = api_key or os.environ.get("HEALTHIE_API_KEY", "") self.base_url = base_url or os.environ.get( "HEALTHIE_API_BASE_URL", "https://api.gethealthie.com/graphql" ) self.session = requests.Session() self.session.headers.update( { "Content-Type": "application/json", "Authorization": f"Basic {self.api_key}", "AuthorizationSource": "API", } ) def query(self, query: str, variables: dict[str, Any] | None = None) -> dict: """Execute a GraphQL query/mutation.""" payload: dict[str, Any] = {"query": query} if variables: payload["variables"] = variables resp = self.session.post(self.base_url, json=payload, timeout=30) resp.raise_for_status() return resp.json()