import logging
from functools import wraps
logger = logging.getLogger(__name__)
def logging_strawberry_resolver(func):
@wraps(func)
def inner(*args, **kwargs):
info = kwargs.get("info")
if info is None:
raise ValueError("info must be passed as a keyword argument")
variable_values = info.variable_values
logger.info(f"Executing {info.field_name}", extra={"variable_values": variable_values})
return func(*args, **kwargs)
return inner
The provided code is currently functioning well. However, is it possible to simplify the way we access the 'info' keyword argument in the decorator as shown below?
import logging
from functools import wraps
from strawberry.types import Info
logger = logging.getLogger(__name__)
def logging_strawberry_resolver(func):
@wraps(func)
def inner(info: Info, *args, **kwargs):
variable_values = info.variable_values
logger.info(f"Executing {info.field_name}", extra={"variable_values": variable_values})
return func(*args, **kwargs)
return inner
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too