Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware can not add errors to execution context without raising an error #177

Open
dan98765 opened this issue May 21, 2018 · 2 comments

Comments

@dan98765
Copy link
Collaborator

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.

@dan98765
Copy link
Collaborator Author

It looks like #153 would also solve this.

@nikordaris
Copy link

I think my PR for exposing extensions might also solve this problem. graphql-python/graphql-core#205. This optionally allows middleware to return the ExecutionResult object which in theory would allow you to set both an error and data object as the return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants