Untested but something like this should work (check is bound to functionpointer):
from functools import wraps
def run_only_once(resolve_func):
@wraps(resolve_func)
def wrapper(instance, next, root, info, *args, **kwargs):
if not getattr(resolve_func, "__once", False):
setattr(resolve_func, '__once', True)
return resolve_func(instance, next, root, info, *args, **kwargs)
return next(root, info, *args, **kwargs)
return wrapper
Btw. move the from functools import wraps
out of the function scope, otherwise this will be a dynamic import and will reimport wraps on every call