graphql-python / graphql-python/graphql-core-legacy
Middleware can not add errors to execution context without raising an error
- Vorherrschende Sprache
- Python
- Sterne
- 371
- Forks
- 175
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Use case: I've written a middleware for limiting users to a daily quota of nodes. The middleware counts nodes of particular types we care about limiting, and when the user hits their limit the middleware will raise an exception saying that they've hit their limit.
This works great, except in the case of lists. In this case, we are returning to the user as many elements of the list as possible until they go over the limit, and then no more. In this case, the middleware can not raise an exception because that would prevent it from also returning the promise for the truncated list of data.
Ideally in the middleware I could call execution_context.report_error() from https://github.com/graphql-python/graphql-core/blob/b3a6bd0f89651af10a937e5270e46c696672a2e5/graphql/execution/base.py#L92 to add an error saying "your limit was hit, and list field XYZ has had its data truncated" to the list of reported errors, but then continue along and return the truncated list of data.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne mit dem Lesen von graphql/execution/base.py rund um ExecutionContext.report_error(), das im Issue als relevanter Einstiegspunkt identifiziert wird. Verfolge, wie Fehler in Middleware derzeit ausgelöst und gesammelt werden, und definiere anschließend die Fertigstellung so, dass ein Fehler gemeldet werden kann, während die Ausführung fortgesetzt wird und eine gekürzte Liste zurückgibt. Im Issue wird keine Testdatei erwähnt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend-api-design
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100