// Minimal GraphQL client — swap for graphql-request if preferred. const API_URL = import.meta.env.VITE_API_URL ?? '/graphql' export async function gql( query: string, variables?: Record, ): Promise { const token = localStorage.getItem('token') const res = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}), }, body: JSON.stringify({ query, variables }), }) const json = await res.json() if (json.errors?.length) { if (json.errors[0].message === 'UNAUTHORIZED') { localStorage.removeItem('token') localStorage.removeItem('username') window.location.href = '/' } throw new Error(json.errors[0].message) } return json.data as T } export async function createFolder(path: string): Promise<{ createFolder: boolean }> { const query = `mutation CreateFolder($path: String!) { createFolder(path: $path) }` return gql(query, { path }) } export async function moveDocument(oldSlug: string, newSlug: string): Promise<{ moveDocument: boolean }> { const query = `mutation MoveDocument($oldSlug: String!, $newSlug: String!) { moveDocument(oldSlug: $oldSlug, newSlug: $newSlug) }` return gql(query, { oldSlug, newSlug }) } export async function getFolders(): Promise<{ folders: string[] }> { const query = `query GetFolders { folders }` return gql(query) }