NestJS GraphQL Context

오픈소스·2024년 8월 2일
0

https://github.com/nestjs/nest/blob/master/packages/common/interfaces/features/arguments-host.interface.ts

export type ContextType = 'http' | 'ws' | 'rpc';

https://github.com/nestjs/graphql/blob/master/packages/graphql/lib/services/gql-execution-context.ts

export type GqlContextType = 'graphql' | ContextType;


위와 같은 형태라서, Exception Filter를 Global로 같이 사용하면,
host: ArgumentsHost

  • host.getType<ContextType>() // 'http'
  • host.getType<GqlContextType>() // 'graphql'

둘 다 받아 처리해야 합니다.

GraphQL을 사용할 때는 useGlobalFilters로 모든 Exception을 처리하는 것보다,
UseFilters로 Resolver는 독립적인 ExceptionFilter를 사용하는게 더 좋을 듯 싶습니다.

참고)

0개의 댓글