mirror of
https://github.com/graphql-python/graphene.git
synced 2025-03-05 04:15:47 +03:00
Added NonNull and List to Types
This commit is contained in:
parent
bf168e7b12
commit
1956c1fb03
|
@ -82,6 +82,16 @@ class MirroredType(OrderedType):
|
|||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
@property
|
||||
def List(self): # noqa
|
||||
from .definitions import List
|
||||
return List(self, *self.args, **self.kwargs)
|
||||
|
||||
@property
|
||||
def NonNull(self): # noqa
|
||||
from .definitions import NonNull
|
||||
return NonNull(self, *self.args, **self.kwargs)
|
||||
|
||||
|
||||
class ArgumentType(MirroredType):
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from graphene.core.exceptions import SkipField
|
|||
from graphene.core.options import Options
|
||||
from graphene.core.types.argument import ArgumentsGroup
|
||||
from graphene.core.types.base import BaseType
|
||||
from graphene.core.types.definitions import List, NonNull
|
||||
from graphql.core.type import (GraphQLArgument, GraphQLInputObjectType,
|
||||
GraphQLInterfaceType, GraphQLObjectType)
|
||||
|
||||
|
@ -99,6 +100,9 @@ class ObjectTypeMeta(type):
|
|||
new_class._meta.interfaces.append(base)
|
||||
# new_class._meta.parents.extend(base._meta.parents)
|
||||
|
||||
setattr(new_class, 'NonNull', NonNull(new_class))
|
||||
setattr(new_class, 'List', List(new_class))
|
||||
|
||||
new_class._prepare()
|
||||
return new_class
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from graphene.core.types import InputObjectType, ObjectType
|
|||
from ..argument import Argument
|
||||
from ..base import MountedType, OrderedType
|
||||
from ..field import Field, InputField
|
||||
from ..definitions import List, NonNull
|
||||
|
||||
|
||||
def test_orderedtype_equal():
|
||||
|
@ -71,3 +72,23 @@ def test_type_as_argument():
|
|||
a = MountedType(description='A')
|
||||
argument = a.as_argument()
|
||||
assert isinstance(argument, Argument)
|
||||
|
||||
|
||||
def test_type_as_list():
|
||||
m = MountedType(2, 3, my_c='A')
|
||||
a = m.List
|
||||
|
||||
assert isinstance(a, List)
|
||||
assert a.of_type == m
|
||||
assert a.args == (2, 3)
|
||||
assert a.kwargs == {'my_c': 'A'}
|
||||
|
||||
|
||||
def test_type_as_nonnull():
|
||||
m = MountedType(2, 3, my_c='A')
|
||||
a = m.NonNull
|
||||
|
||||
assert isinstance(a, NonNull)
|
||||
assert a.of_type == m
|
||||
assert a.args == (2, 3)
|
||||
assert a.kwargs == {'my_c': 'A'}
|
||||
|
|
|
@ -112,3 +112,17 @@ def test_field_mantain_resolver_tags():
|
|||
|
||||
field = schema.T(Droid._meta.fields_map['name'])
|
||||
assert resolver_has_tag(field.resolver, 'test')
|
||||
|
||||
|
||||
def test_type_has_nonnull():
|
||||
class Droid(Character):
|
||||
name = String()
|
||||
|
||||
assert Droid.NonNull.of_type == Droid
|
||||
|
||||
|
||||
def test_type_has_list():
|
||||
class Droid(Character):
|
||||
name = String()
|
||||
|
||||
assert Droid.List.of_type == Droid
|
||||
|
|
Loading…
Reference in New Issue
Block a user