Making sure meta.table is always available.
This commit is contained in:
parent
58d4b2b56e
commit
e90e2b214e
|
@ -4,6 +4,7 @@ import {
|
||||||
Query,
|
Query,
|
||||||
QueryPreview,
|
QueryPreview,
|
||||||
SourceName,
|
SourceName,
|
||||||
|
TableSourceType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import * as setup from "../utilities"
|
import * as setup from "../utilities"
|
||||||
import {
|
import {
|
||||||
|
@ -740,12 +741,25 @@ describe.each(
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("query through datasource", () => {
|
describe("query through datasource", () => {
|
||||||
it("should be able to query a pg datasource", async () => {
|
it("should be able to query the datasource", async () => {
|
||||||
|
const entityId = "test_table"
|
||||||
|
await config.api.datasource.update({
|
||||||
|
...datasource,
|
||||||
|
entities: {
|
||||||
|
[entityId]: {
|
||||||
|
name: entityId,
|
||||||
|
schema: {},
|
||||||
|
type: "table",
|
||||||
|
sourceId: datasource._id!,
|
||||||
|
sourceType: TableSourceType.EXTERNAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
const res = await config.api.datasource.query({
|
const res = await config.api.datasource.query({
|
||||||
endpoint: {
|
endpoint: {
|
||||||
datasourceId: datasource._id!,
|
datasourceId: datasource._id!,
|
||||||
operation: Operation.READ,
|
operation: Operation.READ,
|
||||||
entityId: "test_table",
|
entityId,
|
||||||
},
|
},
|
||||||
resource: {
|
resource: {
|
||||||
fields: ["id", "name"],
|
fields: ["id", "name"],
|
||||||
|
|
|
@ -52,6 +52,12 @@ export async function getDatasourceAndQuery(
|
||||||
): Promise<DatasourcePlusQueryResponse> {
|
): Promise<DatasourcePlusQueryResponse> {
|
||||||
const datasourceId = json.endpoint.datasourceId
|
const datasourceId = json.endpoint.datasourceId
|
||||||
const datasource = await sdk.datasources.get(datasourceId)
|
const datasource = await sdk.datasources.get(datasourceId)
|
||||||
|
const table = datasource.entities?.[json.endpoint.entityId]
|
||||||
|
if (!json.meta && table) {
|
||||||
|
json.meta = {
|
||||||
|
table,
|
||||||
|
}
|
||||||
|
}
|
||||||
return makeExternalQuery(datasource, json)
|
return makeExternalQuery(datasource, json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ export class DatasourceAPI extends TestAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
query = async (
|
query = async (
|
||||||
query: Omit<QueryJson, "meta">,
|
query: Omit<QueryJson, "meta"> & Partial<Pick<QueryJson, "meta">>,
|
||||||
expectations?: Expectations
|
expectations?: Expectations
|
||||||
) => {
|
) => {
|
||||||
return await this._post<any>(`/api/datasources/query`, {
|
return await this._post<any>(`/api/datasources/query`, {
|
||||||
|
|
Loading…
Reference in New Issue