-
-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move where we create the resolvers for our fields #1044
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1044 +/- ##
==========================================
- Coverage 97.76% 97.75% -0.01%
==========================================
Files 78 78
Lines 2813 2811 -2
Branches 382 383 +1
==========================================
- Hits 2750 2748 -2
Misses 41 41
Partials 22 22 |
def _get_arguments( | ||
self, | ||
field: StrawberryField, | ||
source: Any, | ||
info: Any, | ||
kwargs: Dict[str, Any], | ||
) -> Tuple[List[Any], Dict[str, Any]]: | ||
if field.base_resolver is None: | ||
return [], {} | ||
|
||
kwargs = convert_arguments(kwargs, field.arguments) | ||
|
||
# the following code allows to omit info and root arguments | ||
# by inspecting the original resolver arguments, | ||
# if it asks for self, the source will be passed as first argument | ||
# if it asks for root, the source it will be passed as kwarg | ||
# if it asks for info, the info will be passed as kwarg | ||
|
||
args = [] | ||
|
||
if field.base_resolver.has_self_arg: | ||
args.append(source) | ||
|
||
if field.base_resolver.has_root_arg: | ||
kwargs["root"] = source | ||
|
||
if field.base_resolver.has_info_arg: | ||
kwargs["info"] = info | ||
|
||
return args, kwargs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this method be embedded in from_resolver
with the other functions? It doesn't need any state on the class and is only consumed by that one method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that from_resolver
is getting quite long, but I still think that would be cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, can do :)
source: Any, | ||
info: Any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do source
and info
have known types now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
info yes, source depends on the resolver, so I think any is good :)
Description
This PR moves where we create our custom resolver for fields. Our custom logic resolver
is pretty much tied to GraphQL core and the schema. So it makes sense to move it there,
it will also help with the auto_camel_case changes, as we need to know if we have auto
camel casing on when fetching the arguments.
Types of Changes