strawberry
strawberry copied to clipboard
Execution Context errors
What is self.execution_context.errors on an extension, is it needed? (we have errors on the result)
Related: https://github.com/StellateHQ/stellate-strawberry/pull/6
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
Good point. I just spend some time looking at the code. In a nutshell: execution_context.result is not available during the execution of early extension hooks such the parsing hook.
Longer explanation:
During execution, the execution context is first created in the schema.execute and schema.execute_sync methods. At this point the execution_context.result is still None.
https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/schema/schema.py#L257-L264
Next the operation, parsing and validation hooks of all extensions are called. If they catch any errors (for example while parsing the query) they add it to execution_context.errors because executon_context.result(.errors) is not available yet.
https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/schema/execute.py#L103-L117
One all extension hooks are done execution_context.errors is copied to execution_context.result.errors:
https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/schema/execute.py#L173-L177
I agree it would be much cleaner and less error-prone if only one of them would be available to extensions.