File tree Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Original file line number Diff line number Diff line change 1
1
import mongoengine
2
+ import uuid
2
3
from graphene import (
3
4
ID ,
4
5
Boolean ,
23
24
24
25
singledispatch = import_single_dispatch ()
25
26
26
- _union_registry = {}
27
-
28
27
29
28
class MongoEngineConversionError (Exception ):
30
29
pass
@@ -126,18 +125,21 @@ def convert_field_to_union(field, registry=None):
126
125
if _type :
127
126
_types .append (_type .type )
128
127
else :
129
- # Can register type auto-matically here.
128
+ # TODO: Register type auto-matically here.
130
129
pass
131
130
132
131
if len (_types ) == 0 :
133
132
return None
134
133
135
- print ('*' * 50 )
136
- print (field .__dict__ )
137
- name = field ._owner_document .__name__ + '_' + field .db_field + '_union'
134
+ # XXX: Use uuid to avoid duplicate name
135
+ name = '{}_{}_union_{}' .format (
136
+ field ._owner_document .__name__ ,
137
+ field .db_field ,
138
+ str (uuid .uuid1 ()).replace ('-' , '' )
139
+ )
138
140
Meta = type ('Meta' , (object , ), {'types' : tuple (_types )})
139
- _union_registry [ name ] = type (name , (Union , ), {'Meta' : Meta })
140
- return Field (_union_registry . get ( name ) )
141
+ _union = type (name , (Union , ), {'Meta' : Meta })
142
+ return Field (_union )
141
143
142
144
143
145
@convert_mongoengine_field .register (mongoengine .EmbeddedDocumentField )
Original file line number Diff line number Diff line change 1
1
import graphene
2
2
from graphene .relay import Node
3
3
4
- from . import models , types
4
+ from . import models
5
+ from . import types # noqa: F401
5
6
from ..types import MongoengineObjectType
6
7
7
8
Original file line number Diff line number Diff line change 2
2
import mongoengine
3
3
4
4
from collections import OrderedDict
5
- from graphene .relay import Connection , Node , is_node
5
+ from graphene .relay import Connection , Node
6
6
from graphene .types .objecttype import ObjectType , ObjectTypeOptions
7
7
from graphene .types .utils import yank_fields_from_attrs
8
8
13
13
14
14
15
15
def construct_fields (model , registry , only_fields , exclude_fields ):
16
+ """
17
+ Args:
18
+ model (mongoengine.Document):
19
+ registry (graphene_mongo.registry.Registry):
20
+ only_fields ([str]):
21
+ exclude_fields ([str]):
22
+
23
+ Returns:
24
+ (OrderedDict, OrderedDict): coverted fields and self reference fields.
25
+
26
+ """
16
27
_model_fields = get_model_fields (model )
17
28
fields = OrderedDict ()
18
29
self_referenced = OrderedDict ()
You can’t perform that action at this time.
0 commit comments