Skip to content

Commit e1a2cfa

Browse files
authored
fix(api-gateway): Handle array format for joins in /meta?extended endpoint (#9881)
* 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. * Extract the duplicate transformation logic into a local transformJoin function
1 parent 8ddaba5 commit e1a2cfa

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

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

82-
return Object.entries(joins)?.map(([joinName, join]: [joinName: string, join: any]) => ({
82+
const transformJoin = (join: any, name: string) => ({
8383
...join,
84-
name: joinName,
84+
name,
8585
sql: stringifyMemberSql(join.sql),
86-
}));
86+
});
87+
88+
// Handle joins as array (new format after PR #9800)
89+
if (Array.isArray(joins)) {
90+
return joins.map((join: any) => transformJoin(join, join.name));
91+
}
92+
93+
// Fallback for object format (legacy)
94+
return Object.entries(joins)?.map(([joinName, join]: [joinName: string, join: any]) => transformJoin(join, joinName));
8795
}
8896

8997
function transformPreAggregations(preAggregations: any) {

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)