-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
import functools | ||
from strawberry.types.fields.resolver import StrawberryResolver | ||
|
||
from .resolvers import get_resolver_arguments | ||
from .resolvers import get_arguments | ||
from .utils.inspect import get_func_args | ||
|
||
|
||
def make_strawberry_decorator(func): | ||
def decorator(resolver): | ||
if hasattr(resolver, "_field_definition"): | ||
raise Exception("Can't apply decorator after strawberry.field") # TODO | ||
################################################################## | ||
### aaaaaaaaaaaaaaaaaaaa | ||
return StrawberryResolver(resolver, decorators=[func]) | ||
|
||
function_args = get_func_args(resolver) | ||
return decorator | ||
|
||
@functools.wraps(resolver) | ||
def wrapped_resolver(source, info, **kwargs): | ||
def wrapped(**kwargs): | ||
# If resolver is another strawberry decorator then pass all the | ||
# arguments to it | ||
if getattr(resolver, "_strawberry_decorator", False): | ||
return resolver(source, info, **kwargs) | ||
... | ||
|
||
args, extra_kwargs = get_resolver_arguments(function_args, source, info) | ||
return resolver(*args, **extra_kwargs, **kwargs) | ||
# def decorator(resolver): | ||
# if hasattr(resolver, "_field_definition"): | ||
# raise Exception("Can't apply decorator after strawberry.field") # TODO | ||
|
||
# Call the decorator body with the original set of kwargs so that it | ||
# has the opportunity to modify them | ||
return func(wrapped, source, info=info, **kwargs) | ||
# function_args = get_func_args(resolver) | ||
|
||
wrapped_resolver._strawberry_decorator = True | ||
# @functools.wraps(resolver) | ||
# def wrapped_resolver(root, info, **kwargs): | ||
# def wrapped(**kwargs): | ||
# # If resolver is another strawberry decorator then pass all the | ||
# # arguments to it | ||
# if getattr(resolver, "_strawberry_decorator", False): | ||
# return resolver(root, info, **kwargs) | ||
|
||
return wrapped_resolver | ||
# breakpoint() | ||
|
||
return decorator | ||
# args, kwargs = get_arguments( | ||
# function_args, kwargs=kwargs, source=root, info=info | ||
# ) | ||
# return resolver(*args, **kwargs) | ||
|
||
# # Call the decorator body with the original set of kwargs so that it | ||
# # has the opportunity to modify them | ||
# return func(wrapped, root, info=info, **kwargs) | ||
|
||
# wrapped_resolver._strawberry_decorator = True | ||
|
||
# return wrapped_resolver | ||
|
||
# return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters