feat: use apollo playground in debug mode (#3295)

This commit is contained in:
Jérémy M
2024-01-11 10:21:51 +01:00
committed by GitHub
parent ebe8698910
commit 1aa0f86724
4 changed files with 76 additions and 24 deletions

View File

@ -1,32 +1,47 @@
import { YogaDriver, YogaDriverConfig } from '@graphql-yoga/nestjs';
import { YogaDriverConfig } from '@graphql-yoga/nestjs';
import { GraphQLError } from 'graphql';
import GraphQLJSON from 'graphql-type-json';
import { maskError } from 'graphql-yoga';
import { handleExceptionAndConvertToGraphQLError } from 'src/filters/utils/global-exception-handler.util';
import { EnvironmentService } from 'src/integrations/environment/environment.service';
import { ExceptionHandlerService } from 'src/integrations/exception-handler/exception-handler.service';
import { MetadataModule } from 'src/metadata/metadata.module';
import { renderApolloPlayground } from 'src/workspace/utils/render-apollo-playground.util';
export const metadataModuleFactory = async (
environmentService: EnvironmentService,
exceptionHandlerService: ExceptionHandlerService,
): Promise<YogaDriverConfig> => ({
context: ({ req }) => ({ req }),
driver: YogaDriver,
autoSchemaFile: true,
include: [MetadataModule],
resolvers: { JSON: GraphQLJSON },
plugins: [],
path: '/metadata',
maskedErrors: {
maskError(error: GraphQLError, message, isDev) {
if (error.originalError) {
return handleExceptionAndConvertToGraphQLError(
error.originalError,
exceptionHandlerService,
);
}
return maskError(error, message, isDev);
): Promise<YogaDriverConfig> => {
const config: YogaDriverConfig = {
context: ({ req }) => ({ req }),
autoSchemaFile: true,
include: [MetadataModule],
renderGraphiQL() {
return renderApolloPlayground({ path: 'metadata' });
},
},
});
resolvers: { JSON: GraphQLJSON },
plugins: [],
path: '/metadata',
maskedErrors: {
maskError(error: GraphQLError, message, isDev) {
if (error.originalError) {
return handleExceptionAndConvertToGraphQLError(
error.originalError,
exceptionHandlerService,
);
}
return maskError(error, message, isDev);
},
},
};
if (environmentService.isDebugMode()) {
config.renderGraphiQL = () => {
return renderApolloPlayground({ path: 'metadata' });
};
}
return config;
};