loopbackio / loopbackio/loopback-next
[BUG]: @inject() + asProxyWithInterceptors make repository function not work!
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 5.1k
- フォーク
- 1.1k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 27
説明
### Describe the bug
# What is the problem
When I use the global interceptor:
`@inject('repositorys.xxxRepository', {asProxyWithInterceptors: true})` will be successfully intercepted.
But many functions of repository variable not work!
```typescript
export class TodoController {
constructor(
@inject('repositorys.TodoRepository', {asProxyWithInterceptors: true})
public todoRepository: TodoRepository,
) { }
@get('/todos')
@response(200, {
description: 'Array of Todo model instances',
content: {
'application/json': {
schema: {
type: 'array',
items: getModelSchemaRef(Todo, {includeRelations: true}),
},
},
},
})
async find(
@param.filter(Todo) filter?: Filter,
): Promise {
return this.todoRepository.find(filter);
}
}
```
HTTP Status Code 500 Error:
```cmd
Server is running at http://[::1]:3000
Try http://[::1]:3000/ping
TodoRepository#find() interceptor success!
Request GET /todos?filter=%7B%0A%20%0A%7D failed with status code 500. ResolutionError: The argument 'TodoRepository.prototype.find[1]' is not decorated
for dependency injection but no value was supplied by the caller. Did you forget to apply @inject() to the argument? (context: InterceptedInvocationContext-n626DiRrTbSKOXsrJCAr-w-38)
at D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\resolver.ts:233:15
at resolveList (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\value-promise.ts:169:28)
at resolveInjectedArguments (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\resolver.ts:220:21)
at invokeTargetMethodWithInjection (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\invocation.ts:223:49)
at InterceptedInvocationContext.invokeTargetMethod (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\invocation.ts:119:14)
at targetMethodInvoker (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor.ts:349:23)
at D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor-chain.ts:219:14
at transformValueOrPromise (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\value-promise.ts:298:12)
at GenericInterceptorChain.invokeNextInterceptor (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor-chain.ts:214:35)
at GenericInterceptorChain.next (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor-chain.ts:202:17)
at D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor-chain.ts:219:42
at TestInterceptor.intercept (D:\githubFile\loopback4-repository-proxy-issue\src\interceptors\test.interceptor.ts:55:28)
at D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor-chain.ts:219:14
at transformValueOrPromise (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\value-promise.ts:298:12)
at GenericInterceptorChain.invokeNextInterceptor (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor-chain.ts:214:35)
at GenericInterceptorChain.next (D:\githubFile\loopback4-repository-proxy-issue\node_modules\@loopback\context\src\interceptor-chain.ts:202:17)
```
# Expected behavior
The interceptor takes effect and the repository variable function work.
# Actual behavior
It throws the above exception.
# How to reproduce the problem
1. git clone [https://github.com/Embraceeeee/loopback4-repository-proxy-issue](https://github.com/Embraceeeee/loopback4-repository-proxy-issue)
2. npm install
3. npm start
4. visit url [http://[::1]:3000/explorer/#/TodoController](http://[::1]:3000/explorer/#/TodoController)
5. view output
### Logs
_No response_
### Additional information
_No response_
### Reproduction
https://github.com/Embraceeeee/loopback4-repository-proxy-issue
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている再現用リポジトリから始めます。npm install、npm start、および TodoController エンドポイントを実行して、失敗を再現します。src/interceptors/test.interceptor.ts と、stack trace に関係するリポジトリの proxy/interceptor エントリーポイントを読みます。interceptor が有効な状態でも dependency-resolution error が発生せず、リポジトリのメソッドが動作すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- nodejs, typescript
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100