graphql-python / graphql-python/graphene-mongo
Forced to use relay pagination on list of embedded documents?
- Lingua principale
- Python
- Stelle
- 287
- Fork
- 111
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Reproduce the schema setup from test.py and start in graphene_mongo/fields.py, where the connection field arguments reach Graphene's argument sorting. Check how an embedded Person type without Node triggers the TypeError, then verify that schema construction succeeds while the embedded people list remains directly accessible without forced connection pagination.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- graphql, mongodb, python
- Ambito
- api, backend, database
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100