|
18 | 18 | from mongoengine.base import get_document
|
19 | 19 |
|
20 | 20 | from . import advanced_types
|
| 21 | +from .registry import get_global_registry |
21 | 22 | from .utils import (
|
22 | 23 | import_single_dispatch, get_field_description,
|
23 |
| - ClassFactory, add_method, |
24 | 24 | )
|
25 | 25 |
|
26 | 26 | singledispatch = import_single_dispatch()
|
@@ -117,35 +117,21 @@ def convert_field_to_list(field, registry=None):
|
117 | 117 |
|
118 | 118 | @convert_mongoengine_field.register(mongoengine.GenericReferenceField)
|
119 | 119 | def convert_field_to_union(field, registry=None):
|
120 |
| - # pass |
121 |
| - # print(field.__dict__) |
122 |
| - # print(type(field.choices[0])) |
123 |
| - # print(get_document(field.choices[0])) |
124 |
| - from graphene_mongo import MongoengineObjectType |
125 |
| - from .registry import Registry, get_global_registry |
| 120 | + |
126 | 121 | _types = []
|
127 | 122 | for choice in field.choices:
|
128 |
| - model = get_document(choice) |
129 |
| - # cls = ClassFactory(choice, BaseClass=MongoengineObjectType) |
130 |
| - # Meta = ClassFactory('Meta', argnames={'model': model}) |
131 |
| - # t = add_method(type(choice + 'Type', {'Meta': Meta}, cls)) |
132 |
| - # print(t) |
133 |
| - # Meta = type('Meta', (object, ), {'model': model}) |
134 |
| - # class Meta: |
135 |
| - # model = get_document(choice) |
136 |
| - ## print(Meta.__dict__) |
137 |
| - """ |
138 |
| - class Q(MongoengineObjectType): |
139 |
| - class Meta: |
140 |
| - model = get_document(choice) |
141 |
| - """ |
142 |
| - # cls = ClassFactory(choice + 'Type', BaseClass=MongoengineObjectType, Meta=Meta) |
143 |
| - # cls = type(choice + 'Type', (MongoengineObjectType, ), {'Meta': Meta}) |
144 |
| - # _types.append(cls) |
145 | 123 | field = fields.ReferenceField(get_document(choice))
|
146 | 124 | _field = convert_mongoengine_field(field, get_global_registry())
|
147 | 125 | _type = _field.get_type()
|
148 |
| - _types.append(_type.type) |
| 126 | + if _type: |
| 127 | + _types.append(_type.type) |
| 128 | + else: |
| 129 | + # Can register type auto-matically here. |
| 130 | + pass |
| 131 | + |
| 132 | + if len(_types) == 0: |
| 133 | + return None |
| 134 | + |
149 | 135 | class U(Union):
|
150 | 136 | class Meta:
|
151 | 137 | types = tuple(_types)
|
|
0 commit comments