mirror of
https://github.com/grafana/grafana.git
synced 2025-09-29 02:04:21 +08:00

* E2C: Start connecting on-prem to real apis * actually run the migration * show resources * basic dashboards resources * show dashboard title * remove console logs * cleanup 1 * i18n * disconnect * i18n * restore type * use fixed format * fix
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { BaseQueryFn, createApi } from '@reduxjs/toolkit/query/react';
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
|
import { BackendSrvRequest, getBackendSrv } from '@grafana/runtime';
|
|
|
|
interface RequestOptions extends BackendSrvRequest {
|
|
manageError?: (err: unknown) => { error: unknown };
|
|
showErrorAlert?: boolean;
|
|
|
|
// rtk codegen sets this
|
|
body?: BackendSrvRequest['data'];
|
|
}
|
|
|
|
function createBackendSrvBaseQuery({ baseURL }: { baseURL: string }): BaseQueryFn<RequestOptions> {
|
|
async function backendSrvBaseQuery(requestOptions: RequestOptions) {
|
|
try {
|
|
const { data: responseData, ...meta } = await lastValueFrom(
|
|
getBackendSrv().fetch({
|
|
...requestOptions,
|
|
url: baseURL + requestOptions.url,
|
|
showErrorAlert: requestOptions.showErrorAlert,
|
|
data: requestOptions.body,
|
|
})
|
|
);
|
|
return { data: responseData, meta };
|
|
} catch (error) {
|
|
return requestOptions.manageError ? requestOptions.manageError(error) : { error };
|
|
}
|
|
}
|
|
|
|
return backendSrvBaseQuery;
|
|
}
|
|
|
|
export const baseAPI = createApi({
|
|
reducerPath: 'migrateToCloudGeneratedAPI',
|
|
baseQuery: createBackendSrvBaseQuery({ baseURL: '/api' }),
|
|
endpoints: () => ({}),
|
|
});
|