mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
refactor: migrate from @hey-api/openapi-ts to openapi-react-query
- Replace @hey-api/openapi-ts with openapi-typescript and openapi-react-query - Generate TypeScript types from OpenAPI spec - Set up React Query infrastructure with QueryClientProvider - Migrate all API hooks to use React Query patterns - Maintain backward compatibility for existing components - Remove old API infrastructure and dependencies
This commit is contained in:
40
www/app/lib/apiClient.tsx
Normal file
40
www/app/lib/apiClient.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import createClient from "openapi-fetch";
|
||||
import type { paths } from "../reflector-api";
|
||||
import {
|
||||
queryOptions,
|
||||
useMutation,
|
||||
useQuery,
|
||||
useSuspenseQuery,
|
||||
} from "@tanstack/react-query";
|
||||
import createFetchClient from "openapi-react-query";
|
||||
|
||||
// Create the base openapi-fetch client
|
||||
export const client = createClient<paths>({
|
||||
// Base URL will be set dynamically via middleware
|
||||
baseUrl: "",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
// Create the React Query client wrapper
|
||||
export const $api = createFetchClient<paths>(client);
|
||||
|
||||
// Configure authentication
|
||||
export const configureApiAuth = (token: string | null | undefined) => {
|
||||
if (token) {
|
||||
client.use({
|
||||
onRequest({ request }) {
|
||||
request.headers.set("Authorization", `Bearer ${token}`);
|
||||
return request;
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Export typed hooks for convenience
|
||||
export const useApiQuery = $api.useQuery;
|
||||
export const useApiMutation = $api.useMutation;
|
||||
export const useApiSuspenseQuery = $api.useSuspenseQuery;
|
||||
Reference in New Issue
Block a user