Skip to content

Commit f1140de

Browse files
authored
Revert "chore(cubejs-api-gateway): added endpoint to run sql query directly (#5723)" (#5784)
This reverts commit f1e25bb.
1 parent 17ba3e2 commit f1140de

File tree

2 files changed

+0
-113
lines changed

2 files changed

+0
-113
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,6 @@ class ApiGateway {
251251
}
252252
}));
253253

254-
app.post(
255-
`${this.basePath}/v1/sql-runner`,
256-
jsonParser,
257-
userMiddlewares,
258-
async (req: Request, res: Response) => {
259-
await this.sqlRunner({
260-
query: req.body.query,
261-
context: req.context!,
262-
res: this.resToResultFn(res),
263-
});
264-
}
265-
);
266-
267254
app.get(`${this.basePath}/v1/run-scheduled-refresh`, userMiddlewares, (async (req, res) => {
268255
await this.runScheduledRefresh({
269256
queryingOptions: req.query.queryingOptions,
@@ -1083,54 +1070,6 @@ class ApiGateway {
10831070
}
10841071
}
10851072

1086-
public async sqlRunner({ query, context, res }: QueryRequest) {
1087-
const requestStarted = new Date();
1088-
try {
1089-
if (!query) {
1090-
throw new UserError(
1091-
'A user\'s query must contain a body'
1092-
);
1093-
}
1094-
1095-
if (!(query as Record<string, any>).query) {
1096-
throw new UserError(
1097-
'A user\'s query must contain at least one query param.'
1098-
);
1099-
}
1100-
1101-
query = {
1102-
...query,
1103-
requestId: context.requestId
1104-
};
1105-
1106-
this.log(
1107-
{
1108-
type: 'Load SQL Runner Request',
1109-
query,
1110-
},
1111-
context
1112-
);
1113-
1114-
const result = await this.getAdapterApi(context).executeQuery(query);
1115-
1116-
this.log(
1117-
{
1118-
type: 'Load SQL Runner Request Success',
1119-
query,
1120-
duration: this.duration(requestStarted),
1121-
dbType: result.dbType,
1122-
},
1123-
context
1124-
);
1125-
1126-
res(result);
1127-
} catch (e) {
1128-
this.handleError({
1129-
e, context, query, res, requestStarted
1130-
});
1131-
}
1132-
}
1133-
11341073
protected createSecurityContextExtractor(options?: JWTOptions): SecurityContextExtractorFn {
11351074
if (options?.claimsNamespace) {
11361075
return (ctx: Readonly<RequestContext>) => {

packages/cubejs-api-gateway/test/index.test.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -339,58 +339,6 @@ describe('API Gateway', () => {
339339
expect(res.body.query.measures).toStrictEqual(['Foo.bar']);
340340
});
341341

342-
test('post http method for sql-runner route required params', async () => {
343-
const { app } = createApiGateway();
344-
345-
const res = await request(app)
346-
.post('/cubejs-api/v1/sql-runner')
347-
.set('Content-type', 'application/json')
348-
.set(
349-
'Authorization',
350-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
351-
)
352-
.send({})
353-
.expect(400);
354-
355-
expect(res.body && res.body.error).toStrictEqual('A user\'s query must contain a body');
356-
357-
const res2 = await request(app)
358-
.post('/cubejs-api/v1/sql-runner')
359-
.set('Content-type', 'application/json')
360-
.set(
361-
'Authorization',
362-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
363-
)
364-
.send({ query: { query: '' } })
365-
.expect(400);
366-
367-
expect(res2.body && res2.body.error).toStrictEqual(
368-
'A user\'s query must contain at least one query param.'
369-
);
370-
});
371-
372-
test('post http method for sql-runner route', async () => {
373-
const { app } = createApiGateway();
374-
375-
const query = {
376-
query: 'SELECT * FROM Foo',
377-
};
378-
379-
const res = await request(app)
380-
.post('/cubejs-api/v1/sql-runner')
381-
.set('Content-type', 'application/json')
382-
.set(
383-
'Authorization',
384-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
385-
)
386-
.send({ query })
387-
.expect(200);
388-
389-
expect(res.body.data).toStrictEqual([
390-
{ foo__bar: 42 },
391-
]);
392-
});
393-
394342
test('meta endpoint to get schema information', async () => {
395343
const { app } = createApiGateway();
396344

0 commit comments

Comments
 (0)