Direct execution - Remove conditional schema (#19383)
This commit is contained in:
+7
-2
@@ -8,6 +8,7 @@ import { classifyTopLevelFields } from 'src/engine/api/graphql/direct-execution/
|
||||
import { findOperationDefinition } from 'src/engine/api/graphql/direct-execution/utils/find-operation-definition.util';
|
||||
import { isSubscriptionOperation } from 'src/engine/api/graphql/direct-execution/utils/is-subscription-operation.util';
|
||||
import { type FeatureFlagService } from 'src/engine/core-modules/feature-flag/services/feature-flag.service';
|
||||
import { UserInputError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
|
||||
export type DirectExecutionPluginConfig = {
|
||||
directExecutionService: DirectExecutionService;
|
||||
@@ -54,8 +55,12 @@ export function useDirectExecution(
|
||||
const { hasIntrospectionFields, hasWorkspaceFields, hasCoreFields } =
|
||||
classifyTopLevelFields(document, operationName, workspaceResolverNames);
|
||||
|
||||
if (!hasCoreFields) {
|
||||
req.skipWorkspaceSchemaCreation = true;
|
||||
if (hasCoreFields && hasWorkspaceFields) {
|
||||
const error = new UserInputError(
|
||||
'This query cannot be executed as a single request. Please split it into separate queries.',
|
||||
);
|
||||
|
||||
return endResponse(Response.json({ errors: [error.toJSON()] }));
|
||||
}
|
||||
|
||||
if (hasCoreFields) {
|
||||
|
||||
+1
-68
@@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger, UnauthorizedException } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ContextIdFactory, ModuleRef } from '@nestjs/core';
|
||||
import { type GqlOptionsFactory } from '@nestjs/graphql';
|
||||
|
||||
@@ -7,14 +7,11 @@ import {
|
||||
type YogaDriverServerContext,
|
||||
} from '@graphql-yoga/nestjs';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { GraphQLError, GraphQLSchema } from 'graphql';
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
import {
|
||||
type GraphQLSchemaWithContext,
|
||||
type YogaInitialContext,
|
||||
} from 'graphql-yoga';
|
||||
import { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface';
|
||||
|
||||
@@ -35,7 +32,6 @@ import { MetricsKeys } from 'src/engine/core-modules/metrics/types/metrics-keys.
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { type FlatWorkspace } from 'src/engine/core-modules/workspace/types/flat-workspace.type';
|
||||
import { DataloaderService } from 'src/engine/dataloaders/dataloader.service';
|
||||
import { handleExceptionAndConvertToGraphQLError } from 'src/engine/utils/global-exception-handler.util';
|
||||
import { renderApolloPlayground } from 'src/engine/utils/render-apollo-playground.util';
|
||||
|
||||
export interface GraphQLContext extends YogaDriverServerContext<'express'> {
|
||||
@@ -47,8 +43,6 @@ export interface GraphQLContext extends YogaDriverServerContext<'express'> {
|
||||
export class GraphQLConfigService
|
||||
implements GqlOptionsFactory<YogaDriverConfig<'express'>>
|
||||
{
|
||||
private readonly logger = new Logger(GraphQLConfigService.name);
|
||||
|
||||
constructor(
|
||||
private readonly exceptionHandlerService: ExceptionHandlerService,
|
||||
private readonly twentyConfigService: TwentyConfigService,
|
||||
@@ -96,67 +90,6 @@ export class GraphQLConfigService
|
||||
include: [CoreEngineModule],
|
||||
resolverSchemaScope: 'core',
|
||||
buildSchemaOptions: {},
|
||||
conditionalSchema: async (context) => {
|
||||
const { workspace, user, application, skipWorkspaceSchemaCreation } =
|
||||
context.req;
|
||||
|
||||
try {
|
||||
if (!isDefined(workspace) || skipWorkspaceSchemaCreation) {
|
||||
return new GraphQLSchema({});
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
`Creating schema for workspace ${workspace.id} for request ${context?.req?.body?.operationName}`,
|
||||
);
|
||||
|
||||
return await this.createSchema(context, workspace, application?.id);
|
||||
} catch (error) {
|
||||
if (error instanceof UnauthorizedException) {
|
||||
throw new GraphQLError('Unauthenticated', {
|
||||
extensions: {
|
||||
code: 'UNAUTHENTICATED',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (error instanceof JsonWebTokenError) {
|
||||
//mockedUserJWT
|
||||
throw new GraphQLError('Unauthenticated', {
|
||||
extensions: {
|
||||
code: 'UNAUTHENTICATED',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (error instanceof TokenExpiredError) {
|
||||
throw new GraphQLError('Unauthenticated', {
|
||||
extensions: {
|
||||
code: 'UNAUTHENTICATED',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
throw handleExceptionAndConvertToGraphQLError(
|
||||
error,
|
||||
this.exceptionHandlerService,
|
||||
isDefined(user)
|
||||
? {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
}
|
||||
: undefined,
|
||||
isDefined(workspace)
|
||||
? {
|
||||
id: workspace.id,
|
||||
displayName: workspace.displayName,
|
||||
activationStatus: workspace.activationStatus,
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
}
|
||||
},
|
||||
resolvers: { JSON: GraphQLJSON },
|
||||
plugins: plugins,
|
||||
context: () => ({
|
||||
|
||||
Reference in New Issue
Block a user