Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorize 0 depth #6171

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const fieldMultiSelectMock = {
],
};

const fieldRelationMock = {
export const fieldRelationMock = {
name: 'fieldRelation',
type: FieldMetadataType.RELATION,
fromRelationMetadata: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { computeDepth } from 'src/engine/api/rest/core/query-builder/utils/compute-depth.utils';

describe('computeDepth', () => {
it('should compute depth from query', () => {
const request: any = {
query: { depth: '1' },
};
[0, 1, 2].forEach((depth) => {
it('should compute depth from query', () => {
const request: any = {
query: { depth: `${depth}` },
};

expect(computeDepth(request)).toEqual(1);
expect(computeDepth(request)).toEqual(depth);
});
});

it('should return default depth if missing', () => {
Expand All @@ -19,7 +21,7 @@ describe('computeDepth', () => {

expect(() => computeDepth(request)).toThrow();

request.query.depth = '0';
request.query.depth = '-1';

expect(() => computeDepth(request)).toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BadRequestException } from '@nestjs/common';

import { Request } from 'express';

const ALLOWED_DEPTH_VALUES = [1, 2];
const ALLOWED_DEPTH_VALUES = [0, 1, 2];

export const computeDepth = (request: Request): number | undefined => {
if (!request.query.depth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const mapFieldMetadataToGraphqlQuery = (
field,
maxDepthForRelations = DEFAULT_DEPTH_VALUE,
): string | undefined => {
if (maxDepthForRelations <= 0) {
if (maxDepthForRelations < 0) {
return '';
}

Expand All @@ -32,6 +32,7 @@ export const mapFieldMetadataToGraphqlQuery = (
if (fieldIsSimpleValue) {
return field.name;
} else if (
maxDepthForRelations > 0 &&
fieldType === FieldMetadataType.RELATION &&
field.toRelationMetadata?.relationType === RelationMetadataType.ONE_TO_MANY
) {
Expand All @@ -45,7 +46,6 @@ export const mapFieldMetadataToGraphqlQuery = (
{
id
${(relationMetadataItem?.fields ?? [])
.filter((field) => field.type !== FieldMetadataType.RELATION)
.map((field) =>
mapFieldMetadataToGraphqlQuery(
objectMetadataItems,
Expand All @@ -56,6 +56,7 @@ export const mapFieldMetadataToGraphqlQuery = (
.join('\n')}
}`;
} else if (
maxDepthForRelations > 0 &&
fieldType === FieldMetadataType.RELATION &&
field.fromRelationMetadata?.relationType ===
RelationMetadataType.ONE_TO_MANY
Expand All @@ -72,7 +73,6 @@ export const mapFieldMetadataToGraphqlQuery = (
node {
id
${(relationMetadataItem?.fields ?? [])
.filter((field) => field.type !== FieldMetadataType.RELATION)
.map((field) =>
mapFieldMetadataToGraphqlQuery(
objectMetadataItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('computeParameters', () => {
required: false,
schema: {
type: 'integer',
enum: [1, 2],
enum: [0, 1, 2],
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const computeDepthParameters = (): OpenAPIV3_1.ParameterObject => {
required: false,
schema: {
type: 'integer',
enum: [1, 2],
enum: [0, 1, 2],
},
};
};
Expand Down
Loading