9e21e55db4
## Fix resolver schema leaking between `/metadata` and `/graphql` endpoints ### Summary - Patch `@nestjs/graphql` to support a `resolverSchemaScope` option that filters resolvers at both schema generation and runtime, preventing cross-endpoint leaking - Introduce `@CoreResolver()` and `@MetadataResolver()` decorators to explicitly scope each resolver to its endpoint - Move most resolvers (auth, billing, workspace, user, etc.) to the metadata schema where the frontend expects them; only workflow and timeline calendar/messaging resolvers remain on `/graphql` - Fix frontend `SSEQuerySubscribeEffect` to use the default (metadata) Apollo client instead of the core client ### Problem NestJS GraphQL's module-based resolver discovery traverses transitive imports, causing resolvers from `/metadata` modules to leak into the `/graphql` schema and vice versa. This made the schemas unpredictable and tightly coupled to module import order. ### Approach - Added `resolverSchemaScope` to `GqlModuleOptions` via a patch on `@nestjs/graphql`, filtering in both `filterResolvers()` (runtime binding) and `getAllCtors()` (schema generation) - Each resolver is explicitly decorated with `@CoreResolver()` or `@MetadataResolver()` - Organized decorator, constant, and type files under `graphql-config/` following project conventions Core GQL Schema: (see: no more fields!) <img width="827" height="894" alt="image" src="https://github.com/user-attachments/assets/668f3f0f-485e-43f0-92be-4345aeccacb6" /> Metadata GQL Schema (see no more getTimelineCalendarEventsFromCompany) <img width="827" height="894" alt="image" src="https://github.com/user-attachments/assets/443913db-e5fe-4161-b0e7-4a971cc80a71" />
83 lines
3.3 KiB
TypeScript
83 lines
3.3 KiB
TypeScript
import { UseGuards, UseInterceptors } from '@nestjs/common';
|
|
import { Args, Mutation, Query } from '@nestjs/graphql';
|
|
|
|
import { PermissionFlagType } from 'twenty-shared/constants';
|
|
|
|
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
|
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
|
import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';
|
|
import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
|
|
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
|
import { CreateSkillInput } from 'src/engine/metadata-modules/skill/dtos/create-skill.input';
|
|
import { SkillDTO } from 'src/engine/metadata-modules/skill/dtos/skill.dto';
|
|
import { UpdateSkillInput } from 'src/engine/metadata-modules/skill/dtos/update-skill.input';
|
|
import { SkillGraphqlApiExceptionInterceptor } from 'src/engine/metadata-modules/skill/interceptors/skill-graphql-api-exception.interceptor';
|
|
import { SkillService } from 'src/engine/metadata-modules/skill/skill.service';
|
|
import { WorkspaceMigrationGraphqlApiExceptionInterceptor } from 'src/engine/workspace-manager/workspace-migration/interceptors/workspace-migration-graphql-api-exception.interceptor';
|
|
|
|
@UseGuards(WorkspaceAuthGuard, SettingsPermissionGuard(PermissionFlagType.AI))
|
|
@UseInterceptors(
|
|
WorkspaceMigrationGraphqlApiExceptionInterceptor,
|
|
SkillGraphqlApiExceptionInterceptor,
|
|
)
|
|
@MetadataResolver(() => SkillDTO)
|
|
export class SkillResolver {
|
|
constructor(private readonly skillService: SkillService) {}
|
|
|
|
@Query(() => [SkillDTO])
|
|
async skills(
|
|
@AuthWorkspace() workspace: WorkspaceEntity,
|
|
): Promise<SkillDTO[]> {
|
|
return this.skillService.findAll(workspace.id);
|
|
}
|
|
|
|
@Query(() => SkillDTO, { nullable: true })
|
|
async skill(
|
|
@Args('id', { type: () => UUIDScalarType }) id: string,
|
|
@AuthWorkspace() workspace: WorkspaceEntity,
|
|
): Promise<SkillDTO | null> {
|
|
return this.skillService.findById(id, workspace.id);
|
|
}
|
|
|
|
@Mutation(() => SkillDTO)
|
|
async createSkill(
|
|
@Args('input') input: CreateSkillInput,
|
|
@AuthWorkspace() workspace: WorkspaceEntity,
|
|
): Promise<SkillDTO> {
|
|
return this.skillService.create(input, workspace.id);
|
|
}
|
|
|
|
@Mutation(() => SkillDTO)
|
|
async updateSkill(
|
|
@Args('input') input: UpdateSkillInput,
|
|
@AuthWorkspace() workspace: WorkspaceEntity,
|
|
): Promise<SkillDTO> {
|
|
return this.skillService.update(input, workspace.id);
|
|
}
|
|
|
|
@Mutation(() => SkillDTO)
|
|
async deleteSkill(
|
|
@Args('id', { type: () => UUIDScalarType }) id: string,
|
|
@AuthWorkspace() workspace: WorkspaceEntity,
|
|
): Promise<SkillDTO> {
|
|
return this.skillService.delete(id, workspace.id);
|
|
}
|
|
|
|
@Mutation(() => SkillDTO)
|
|
async activateSkill(
|
|
@Args('id', { type: () => UUIDScalarType }) id: string,
|
|
@AuthWorkspace() workspace: WorkspaceEntity,
|
|
): Promise<SkillDTO> {
|
|
return this.skillService.activate(id, workspace.id);
|
|
}
|
|
|
|
@Mutation(() => SkillDTO)
|
|
async deactivateSkill(
|
|
@Args('id', { type: () => UUIDScalarType }) id: string,
|
|
@AuthWorkspace() workspace: WorkspaceEntity,
|
|
): Promise<SkillDTO> {
|
|
return this.skillService.deactivate(id, workspace.id);
|
|
}
|
|
}
|