Skip to content

Commit

Permalink
Added more protection
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbordeau committed Nov 14, 2024
1 parent a78b297 commit ea89cc3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, LoggerService } from '@nestjs/common';

import { Record as ObjectRecord } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface';
import { QueryResultFieldValue } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/interfaces/query-result-field-value';
Expand All @@ -14,6 +14,7 @@ import { WorkspaceMemberQueryResultGetterHandler } from 'src/engine/api/graphql/
import { isQueryResultFieldValueAConnection } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/utils/is-query-result-field-value-a-connection.guard';
import { isQueryResultFieldValueANestedRecordArray } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/utils/is-query-result-field-value-a-nested-record-array.guard';
import { isQueryResultFieldValueARecordArray } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/utils/is-query-result-field-value-a-record-array.guard';
import { isQueryResultFieldValueARecord } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/utils/is-query-result-field-value-a-record.guard';
import { FileService } from 'src/engine/core-modules/file/services/file.service';
import { ObjectMetadataMap } from 'src/engine/metadata-modules/utils/generate-object-metadata-map.util';
import { isRelationFieldMetadataType } from 'src/engine/utils/is-relation-field-metadata-type.util';
Expand All @@ -26,7 +27,10 @@ import { isDefined } from 'src/utils/is-defined';
export class QueryResultGettersFactory {
private handlers: Map<string, QueryResultGetterHandlerInterface>;

constructor(private readonly fileService: FileService) {
constructor(
private readonly fileService: FileService,
private readonly loggerService: LoggerService,
) {
this.initializeHandlers();
}

Expand Down Expand Up @@ -203,13 +207,20 @@ export class QueryResultGettersFactory {
objectMetadataMap,
workspaceId,
);
} else {
} else if (isQueryResultFieldValueARecord(queryResultField)) {
return await this.processRecord(
queryResultField,
objectMetadataItemId,
objectMetadataMap,
workspaceId,
);
} else {
this.loggerService.warn(
`Query result field is not a record, connection, nested record array or record array.
This is an undetected case in query result getter that should be implemented !!`,
);

return queryResultField;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Record as ObjectRecord } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface';
import { QueryResultFieldValue } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/interfaces/query-result-field-value';

export const isQueryResultFieldValueARecord = (
result: QueryResultFieldValue,
): result is ObjectRecord[] => {
return 'id' in result && 'createdAt' in result && 'updatedAt' in result;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AuthModule } from 'src/engine/core-modules/auth/auth.module';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';
import { FileModule } from 'src/engine/core-modules/file/file.module';
import { LoggerModule } from 'src/engine/core-modules/logger/logger.module';
import { TelemetryModule } from 'src/engine/core-modules/telemetry/telemetry.module';
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
Expand All @@ -30,6 +31,7 @@ import { EntityEventsToDbListener } from './listeners/entity-events-to-db.listen
TelemetryModule,
FileModule,
FeatureFlagModule,
LoggerModule,
],
providers: [
...workspaceQueryRunnerFactories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
const objectMetadata =
objectMetadataMap[fieldMetadataItem.objectMetadataId];

if (!objectMetadata) {
return new NotFoundException(
`Object metadata not found for field ${fieldMetadataItem.id}`,
);
}

const fieldMetadata = objectMetadata.fields[fieldMetadataItem.id];

const relationMetadata =
Expand Down

0 comments on commit ea89cc3

Please sign in to comment.