Files
Ashley Harrison 30bf2bcde1 API client generation: create a central getAPIBaseURL function (#99961)
* create a getAPIBaseURL function

* use base url in iam api
2025-02-03 13:05:47 +00:00

60 lines
1.7 KiB
TypeScript

/**
* This is a temporary place for Query Library API and data types.
* To be exposed via grafana-runtime/data in the future.
*
* Query Library is an experimental feature, the API and components are subject to change
*
* @alpha
*/
import { config } from '@grafana/runtime';
import { QUERY_LIBRARY_GET_LIMIT } from './api/api';
import { generatedQueryLibraryApi } from './api/endpoints.gen';
import { mockData } from './api/mocks';
export const {
useCreateQueryTemplateMutation,
useDeleteQueryTemplateMutation,
useListQueryTemplateQuery,
useUpdateQueryTemplateMutation,
} = generatedQueryLibraryApi.enhanceEndpoints({
endpoints: {
// Need to mutate the generated query to force query limit
listQueryTemplate: (endpointDefinition) => {
const originalQuery = endpointDefinition.query;
if (originalQuery) {
endpointDefinition.query = (requestOptions) =>
originalQuery({
...requestOptions,
limit: QUERY_LIBRARY_GET_LIMIT,
});
}
},
// Need to mutate the generated query to set the Content-Type header correctly
updateQueryTemplate: (endpointDefinition) => {
const originalQuery = endpointDefinition.query;
if (originalQuery) {
endpointDefinition.query = (requestOptions) => ({
...originalQuery(requestOptions),
headers: {
'Content-Type': 'application/merge-patch+json',
},
});
}
},
},
});
export function isQueryLibraryEnabled() {
return config.featureToggles.queryLibrary;
}
export const QueryLibraryMocks = {
data: mockData.all,
};
export const IdentityServiceMocks = {
data: mockData.identityDisplay,
};