This commit is contained in:
Mateusz Bocian 2017-11-15 06:29:07 +00:00 committed by GitHub
commit 7a2f420d2a
3 changed files with 24 additions and 3 deletions

View File

@ -82,7 +82,7 @@ def test_generate_objecttype_with_fields():
def test_generate_objecttype_with_private_attributes():
class MyObjectType(ObjectType):
_private_state = None
_private_state = Field(MyType)
assert '_private_state' not in MyObjectType._meta.fields
assert hasattr(MyObjectType, '_private_state')

View File

@ -297,6 +297,27 @@ def test_query_middlewares():
assert executed.data == {'hello': 'dlroW', 'other': 'rehto'}
def test_query_private_values():
class MyType(ObjectType):
_private = String()
public = String()
class Query(ObjectType):
field = Field(MyType)
hello_schema = Schema(Query)
executed = hello_schema.execute('{ field { Private } }')
assert executed.errors
executed = hello_schema.execute('{ field { _private } }')
assert executed.errors
executed = hello_schema.execute('{ field { public } }')
assert not executed.errors
assert executed.data == {'field': None}
def test_objecttype_on_instances():
class Ship:
@ -442,8 +463,6 @@ def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark
def test_query_annotated_resolvers():
import json
context = Context(key="context")
class Query(ObjectType):

View File

@ -28,6 +28,8 @@ def yank_fields_from_attrs(attrs, _as=None, sort=True):
'''
fields_with_names = []
for attname, value in list(attrs.items()):
if attname.startswith('_'):
continue
field = get_field_as(value, _as)
if not field:
continue