graphql-python / graphql-python/graphene-mongo

Forced to use relay pagination on list of embedded documents?

Offen
#162 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
287
Forks
111
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
graphql, mongodb, python
Bereich
api, backend, database
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.