Comments (18)
@SlumberyDude посмотри пожалуйста тест в @atls/grpc-keto
- не могу понять почему падает
from nestjs.
@SlumberyDude столкнулся с другой проблемой - в интеграционном тесте KetoGuard
не видит свою зависимость KetoReadClientService
, хотя она поставляется модулем.
Воспроизведение: yarn test integration client-read.test
Nest can't resolve dependencies of the KetoGuard (Reflector, ?). Please make sure that the argument dependency at index [1] is available in the KetoIntegrationModule context.
Potential solutions:
- Is KetoIntegrationModule a valid NestJS module?
- If dependency is a provider, is it part of the current KetoIntegrationModule?
- If dependency is exported from a separate @Module, is that module imported within KetoIntegrationModule?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Сам тест находится тут: /packages/grpc-keto/integration/test
from nestjs.
@SlumberyDude сделал рефактор кода, добавил много чего в провайдеры. Сейчас ошибка такая:
Nest can't resolve dependencies of the KetoCheckClientService (?). Please make sure that the argument dependency at index [0] is available in the KetoModule context.
Речь о вот этом провайдере:
export class KetoCheckClientService extends CheckServiceClient {
constructor(@Inject(KETO_MODULE_OPTIONS) private readonly options: KetoModuleOptions) {
super(options.read, options.credentials)
}
}
И что странно, KETO_MODULE_OPTIONS
он якобы не находит, хотя они есть в модуле:
export const createKetoOptionsProvider = (options: KetoModuleOptions): Provider[] => [
{
provide: KETO_MODULE_OPTIONS,
useValue: options,
},
]
Можешь плиз посмотреть?
from nestjs.
@Nelfimov Исправил провайдеры на вот это
export const createKetoExportsProvider = (): Provider[] => [
{
provide: KETO_CHECK_CLIENT,
// useClass: KetoCheckClientService,
useFactory: (options: KetoModuleOptions) =>
new KetoCheckClientService(options),
inject: [KETO_MODULE_OPTIONS]
},
{
provide: KETO_WRITE_NATIVE_CLIENT,
// useClass: KetoWriteNativeClientService,
useFactory: (options: KetoModuleOptions) =>
new KetoWriteNativeClientService(options),
inject: [KETO_MODULE_OPTIONS]
},
{
provide: KETO_READ_CLIENT,
// useClass: KetoReadClientService,
useFactory: (checkClientService: KetoCheckClientService) =>
new KetoReadClientService(checkClientService),
inject: [KETO_WRITE_NATIVE_CLIENT]
},
{
provide: KETO_WRITE_CLIENT,
// useClass: KetoWriteClientService,
useFactory: (ketoWriteNativeClientService: KetoWriteNativeClientService) =>
new KetoWriteClientService(ketoWriteNativeClientService),
inject: [KETO_CHECK_CLIENT]
},
{
provide: KETO_GUARD,
useFactory: (reflector: Reflector, ketoReadClient: KetoReadClientService) =>
new KetoGuard(reflector, ketoReadClient),
inject: [KETO_READ_CLIENT],
},
]
Прокатило, чтобы yarn test integration grpc-keto
перестал выдавать ошибки связанные с зависимостями, но в решении я не уверен.
from nestjs.
Теперь будто прошлись по кругу и вернулись обратно:
Nest can't resolve dependencies of the KetoGuard (Reflector, ?). Please make sure that the argument dependency at index [1] is available in the KetoIntegrationModule context.
@Module({
imports: [
KetoModule.register({
read: 'http://localhost:4466',
write: 'http://localhost:4467',
}),
],
controllers: [KetoIntegrationController],
})
export class KetoIntegrationModule {}
@Injectable()
export class KetoGuard implements CanActivate {
constructor(
private readonly reflector: Reflector,
@Inject(KETO_READ_CLIENT) private readonly ketoReadClient: KetoReadClientService
) {}
...
from nestjs.
Решил проблему - гарды нельзя экспортировать, иначе они не увидят скоуп модуля куда импортируются. Поэтому просто убрал гард из экспортируемых провайдеров.
Тут подробнее: nestjs/nest#3856 (comment)
from nestjs.
@Nelfimov Нашел вот тут похожий кейс, что глобальную константу нестовую не нужно экспортировать, если убрать guardProvider
из экспортируемых переменных, то ошибки не будет. Ну или создать под гард отдельную свою константу, а не APP_GUARD
хотя скорее всего это будет уже не то.
Наверное глобальный гард можно не экспортировать, потому что в доке написано, что они распространяются на все приложение. (вот непонятно, где это приложение заканчивается) https://docs.nestjs.com/guards и будут работать для всего приложения наверное
Global guards are used across the whole application, for every controller and every route handler. In terms of dependency injection, global guards registered from outside of any module
When using this approach to perform dependency injection for the guard, note that regardless of the module where this construction is employed, the guard is, in fact, global.
from nestjs.
@SlumberyDude столкнулся с другой проблемой - в интеграционном тесте
KetoGuard
не видит свою зависимостьKetoReadClientService
, хотя она поставляется модулем.Воспроизведение:
yarn test integration client-read.test
Nest can't resolve dependencies of the KetoGuard (Reflector, ?). Please make sure that the argument dependency at index [1] is available in the KetoIntegrationModule context. Potential solutions: - Is KetoIntegrationModule a valid NestJS module? - If dependency is a provider, is it part of the current KetoIntegrationModule? - If dependency is exported from a separate @Module, is that module imported within KetoIntegrationModule? @Module({ imports: [ /* the Module containing dependency */ ] })Сам тест находится тут:
/packages/grpc-keto/integration/test
пересобери ярн
from nestjs.
Снос yarn.lock
и пересборка не помогли.
После этого повалились все тайпчеки по репе из-за нефиксированных версий.
from nestjs.
@Nelfimov папку кеш, а не ярн лок
from nestjs.
не помогло
from nestjs.
@Nelfimov Проблема в том, что из модуля KetoModule
гард экспортируется в виде
{
provide: KETO_GUARD,
useFactory: (reflector: Reflector, ketoReadClient: KetoReadClientService) =>
new KetoGuard(reflector, ketoReadClient),
inject: [KETO_READ_CLIENT],
},
То есть он привязывается к токену-константе KETO_GUARD
А потом уже в контроллере клиент (у нас KetoIntegrationController
) использует @UseGuards(KetoGuard)
что не прокатывает потому что экспортируется не KetoGuard
, а KETO_GUARD
. Вот ищу как это обойти, пока что не могу загуглить как экспортированный в виде токена гард потом использовать в декораторе @UseGuards
. Обычно эти экспортированные в виде токенов-констант провайдеры инжектят в другие провайдеры через @Inject(OTHER_PROVIDER_TOKEN) otherProvider: OtherProvider
, но тут другой случай.
from nestjs.
@Nelfimov Если явно добавить CheckServiceClient, KetoReadClientService, KetoGuard
в список провайдеров в кето модуль, то вроде ошибка импорта чинится,
return {
global: options?.global ?? true,
module: KetoModule,
providers: [...optionsProvider, ...exportsProvider, CheckServiceClient, KetoReadClientService, KetoGuard],
exports: [...exportsProvider]
}
Другого способа пока что не нашел
from nestjs.
@Nelfimov Может действительно было правильно (как изначально было) сделать guard
провайдер как-то вроде
{
provide: APP_GUARD,
useFactory: (reflector: Reflector, ketoReadClient: KetoReadClientService) =>
new KetoGuard(reflector, ketoReadClient),
inject: [KETO_READ_CLIENT],
}
Чтобы сделать его глобальным. Тогда вроде его не нужно экспортировать, а только записать в провайдеры. И убрать @UseGuards(KetoGuard)
из контроллера KetoIntegrationController
(потому что по идее глобальный гард должен работать и так - то есть без декоратора).
Нужно проверить, будет ли такой глобальный гард работать.
from nestjs.
Проверю, однако цель у этого адаптера сделать локальный гард чтобы покрывать только часть контроллера.
from nestjs.
@Nelfimov А как в прошлый раз получилось преодолеть ошибку, когда такая же была? Ты говоришь мы сделали круг.
from nestjs.
@Nelfimov А если их не экспортировать, то тогда как ими пользоваться?
from nestjs.
Брать напрямую из пакета и использовать в UseGuards
from nestjs.
Related Issues (20)
- [bug] nestjs-map-errors-interceptor works incorrectly with nestjs >7 HOT 1
- NestJS Gateway Type
- Connection isn't provided HOT 1
- Обновление grpc-playground HOT 21
- Обновление grpc-errors
- Обновление grpc-http-proxy
- Обновление `grpc-identity` HOT 5
- Обновление `grpc-reflection` HOT 3
- Обновление зависимостей `dataloader` HOT 8
- Обновление зависимостей `external-renderer` HOT 9
- Обновление зависимостей `gateway` HOT 9
- Обновление зависимостей `hydra`
- Обновление зависимостей `keto` HOT 4
- Обновление зависимостей `kratos` HOT 4
- Обновление зависимостей `logger`
- Обновление зависимостей `signed-url` HOT 2
- Обновление зависимостей `typeorm-seeding`
- Обновление зависимостей `typesense` HOT 1
- Обновление зависимостей `typesense-typeorm` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs.