graphql-python / graphql-python/graphene-mongo

Forced to use relay pagination on list of embedded documents?

Open
#162 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
287
Forks
111
PR merge metrics
No merged PRs in 30d

Description

Suppose I have this document structure:

```python
class PersonModel(EmbeddedDocument):
name = StringField()

class HouseModel(Document):
people = ListField(EmbeddedDocumentField(PersonModel))
```

Then I define my MongoengineObjectTypes:

```python
class Person(MongoengineObjectType):
class Meta:
model = PersonModel
# no interface, since I want to access the people directly

class House(MongoengineObjectType):
class Meta:
model = HouseModel
interfaces = (Node,)
```

Then I build my schema:

```python
class Query(graphene.ObjectType):
node = Node.Field()
houses = MongoengineConnectionField(House)

schema = graphene.Schema(query=Query, types=[House, Person])
```

This spits out an unfriendly error:

```text
Traceback (most recent call last):
File "test.py", line 32, in
schema = graphene.Schema(query=Query, types=[House, Person])
File "%python39%\lib\site-packages\graphene\types\schema.py", line 78, in __init__
self.build_typemap()
File "%python39%\lib\site-packages\graphene\types\schema.py", line 167, in build_typemap
self._type_map = TypeMap(
File "%python39%\lib\site-packages\graphene\types\typemap.py", line 80, in __init__
super(TypeMap, self).__init__(types)
File "%python39%\lib\site-packages\graphql\type\typemap.py", line 31, in __init__
self.update(reduce(self.reducer, types, OrderedDict())) # type: ignore
File "%python39%\lib\site-packages\graphene\types\typemap.py", line 88, in reducer
return self.graphene_reducer(map, type)
File "%python39%\lib\site-packages\graphene\types\typemap.py", line 117, in graphene_reducer
return GraphQLTypeMap.reducer(map, internal_type)
File "%python39%\lib\site-packages\graphql\type\typemap.py", line 109, in reducer
field_map = type_.fields
File "%python39%\lib\site-packages\graphql\pyutils\cached_property.py", line 22, in __get__
value = obj.__dict__[self.func.__name__] = self.func(obj)
File "%python39%\lib\site-packages\graphql\type\definition.py", line 198, in fields
return define_field_map(self, self._fields)
File "%python39%\lib\site-packages\graphql\type\definition.py", line 212, in define_field_map
field_map = field_map()
File "%python39%\lib\site-packages\graphene\types\typemap.py", line 286, in construct_fields_for_type
for arg_name, arg in field.args.items():
File "%python39%\lib\site-packages\graphene_mongo\fields.py", line 68, in args
return to_arguments(
File "%python%\lib\site-packages\graphene\types\argument.py", line 80, in to_arguments
extra_args = sorted(extra_args.items(), key=lambda f: f[1])
TypeError: '<' not supported between instances of 'Person' and 'ID'
```

But if I add `interfaces = (Node,)` to the meta of `Person` the error goes away. However, I am also now forced to paginate through data which I know will also be only a small collection.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.