Skip to content

Commit b3ed86d

Browse files
committed
fix(api-gateway): Handle array format for joins in /meta?extended endpoint
After PR #9800, joins are stored as arrays instead of objects in the schema compiler. The transformJoins function in the API gateway was still using Object.entries() which, when applied to arrays, returns numeric indices as keys instead of actual join names. This fix: - Checks if joins is an array and preserves the name property - Maintains backward compatibility with object format - Adds test coverage for both array and object formats Fixes the issue where join names appear as "0", "1", "2" instead of their actual names in the /meta?extended endpoint response.
1 parent 26e477b commit b3ed86d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ function transformJoins(joins: any) {
7979
return undefined;
8080
}
8181

82+
// Handle joins as array (new format after PR #9800)
83+
if (Array.isArray(joins)) {
84+
return joins.map((join: any) => ({
85+
...join,
86+
name: join.name,
87+
sql: stringifyMemberSql(join.sql),
88+
}));
89+
}
90+
91+
// Fallback for object format (legacy)
8292
return Object.entries(joins)?.map(([joinName, join]: [joinName: string, join: any]) => ({
8393
...join,
8494
name: joinName,

packages/cubejs-api-gateway/test/helpers/transformMetaExtended.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,30 @@ describe('transformMetaExtended helpers', () => {
219219
expect(handledJoins?.length).toBe(2);
220220
});
221221

222+
test('transformJoins - array format', () => {
223+
// Test new array format (after PR #9800)
224+
const arrayJoins = [
225+
{
226+
name: 'PlaygroundUsers',
227+
relationship: 'belongsTo',
228+
sql: () => `{CUBE}.id = {PlaygroundUsers.anonymous}`,
229+
},
230+
{
231+
name: 'IpEnrich',
232+
relationship: 'belongsTo',
233+
sql: () => `{CUBE.email} = {IpEnrich.email}`,
234+
},
235+
];
236+
237+
const handledJoins = transformJoins(arrayJoins);
238+
expect(handledJoins).toBeDefined();
239+
expect(handledJoins?.length).toBe(2);
240+
expect(handledJoins?.[0].name).toBe('PlaygroundUsers');
241+
expect(handledJoins?.[1].name).toBe('IpEnrich');
242+
expect(handledJoins?.[0].sql).toBe('`{CUBE}.id = {PlaygroundUsers.anonymous}`');
243+
expect(handledJoins?.[1].sql).toBe('`{CUBE.email} = {IpEnrich.email}`');
244+
});
245+
222246
test('transformPreAggregations', () => {
223247
expect(transformPreAggregations(undefined)).toBeUndefined();
224248
const handledPreAggregations = transformPreAggregations(MOCK_USERS_CUBE.preAggregations);

0 commit comments

Comments
 (0)