Skip to content

Commit c81b0df

Browse files
committed
fix lost lines in merge
1 parent 45acfe3 commit c81b0df

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

graphene_mongo/types.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from graphene.types.utils import yank_fields_from_attrs
1010
from graphene.utils.str_converters import to_snake_case
1111

12+
from graphene_mongo import MongoengineConnectionField
1213
from .converter import convert_mongoengine_field
1314
from .registry import Registry, get_global_registry, get_inputs_registry
1415
from .utils import get_model_fields, is_valid_mongoengine_model, get_query_fields
@@ -128,22 +129,29 @@ def __init_subclass_with_meta__(
128129
use_connection = any(
129130
(issubclass(interface, Node) for interface in interfaces)
130131
)
131-
mongoengine_fields = yank_fields_from_attrs(
132-
converted_fields, _as=graphene.Field
133-
)
134-
if use_connection is None and interfaces:
135-
use_connection = any(
136-
(issubclass(interface, Node) for interface in interfaces)
137-
)
138132

139-
if use_connection and not connection:
140-
# We create the connection automatically
141-
if not connection_class:
142-
connection_class = Connection
133+
if use_connection and not connection:
134+
# We create the connection automatically
135+
if not connection_class:
136+
connection_class = Connection
143137

144-
connection = connection_class.create_type(
145-
"{}Connection".format(cls.__name__), node=cls
146-
)
138+
connection = connection_class.create_type(
139+
"{}Connection".format(cls.__name__), node=cls
140+
)
141+
142+
if connection is not None:
143+
assert issubclass(connection, Connection), (
144+
"The attribute connection in {}.Meta must be of type Connection. "
145+
'Received "{}" instead.'
146+
).format(cls.__name__, type(connection))
147+
148+
if connection_field_class is not None:
149+
assert issubclass(connection_field_class, graphene.ConnectionField), (
150+
"The attribute connection_field_class in {}.Meta must be of type graphene.ConnectionField. "
151+
'Received "{}" instead.'
152+
).format(cls.__name__, type(connection_field_class))
153+
else:
154+
connection_field_class = MongoengineConnectionField
147155

148156
if _meta:
149157
assert isinstance(_meta, MongoengineGenericObjectTypeOptions), (
@@ -176,7 +184,12 @@ def __init_subclass_with_meta__(
176184
converted_fields = construct_self_referenced_fields(
177185
self_referenced, registry
178186
)
179-
187+
if converted_fields:
188+
mongoengine_fields = yank_fields_from_attrs(
189+
converted_fields, _as=graphene.Field
190+
)
191+
cls._meta.fields.update(mongoengine_fields)
192+
registry.register(cls)
180193
@classmethod
181194
def rescan_fields(cls):
182195
"""Attempts to rescan fields and will insert any not converted initially"""

0 commit comments

Comments
 (0)