Using Graphql with Nestjs. I can use union types for custom excepitons like this;
export const CityUnion = createUnionType({
name: 'CityUnion',
types: () => [City, BaseCustomException] as const,
resolveType(value) {
if (value.errorCode) {
return BaseCustomException;
}
return City;
},
});
For authorization, I have permissions guards like this;
@Query(() => [Country])
@UseGuards(PermissionGuard)
async countries(
@Args('name', { type: () => String, nullable: true }) name: string,
) {
return await this.countryService.findAll(name);
}
My problem is, in case of authorization errors, client gets http 200. Is it possible to use union types in Permission guard to handle authorization errors in a schema based way?