feat: new relation schema generation (#9882)

Fix https://github.com/twentyhq/core-team-issues/issues/295

Based on the feature-flag `IsNewRelationEnabled` the schema will be
marked as outdated and regenerated, this will cause an error on the
front-end on the first request on the following ones schema will be well
generated ans request will work.
This commit is contained in:
Jérémy M
2025-01-29 10:33:17 +01:00
committed by GitHub
parent f74bb5a60b
commit fbb67d74c8
18 changed files with 361 additions and 24 deletions

View File

@ -5,6 +5,7 @@ import { EntitySchemaOptions } from 'typeorm';
import { InjectCacheStorage } from 'src/engine/core-modules/cache-storage/decorators/cache-storage.decorator';
import { CacheStorageService } from 'src/engine/core-modules/cache-storage/services/cache-storage.service';
import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/types/cache-storage-namespace.enum';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { ObjectMetadataMaps } from 'src/engine/metadata-modules/types/object-metadata-maps';
export enum WorkspaceCacheKeys {
@ -12,6 +13,7 @@ export enum WorkspaceCacheKeys {
GraphQLUsedScalarNames = 'graphql:used-scalar-names',
GraphQLOperations = 'graphql:operations',
ORMEntitySchemas = 'orm:entity-schemas',
GraphQLFeatureFlag = 'graphql:feature-flag',
MetadataObjectMetadataMaps = 'metadata:object-metadata-maps',
MetadataObjectMetadataOngoingCachingLock = 'metadata:object-metadata-ongoing-caching-lock',
MetadataVersion = 'metadata:workspace-metadata-version',
@ -156,6 +158,22 @@ export class WorkspaceCacheStorageService {
);
}
// TODO: remove this after the feature flag is droped
setIsNewRelationEnabled(workspaceId: string, isNewRelationEnabled: boolean) {
return this.cacheStorageService.set<boolean>(
`${WorkspaceCacheKeys.GraphQLFeatureFlag}:${workspaceId}:${FeatureFlagKey.IsNewRelationEnabled}`,
isNewRelationEnabled,
TTL_INFINITE,
);
}
// TODO: remove this after the feature flag is droped
getIsNewRelationEnabled(workspaceId: string): Promise<boolean | undefined> {
return this.cacheStorageService.get<boolean>(
`${WorkspaceCacheKeys.GraphQLFeatureFlag}:${workspaceId}:${FeatureFlagKey.IsNewRelationEnabled}`,
);
}
async flush(workspaceId: string, metadataVersion: number): Promise<void> {
await this.cacheStorageService.del(
`${WorkspaceCacheKeys.MetadataObjectMetadataMaps}:${workspaceId}:${metadataVersion}`,
@ -172,9 +190,13 @@ export class WorkspaceCacheStorageService {
await this.cacheStorageService.del(
`${WorkspaceCacheKeys.ORMEntitySchemas}:${workspaceId}:${metadataVersion}`,
);
await this.cacheStorageService.del(
`${WorkspaceCacheKeys.MetadataObjectMetadataOngoingCachingLock}:${workspaceId}:${metadataVersion}`,
);
// TODO: remove this after the feature flag is droped
await this.cacheStorageService.del(
`${FeatureFlagKey.IsNewRelationEnabled}:${workspaceId}`,
);
}
}