Skip to content

Commit

Permalink
Merge pull request #169 from arunsureshkumar/master
Browse files Browse the repository at this point in the history
Support added for Graphene Federation
  • Loading branch information
abawchen committed Apr 8, 2021
2 parents 97266e6 + e44c660 commit 3ef74bc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions graphene_mongo/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def __init__(self, type, *args, **kwargs):

@property
def type(self):
from .types import GrapheneMongoengineObjectTypes
from .types import MongoengineObjectType

_type = super(ConnectionField, self).type
assert issubclass(
_type, GrapheneMongoengineObjectTypes
), "MongoengineConnectionField only accepts Mongoengine object types"
_type, MongoengineObjectType
), "MongoengineConnectionField only accepts MongoengineObjectType types"
assert _type._meta.connection, "The type {} doesn't have a connection".format(
_type.__name__
)
Expand Down Expand Up @@ -79,7 +79,7 @@ def registry(self):
def args(self):
return to_arguments(
self._base_args or OrderedDict(),
dict(dict(self.field_args, **self.advance_args), **self.filter_args),
dict(dict(dict(self.field_args, **self.advance_args), **self.filter_args), **self.extended_args),
)

@args.setter
Expand All @@ -96,7 +96,8 @@ def is_filterable(k):
Returns:
bool
"""

if hasattr(self.fields[k].type, '_sdl'):
return False
if not hasattr(self.model, k):
return False
if isinstance(getattr(self.model, k), property):
Expand Down Expand Up @@ -201,6 +202,14 @@ def get_advance_field(r, kv):

return reduce(get_advance_field, self.fields.items(), {})

@property
def extended_args(self):
args = OrderedDict()
for k, each in self.fields.items():
if hasattr(each.type, '_sdl'):
args.update({k: graphene.ID()})
return args

@property
def fields(self):
self._type = get_type(self._type)
Expand Down Expand Up @@ -394,9 +403,6 @@ def chained_resolver(self, resolver, is_partial, root, info, **args):
self.filter_args.keys()):
args_copy.pop(arg_name)
if arg_name == '_id' and isinstance(arg, dict):
args_copy['pk__in'] = arg['$in']
elif "$ne" in arg:
args_copy['pk__ne'] = arg['$ne']
operation = list(arg.keys())[0]
args_copy['pk' + operation.replace('$', '__')] = arg[operation]
if '.' in arg_name:
Expand Down

0 comments on commit 3ef74bc

Please sign in to comment.