Skip to content

Commit

Permalink
test: Make test_relay_query work
Browse files Browse the repository at this point in the history
  • Loading branch information
abawchen committed Jan 17, 2019
1 parent 12559fd commit 70414b7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
7 changes: 6 additions & 1 deletion graphene_mongo/advanced_types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import graphene


__all__ = [
'PointFieldType'
]


def _resolve_point_type_coordinates(self, info):
return self['coordinates']


class PointType(graphene.ObjectType):
class PointFieldType(graphene.ObjectType):

type = graphene.String()
coordinates = graphene.List(
Expand Down
5 changes: 2 additions & 3 deletions graphene_mongo/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
Int,
List,
NonNull,
ObjectType,
String,
is_node
)
from graphene.types.json import JSONString

import mongoengine

from .advanced_types import PointType
from .advanced_types import PointFieldType
from .fields import MongoengineConnectionField
from .utils import import_single_dispatch

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

@convert_mongoengine_field.register(mongoengine.PointField)
def convert_point_to_field(field, register=None):
return Field(PointType)
return Field(PointFieldType)


@convert_mongoengine_field.register(mongoengine.DateTimeField)
Expand Down
9 changes: 8 additions & 1 deletion graphene_mongo/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from graphene.types.dynamic import Dynamic
from graphene.types.structures import Structure

from .advanced_types import PointFieldType
from .utils import get_model_reference_fields


Expand Down Expand Up @@ -55,7 +56,13 @@ def args(self, args):

def _field_args(self, items):
def is_filterable(v):
return not isinstance(v, (ConnectionField, Dynamic))
if isinstance(v, (ConnectionField, Dynamic)):
return False
# FIXME: Skip PointTypeField at this moment.
if not isinstance(v.type, Structure) \
and isinstance(v.type(), PointFieldType):
return False
return True

def get_type(v):
if isinstance(v.type, Structure):
Expand Down
23 changes: 9 additions & 14 deletions graphene_mongo/tests/test_relay_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ class Query(graphene.ObjectType):
bar,
baz,
loc {
type
type,
coordinates
}
}
}
Expand All @@ -318,26 +319,20 @@ class Query(graphene.ObjectType):
'node': {
'bar': 'bar',
'baz': 'baz',
'loc': {
'type': 'Point',
'coordinates': [10.0, 20.0]
}
}
}
]
}
}
loc = {
'type': 'Point',
'coordinates': [10, 20]
}
loc_json_string = json.dumps(loc, sort_keys=True)
schema = graphene.Schema(query=Query)

result = schema.execute(query)
print(result.data)
print(result.errors)
# result_loc = json.loads(result.data['children']['edges'][0]['node'].pop('loc'))
# assert not result.errors
# assert json.dumps(result.data, sort_keys=True) == json.dumps(
# expected, sort_keys=True)
# assert json.dumps(result_loc, sort_keys=True) == loc_json_string
assert not result.errors
assert json.dumps(result.data, sort_keys=True) == json.dumps(
expected, sort_keys=True)


def test_should_get_node_by_id(fixtures):
Expand Down
5 changes: 1 addition & 4 deletions graphene_mongo/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .converter import convert_mongoengine_field
from .registry import Registry, get_global_registry
from .utils import (get_model_fields, is_valid_mongoengine_model)
from .tests.models import Child


def construct_fields(model, registry, only_fields, exclude_fields):
_model_fields = get_model_fields(model)
Expand All @@ -35,9 +35,6 @@ def construct_fields(model, registry, only_fields, exclude_fields):
continue
fields[name] = converted

# print(model, model == Child)
# if model == Child:
# print(fields)
return fields, self_referenced


Expand Down

0 comments on commit 70414b7

Please sign in to comment.