loopbackio / loopbackio/loopback-next

[BUG]: @inject() + asProxyWithInterceptors make repository function not work!

Offen
#8,475 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug Repository
Vorherrschende Sprache
TypeScript
Sterne
5.1k
Forks
1.1k
Ø Merge
2 T. 21 Std.
Gemergte PRs (30 T.)
27

Beschreibung

### 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem verknüpften Reproduktions-Repository: Führe npm install, npm start und den TodoController-Endpunkt aus, um den Fehler zu reproduzieren. Lies src/interceptors/test.interceptor.ts sowie die Repository-Proxy-/Interceptor-Einstiegspunkte, die am Stack Trace beteiligt sind; abgeschlossen ist die Aufgabe, wenn die Repository-Methoden funktionieren, während der Interceptor aktiv ist, ohne dass der dependency-resolution error auftritt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
nodejs, typescript
Bereich
api, backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
32/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.