-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameters to toggle batching on or off. This can be configured at 2 levels: - we can configure all the fields of a type at once via SQLAlchemyObjectType.meta.batching - or we can specify it for a specific field via ORMfield.batching. This trumps SQLAlchemyObjectType.meta.batching.
- Loading branch information
Showing
6 changed files
with
325 additions
and
120 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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from graphene.utils.get_unbound_function import get_unbound_function | ||
|
||
|
||
def get_custom_resolver(obj_type, orm_field_name): | ||
""" | ||
Since `graphene` will call `resolve_<field_name>` on a field only if it | ||
does not have a `resolver`, we need to re-implement that logic here so | ||
users are able to override the default resolvers that we provide. | ||
""" | ||
resolver = getattr(obj_type, 'resolve_{}'.format(orm_field_name), None) | ||
if resolver: | ||
return get_unbound_function(resolver) | ||
|
||
return None | ||
|
||
|
||
def get_attr_resolver(obj_type, model_attr): | ||
""" | ||
In order to support field renaming via `ORMField.model_attr`, | ||
we need to define resolver functions for each field. | ||
:param SQLAlchemyObjectType obj_type: | ||
:param str model_attr: the name of the SQLAlchemy attribute | ||
:rtype: Callable | ||
""" | ||
return lambda root, _info: getattr(root, model_attr, None) |
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
Oops, something went wrong.