diff --git a/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts b/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts index 5bb40542bfa..efbffa6a8ae 100644 --- a/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts +++ b/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts @@ -284,6 +284,12 @@ export class ApolloFactory implements ApolloManager { return; // already caught in BE } default: + // Schema-validation errors (no extension code) caused by + // unauthenticated requests are expected and non-actionable; + // skip Sentry when there is no token pair. + if (isUndefinedOrNull(getTokenPair())) { + return; + } sendToSentry({ graphQLError, operation }); } } diff --git a/packages/twenty-server/src/engine/api/graphql/graphql-config/graphql-config.service.ts b/packages/twenty-server/src/engine/api/graphql/graphql-config/graphql-config.service.ts index 6c7715a1836..8ea7dde6aa6 100644 --- a/packages/twenty-server/src/engine/api/graphql/graphql-config/graphql-config.service.ts +++ b/packages/twenty-server/src/engine/api/graphql/graphql-config/graphql-config.service.ts @@ -7,7 +7,7 @@ import { type YogaDriverServerContext, } from '@graphql-yoga/nestjs'; import * as Sentry from '@sentry/node'; -import { GraphQLError, GraphQLSchema } from 'graphql'; +import { GraphQLError } from 'graphql'; import GraphQLJSON from 'graphql-type-json'; import { type GraphQLSchemaWithContext, @@ -87,11 +87,15 @@ export class GraphQLConfigService conditionalSchema: async (context) => { const { workspace, user, application } = context.req; - try { - if (!isDefined(workspace)) { - return new GraphQLSchema({}); - } + if (!isDefined(workspace)) { + throw new GraphQLError('Unauthenticated', { + extensions: { + code: 'UNAUTHENTICATED', + }, + }); + } + try { return await this.createSchema(context, workspace, application?.id); } catch (error) { if (error instanceof UnauthorizedException) {