Skip to content

Commit fab1b6a

Browse files
authored
fix(graphql): exclude empty cubes, revert equals/notEquals type (#6619)
1 parent d724f09 commit fab1b6a

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const DateTimeScalar = asNexusMethod(DateTimeResolver, 'date');
3737
const FloatFilter = inputObjectType({
3838
name: 'FloatFilter',
3939
definition(t) {
40-
t.list.float('equals');
41-
t.list.float('notEquals');
40+
t.float('equals');
41+
t.float('notEquals');
4242
t.list.float('in');
4343
t.list.float('notIn');
4444
t.boolean('set');
@@ -52,8 +52,8 @@ const FloatFilter = inputObjectType({
5252
const StringFilter = inputObjectType({
5353
name: 'StringFilter',
5454
definition(t) {
55-
t.list.string('equals');
56-
t.list.string('notEquals');
55+
t.string('equals');
56+
t.string('notEquals');
5757
t.list.string('in');
5858
t.list.string('notIn');
5959
t.list.string('contains');
@@ -257,10 +257,11 @@ function getMemberType(metaConfig: any, cubeName: string, memberName: string) {
257257

258258
function whereArgToQueryFilters(
259259
whereArg: Record<string, any>,
260-
prefix?: string
260+
prefix?: string,
261+
metaConfig: any[] = []
261262
) {
262263
const queryFilters: any[] = [];
263-
264+
264265
Object.keys(whereArg).forEach((key) => {
265266
if (['OR', 'AND'].includes(key)) {
266267
queryFilters.push({
@@ -281,6 +282,8 @@ function whereArgToQueryFilters(
281282
// age: { equals: 28 } # <-- will require AND
282283
// }
283284
if (Object.keys(whereArg[key]).length > 1) {
285+
const cubeExists = metaConfig.find((cube) => cube.config.name === key);
286+
284287
queryFilters.push(
285288
...whereArgToQueryFilters(
286289
{
@@ -289,7 +292,7 @@ function whereArgToQueryFilters(
289292
[]
290293
),
291294
},
292-
capitalize(key)
295+
cubeExists ? key : capitalize(key)
293296
)
294297
);
295298
} else {
@@ -312,10 +315,12 @@ function whereArgToQueryFilters(
312315
} else {
313316
Object.entries<any>(whereArg[key]).forEach(([member, filters]) => {
314317
Object.entries(filters).forEach(([operator, value]) => {
318+
const cubeExists = metaConfig.find((cube) => cube.config.name === key);
319+
315320
queryFilters.push({
316321
member: prefix
317322
? `${prefix}.${key}`
318-
: `${capitalize(key)}.${member}`,
323+
: `${cubeExists ? key : capitalize(key)}.${member}`,
319324
operator: mapWhereOperator(operator, value),
320325
...(mapWhereValue(operator, value) && {
321326
values: mapWhereValue(operator, value),
@@ -359,7 +364,11 @@ export function makeSchema(metaConfig: any): GraphQLSchema {
359364
];
360365

361366
function hasMembers(cube: any) {
362-
return cube.config.measures.length || cube.config.dimensions.length;
367+
if (cube.public === false) {
368+
return false;
369+
}
370+
371+
return ([...cube.config.measures, ...cube.config.dimensions].filter((member) => member.isVisible)).length > 0;
363372
}
364373

365374
metaConfig.forEach(cube => {
@@ -504,7 +513,7 @@ export function makeSchema(metaConfig: any): GraphQLSchema {
504513
const order: [string, 'asc' | 'desc'][] = [];
505514

506515
if (where) {
507-
filters = whereArgToQueryFilters(where);
516+
filters = whereArgToQueryFilters(where, undefined, metaConfig);
508517
}
509518

510519
if (orderBy) {
@@ -517,6 +526,7 @@ export function makeSchema(metaConfig: any): GraphQLSchema {
517526

518527
getFieldNodeChildren(infos.fieldNodes[0], infos).forEach(cubeNode => {
519528
const cubeExists = metaConfig.find((cube) => cube.config.name === cubeNode.name.value);
529+
520530
const cubeName = cubeExists ? (cubeNode.name.value) : capitalize(cubeNode.name.value);
521531
const orderByArg = getArgumentValue(cubeNode, 'orderBy', infos.variableValues);
522532
// todo: throw if both RootOrderByInput and [Cube]OrderByInput provided

0 commit comments

Comments
 (0)