/** * The app's entire GraphQL client: a thin axios POST to the tracker's * /jobs/api/graphql. Every Pinia store goes through this; there is no cache * or normalisation layer. * * Auth rides along in the main site's HTTP-only cookies, which the browser * sends because the request is same-origin (nginx in production, the Vite * proxy in dev). A lapsed session sends the browser to the site's login. */ import axios from "axios"; import { ADMIN_REQUIRED, goToLogin } from "@/session"; export async function gql(query, variables = {}) { const res = await axios.post(`${import.meta.env.BASE_URL}api/graphql`, { query, variables }); const errors = res.data.errors; if (errors?.some((e) => e.message === ADMIN_REQUIRED)) { goToLogin(); } if (errors && !res.data.data) throw new Error(errors[0].message); return res.data.data; }