Skip to content

Commit 70414b7

Browse files
committed
test: Make test_relay_query work
1 parent 12559fd commit 70414b7

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

graphene_mongo/advanced_types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import graphene
22

33

4+
__all__ = [
5+
'PointFieldType'
6+
]
7+
8+
49
def _resolve_point_type_coordinates(self, info):
510
return self['coordinates']
611

712

8-
class PointType(graphene.ObjectType):
13+
class PointFieldType(graphene.ObjectType):
914

1015
type = graphene.String()
1116
coordinates = graphene.List(

graphene_mongo/converter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
Int,
99
List,
1010
NonNull,
11-
ObjectType,
1211
String,
1312
is_node
1413
)
1514
from graphene.types.json import JSONString
1615

1716
import mongoengine
1817

19-
from .advanced_types import PointType
18+
from .advanced_types import PointFieldType
2019
from .fields import MongoengineConnectionField
2120
from .utils import import_single_dispatch
2221

@@ -68,7 +67,7 @@ def convert_dict_to_jsonstring(field, registry=None):
6867

6968
@convert_mongoengine_field.register(mongoengine.PointField)
7069
def convert_point_to_field(field, register=None):
71-
return Field(PointType)
70+
return Field(PointFieldType)
7271

7372

7473
@convert_mongoengine_field.register(mongoengine.DateTimeField)

graphene_mongo/fields.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from graphene.types.dynamic import Dynamic
1313
from graphene.types.structures import Structure
1414

15+
from .advanced_types import PointFieldType
1516
from .utils import get_model_reference_fields
1617

1718

@@ -55,7 +56,13 @@ def args(self, args):
5556

5657
def _field_args(self, items):
5758
def is_filterable(v):
58-
return not isinstance(v, (ConnectionField, Dynamic))
59+
if isinstance(v, (ConnectionField, Dynamic)):
60+
return False
61+
# FIXME: Skip PointTypeField at this moment.
62+
if not isinstance(v.type, Structure) \
63+
and isinstance(v.type(), PointFieldType):
64+
return False
65+
return True
5966

6067
def get_type(v):
6168
if isinstance(v.type, Structure):

graphene_mongo/tests/test_relay_query.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ class Query(graphene.ObjectType):
304304
bar,
305305
baz,
306306
loc {
307-
type
307+
type,
308+
coordinates
308309
}
309310
}
310311
}
@@ -318,26 +319,20 @@ class Query(graphene.ObjectType):
318319
'node': {
319320
'bar': 'bar',
320321
'baz': 'baz',
322+
'loc': {
323+
'type': 'Point',
324+
'coordinates': [10.0, 20.0]
325+
}
321326
}
322327
}
323328
]
324329
}
325330
}
326-
loc = {
327-
'type': 'Point',
328-
'coordinates': [10, 20]
329-
}
330-
loc_json_string = json.dumps(loc, sort_keys=True)
331331
schema = graphene.Schema(query=Query)
332-
333332
result = schema.execute(query)
334-
print(result.data)
335-
print(result.errors)
336-
# result_loc = json.loads(result.data['children']['edges'][0]['node'].pop('loc'))
337-
# assert not result.errors
338-
# assert json.dumps(result.data, sort_keys=True) == json.dumps(
339-
# expected, sort_keys=True)
340-
# assert json.dumps(result_loc, sort_keys=True) == loc_json_string
333+
assert not result.errors
334+
assert json.dumps(result.data, sort_keys=True) == json.dumps(
335+
expected, sort_keys=True)
341336

342337

343338
def test_should_get_node_by_id(fixtures):

graphene_mongo/types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .converter import convert_mongoengine_field
1010
from .registry import Registry, get_global_registry
1111
from .utils import (get_model_fields, is_valid_mongoengine_model)
12-
from .tests.models import Child
12+
1313

1414
def construct_fields(model, registry, only_fields, exclude_fields):
1515
_model_fields = get_model_fields(model)
@@ -35,9 +35,6 @@ def construct_fields(model, registry, only_fields, exclude_fields):
3535
continue
3636
fields[name] = converted
3737

38-
# print(model, model == Child)
39-
# if model == Child:
40-
# print(fields)
4138
return fields, self_referenced
4239

4340

0 commit comments

Comments
 (0)