mirror of https://github.com/grafana/grafana.git
27 lines
951 B
TypeScript
27 lines
951 B
TypeScript
import { createApi } from '@reduxjs/toolkit/query/react';
|
|
|
|
import { AddQueryTemplateCommand, QueryTemplate } from '../types';
|
|
|
|
import { convertAddQueryTemplateCommandToDataQuerySpec, convertDataQueryResponseToQueryTemplates } from './mappers';
|
|
import { baseQuery } from './query';
|
|
|
|
export const queryLibraryApi = createApi({
|
|
baseQuery,
|
|
tagTypes: ['QueryTemplatesList'],
|
|
endpoints: (builder) => ({
|
|
allQueryTemplates: builder.query<QueryTemplate[], void>({
|
|
query: () => ({}),
|
|
transformResponse: convertDataQueryResponseToQueryTemplates,
|
|
providesTags: ['QueryTemplatesList'],
|
|
}),
|
|
addQueryTemplate: builder.mutation<QueryTemplate, AddQueryTemplateCommand>({
|
|
query: (addQueryTemplateCommand) => ({
|
|
method: 'POST',
|
|
data: convertAddQueryTemplateCommandToDataQuerySpec(addQueryTemplateCommand),
|
|
}),
|
|
invalidatesTags: ['QueryTemplatesList'],
|
|
}),
|
|
}),
|
|
reducerPath: 'queryLibrary',
|
|
});
|