Strawberry provides support for adding extensions. Extensions can be used to
hook into different parts of the GraphQL execution and to provide additional
results to the GraphQL response.
To create a custom extensions you can use extend from our SchemaExtension base
class:
resolve can be used to run code before and after the execution of all
resolvers. When calling the underlying resolver using _next , all of the
arguments to resolve need to be passed to _next , as they will be needed by the
resolvers.
If you need to wrap only certain field resolvers with additional logic, please
check out field extensions .
Note that resolve can also be implemented asynchronously.
get_results allows to return a dictionary of data or alternatively an
awaitable resolving to a dictionary of data that will be included in the GraphQL
response.
Lifecycle hooks runs before graphql operation occur and after it is done.
Lifecycle hooks uses generator syntax. In example: on_operation hook can be
used to run code when a GraphQL operation starts and ends.
The SchemaExtension object has an execution_context property on self of
type ExecutionContext .
This object can be used to gain access to additional GraphQL context, or the
request context. Take a look at the
ExecutionContext type
for available data.