Skip to content

Make relationship arrays nonnull and required #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy.orm import interfaces

from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List,
String)
NonNull, String)
from graphene.types.json import JSONString

from .enums import enum_for_sa_enum
Expand Down Expand Up @@ -46,7 +46,8 @@ def dynamic_type():
# TODO Add a way to override connection_field_factory
return connection_field_factory(relationship_prop, registry, **field_kwargs)
return Field(
List(_type),
List(NonNull(_type)),
required=True,
**field_kwargs
)

Expand Down
8 changes: 6 additions & 2 deletions graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ class Meta:
assert isinstance(dynamic_field, graphene.Dynamic)
graphene_type = dynamic_field.get_type()
assert isinstance(graphene_type, graphene.Field)
assert isinstance(graphene_type.type, graphene.List)
assert graphene_type.type.of_type == A
assert isinstance(graphene_type.type, graphene.NonNull)
list_type = graphene_type.type.of_type
assert isinstance(list_type, graphene.List)
list_element_type = list_type.of_type
assert isinstance(list_element_type, graphene.NonNull)
assert list_element_type.of_type == A


def test_should_manytomany_convert_connectionorlist_connection():
Expand Down
8 changes: 6 additions & 2 deletions graphene_sqlalchemy/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ class Meta:

pets_field = ReporterType._meta.fields['pets']
assert isinstance(pets_field, Dynamic)
assert isinstance(pets_field.type().type, List)
assert pets_field.type().type.of_type == PetType
assert isinstance(pets_field.type().type, NonNull)
list_type = pets_field.type().type.of_type
assert isinstance(list_type, List)
list_element_type = list_type.of_type
assert isinstance(list_element_type, NonNull)
assert list_element_type.of_type == PetType
assert pets_field.type().description == 'Overridden'


Expand Down