mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Changed field attr naming from null to required
This commit is contained in:
parent
cf09066787
commit
948da46fcd
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user