Type query endpoints
This commit is contained in:
parent
abddbdeea7
commit
ac05ccd6a8
|
@ -62,10 +62,7 @@ export function createQueriesStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const importQueries = async ({ data, datasourceId }) => {
|
const importQueries = async ({ data, datasourceId }) => {
|
||||||
return await API.importQueries({
|
return await API.importQueries(datasourceId, data)
|
||||||
datasourceId,
|
|
||||||
data,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const select = id => {
|
const select = id => {
|
||||||
|
|
|
@ -251,17 +251,14 @@ const navigationHandler = action => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryExecutionHandler = async action => {
|
const queryExecutionHandler = async action => {
|
||||||
const { datasourceId, queryId, queryParams, notificationOverride } =
|
const { queryId, queryParams, notificationOverride } = action.parameters
|
||||||
action.parameters
|
|
||||||
try {
|
try {
|
||||||
const query = await API.fetchQueryDefinition(queryId)
|
const query = await API.fetchQueryDefinition(queryId)
|
||||||
if (query?.datasourceId == null) {
|
if (query?.datasourceId == null) {
|
||||||
notificationStore.actions.error("That query couldn't be found")
|
notificationStore.actions.error("That query couldn't be found")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const result = await API.executeQuery({
|
const result = await API.executeQuery(queryId, {
|
||||||
datasourceId,
|
|
||||||
queryId,
|
|
||||||
parameters: queryParams,
|
parameters: queryParams,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,39 @@
|
||||||
export const buildQueryEndpoints = API => ({
|
import {
|
||||||
|
ExecuteQueryRequest,
|
||||||
|
ExecuteQueryResponse,
|
||||||
|
PreviewQueryRequest,
|
||||||
|
PreviewQueryResponse,
|
||||||
|
Query,
|
||||||
|
} from "@budibase/types"
|
||||||
|
import { BaseAPIClient } from "./types"
|
||||||
|
|
||||||
|
export interface QueryEndpoints {
|
||||||
|
executeQuery: (
|
||||||
|
queryId: string,
|
||||||
|
opts?: ExecuteQueryRequest
|
||||||
|
) => Promise<ExecuteQueryResponse | Record<string, any>[]>
|
||||||
|
fetchQueryDefinition: (queryId: string) => Promise<Query>
|
||||||
|
getQueries: () => Promise<Query[]>
|
||||||
|
saveQuery: (query: Query) => Promise<Query>
|
||||||
|
deleteQuery: (id: string, rev: string) => Promise<void>
|
||||||
|
previewQuery: (query: PreviewQueryRequest) => Promise<PreviewQueryResponse>
|
||||||
|
|
||||||
|
// Missing request or response types
|
||||||
|
importQueries: (datasourceId: string, data: any) => Promise<any>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({
|
||||||
/**
|
/**
|
||||||
* Executes a query against an external data connector.
|
* Executes a query against an external data connector.
|
||||||
* @param queryId the ID of the query to execute
|
* @param queryId the ID of the query to execute
|
||||||
* @param pagination pagination info for the query
|
* @param pagination pagination info for the query
|
||||||
* @param parameters parameters for the query
|
* @param parameters parameters for the query
|
||||||
*/
|
*/
|
||||||
executeQuery: async ({ queryId, pagination, parameters }) => {
|
executeQuery: async (queryId, { pagination, parameters } = {}) => {
|
||||||
return await API.post({
|
return await API.post<
|
||||||
|
ExecuteQueryRequest,
|
||||||
|
ExecuteQueryResponse | Record<string, any>[]
|
||||||
|
>({
|
||||||
url: `/api/v2/queries/${queryId}`,
|
url: `/api/v2/queries/${queryId}`,
|
||||||
body: {
|
body: {
|
||||||
parameters,
|
parameters,
|
||||||
|
@ -48,12 +75,12 @@ export const buildQueryEndpoints = API => ({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a query
|
* Deletes a query
|
||||||
* @param queryId the ID of the query to delete
|
* @param id the ID of the query to delete
|
||||||
* @param queryRev the rev of the query to delete
|
* @param rev the rev of the query to delete
|
||||||
*/
|
*/
|
||||||
deleteQuery: async ({ queryId, queryRev }) => {
|
deleteQuery: async (id, rev) => {
|
||||||
return await API.delete({
|
return await API.delete({
|
||||||
url: `/api/queries/${queryId}/${queryRev}`,
|
url: `/api/queries/${id}/${rev}`,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -62,7 +89,7 @@ export const buildQueryEndpoints = API => ({
|
||||||
* @param datasourceId the datasource ID to import queries into
|
* @param datasourceId the datasource ID to import queries into
|
||||||
* @param data the data string of the content to import
|
* @param data the data string of the content to import
|
||||||
*/
|
*/
|
||||||
importQueries: async ({ datasourceId, data }) => {
|
importQueries: async (datasourceId, data) => {
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: "/api/queries/import",
|
url: "/api/queries/import",
|
||||||
body: {
|
body: {
|
|
@ -19,6 +19,7 @@ import { MigrationEndpoints } from "./migrations"
|
||||||
import { OtherEndpoints } from "./other"
|
import { OtherEndpoints } from "./other"
|
||||||
import { PermissionEndpoints } from "./permissions"
|
import { PermissionEndpoints } from "./permissions"
|
||||||
import { PluginEndpoins } from "./plugins"
|
import { PluginEndpoins } from "./plugins"
|
||||||
|
import { QueryEndpoints } from "./queries"
|
||||||
|
|
||||||
export enum HTTPMethod {
|
export enum HTTPMethod {
|
||||||
POST = "POST",
|
POST = "POST",
|
||||||
|
@ -109,4 +110,5 @@ export type APIClient = BaseAPIClient &
|
||||||
MigrationEndpoints &
|
MigrationEndpoints &
|
||||||
OtherEndpoints &
|
OtherEndpoints &
|
||||||
PermissionEndpoints &
|
PermissionEndpoints &
|
||||||
PluginEndpoins & { [key: string]: any }
|
PluginEndpoins &
|
||||||
|
QueryEndpoints & { [key: string]: any }
|
||||||
|
|
|
@ -48,7 +48,7 @@ export default class QueryFetch extends DataFetch {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add pagination to query if supported
|
// Add pagination to query if supported
|
||||||
let queryPayload = { queryId: datasource?._id, parameters }
|
let queryPayload = { parameters }
|
||||||
if (paginate && supportsPagination) {
|
if (paginate && supportsPagination) {
|
||||||
const requestCursor = type === "page" ? parseInt(cursor || 1) : cursor
|
const requestCursor = type === "page" ? parseInt(cursor || 1) : cursor
|
||||||
queryPayload.pagination = { page: requestCursor, limit }
|
queryPayload.pagination = { page: requestCursor, limit }
|
||||||
|
@ -56,7 +56,7 @@ export default class QueryFetch extends DataFetch {
|
||||||
|
|
||||||
// Execute query
|
// Execute query
|
||||||
try {
|
try {
|
||||||
const res = await this.API.executeQuery(queryPayload)
|
const res = await this.API.executeQuery(datasource?._id, queryPayload)
|
||||||
const { data, pagination, ...rest } = res
|
const { data, pagination, ...rest } = res
|
||||||
|
|
||||||
// Derive pagination info from response
|
// Derive pagination info from response
|
||||||
|
|
Loading…
Reference in New Issue