mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-29 04:53:43 +03:00
Enforce NonNull for returned related Sets and their content (#690)
* Enforce NonNull for returned related Sets and their content. https://github.com/graphql-python/graphene-django/issues/448 * Run format. * Remove duplicate assertion
This commit is contained in:
parent
e2e496f505
commit
54cc6a4b13
|
@ -198,7 +198,11 @@ def convert_field_to_list_or_connection(field, registry=None):
|
||||||
|
|
||||||
return DjangoConnectionField(_type, description=description)
|
return DjangoConnectionField(_type, description=description)
|
||||||
|
|
||||||
return DjangoListField(_type, description=description)
|
return DjangoListField(
|
||||||
|
_type,
|
||||||
|
required=True, # A Set is always returned, never None.
|
||||||
|
description=description,
|
||||||
|
)
|
||||||
|
|
||||||
return Dynamic(dynamic_type)
|
return Dynamic(dynamic_type)
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ from .utils import maybe_queryset
|
||||||
|
|
||||||
class DjangoListField(Field):
|
class DjangoListField(Field):
|
||||||
def __init__(self, _type, *args, **kwargs):
|
def __init__(self, _type, *args, **kwargs):
|
||||||
super(DjangoListField, self).__init__(List(_type), *args, **kwargs)
|
# Django would never return a Set of None vvvvvvv
|
||||||
|
super(DjangoListField, self).__init__(List(NonNull(_type)), *args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def model(self):
|
def model(self):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from graphene import NonNull
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
@ -234,8 +235,12 @@ def test_should_manytomany_convert_connectionorlist_list():
|
||||||
assert isinstance(graphene_field, graphene.Dynamic)
|
assert isinstance(graphene_field, graphene.Dynamic)
|
||||||
dynamic_field = graphene_field.get_type()
|
dynamic_field = graphene_field.get_type()
|
||||||
assert isinstance(dynamic_field, graphene.Field)
|
assert isinstance(dynamic_field, graphene.Field)
|
||||||
assert isinstance(dynamic_field.type, graphene.List)
|
# A NonNull List of NonNull A ([A!]!)
|
||||||
assert dynamic_field.type.of_type == A
|
# https://github.com/graphql-python/graphene-django/issues/448
|
||||||
|
assert isinstance(dynamic_field.type, NonNull)
|
||||||
|
assert isinstance(dynamic_field.type.of_type, graphene.List)
|
||||||
|
assert isinstance(dynamic_field.type.of_type.of_type, NonNull)
|
||||||
|
assert dynamic_field.type.of_type.of_type.of_type == A
|
||||||
|
|
||||||
|
|
||||||
def test_should_manytomany_convert_connectionorlist_connection():
|
def test_should_manytomany_convert_connectionorlist_connection():
|
||||||
|
@ -262,8 +267,11 @@ def test_should_manytoone_convert_connectionorlist():
|
||||||
assert isinstance(graphene_field, graphene.Dynamic)
|
assert isinstance(graphene_field, graphene.Dynamic)
|
||||||
dynamic_field = graphene_field.get_type()
|
dynamic_field = graphene_field.get_type()
|
||||||
assert isinstance(dynamic_field, graphene.Field)
|
assert isinstance(dynamic_field, graphene.Field)
|
||||||
assert isinstance(dynamic_field.type, graphene.List)
|
# a NonNull List of NonNull A ([A!]!)
|
||||||
assert dynamic_field.type.of_type == A
|
assert isinstance(dynamic_field.type, NonNull)
|
||||||
|
assert isinstance(dynamic_field.type.of_type, graphene.List)
|
||||||
|
assert isinstance(dynamic_field.type.of_type.of_type, NonNull)
|
||||||
|
assert dynamic_field.type.of_type.of_type.of_type == A
|
||||||
|
|
||||||
|
|
||||||
def test_should_onetoone_reverse_convert_model():
|
def test_should_onetoone_reverse_convert_model():
|
||||||
|
|
|
@ -170,7 +170,7 @@ type Reporter {
|
||||||
firstName: String!
|
firstName: String!
|
||||||
lastName: String!
|
lastName: String!
|
||||||
email: String!
|
email: String!
|
||||||
pets: [Reporter]
|
pets: [Reporter!]!
|
||||||
aChoice: ReporterAChoice!
|
aChoice: ReporterAChoice!
|
||||||
reporterType: ReporterReporterType
|
reporterType: ReporterReporterType
|
||||||
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
|
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
|
||||||
|
|
Loading…
Reference in New Issue
Block a user