Changed field attr naming from null to required

This commit is contained in:
Syrus Akbary 2015-10-05 20:42:24 -07:00
parent cf09066787
commit 948da46fcd
5 changed files with 12 additions and 11 deletions

View File

@ -45,12 +45,12 @@ def _(field):
@convert_django_field.register(models.BooleanField)
def _(field):
return BooleanField(description=field.description, null=False)
return BooleanField(description=field.description, required=True)
@convert_django_field.register(models.NullBooleanField)
def _(field):
return BooleanField(description=field.description, null=True)
return BooleanField(description=field.description)
@convert_django_field.register(models.FloatField)

View File

@ -60,7 +60,7 @@ class GraphQLView(View):
try:
received_json_data = json.loads(request.body)
query = received_json_data.get('query')
except ValueError, e:
except ValueError:
return self.response_errors(ValueError("Malformed json body in the post data"))
else:
query = request.POST.get('query') or request.GET.get('query')

View File

@ -18,10 +18,10 @@ from graphene.core.scalars import GraphQLSkipField
class Field(object):
SKIP = GraphQLSkipField
def __init__(self, field_type, name=None, resolve=None, null=True, args=None, description='', **extra_args):
def __init__(self, field_type, name=None, resolve=None, required=False, args=None, description='', **extra_args):
self.field_type = field_type
self.resolve_fn = resolve
self.null = null
self.required = required
self.args = args or {}
self.extra_args = extra_args
self._type = None
@ -60,7 +60,7 @@ class Field(object):
return schema.get_type(field_type)
def type_wrapper(self, field_type):
if not self.null:
if self.required:
field_type = GraphQLNonNull(field_type)
return field_type

View File

@ -76,12 +76,13 @@ def test_should_integer_convert_int():
def test_should_boolean_convert_boolean():
assert_conversion(models.BooleanField, graphene.BooleanField)
field = assert_conversion(models.BooleanField, graphene.BooleanField)
assert field.required is True
def test_should_nullboolean_convert_boolean():
field = assert_conversion(models.NullBooleanField, graphene.BooleanField)
assert field.null is True
assert field.required is False
def test_should_float_convert_float():

View File

@ -69,15 +69,15 @@ def test_stringfield_type():
assert f.internal_type(schema) == GraphQLString
def test_stringfield_type_null():
f = StringField(null=False)
def test_stringfield_type_required():
f = StringField(required=True)
f.contribute_to_class(ot, 'field_name')
assert isinstance(f.internal_field(schema), GraphQLField)
assert isinstance(f.internal_type(schema), GraphQLNonNull)
def test_field_resolve():
f = StringField(null=False, resolve=lambda *args: 'RESOLVED')
f = StringField(required=True, resolve=lambda *args: 'RESOLVED')
f.contribute_to_class(ot, 'field_name')
field_type = f.internal_field(schema)
assert 'RESOLVED' == field_type.resolver(ot, 2, 3)