5
5
from graphql .error import INVALID
6
6
from graphql .type import (
7
7
GraphQLArgument ,
8
+ GraphQLEnumValue ,
9
+ GraphQLEnumType ,
8
10
GraphQLField ,
9
11
GraphQLFieldResolver ,
12
+ GraphQLInputField ,
13
+ GraphQLInputObjectType ,
10
14
GraphQLInt ,
11
- GraphQLString ,
12
- GraphQLObjectType ,
15
+ GraphQLInterfaceType ,
13
16
GraphQLList ,
17
+ GraphQLNonNull ,
18
+ GraphQLObjectType ,
19
+ GraphQLOutputType ,
14
20
GraphQLScalarType ,
15
- GraphQLInterfaceType ,
16
- GraphQLUnionType ,
17
- GraphQLEnumType ,
18
- GraphQLEnumValue ,
19
- GraphQLInputObjectType ,
20
21
GraphQLSchema ,
21
- GraphQLOutputType ,
22
- GraphQLInputField ,
23
- GraphQLNonNull ,
22
+ GraphQLString ,
23
+ GraphQLUnionType ,
24
24
)
25
25
26
26
ObjectType = GraphQLObjectType ("Object" , {})
29
29
EnumType = GraphQLEnumType ("Enum" , {"foo" : GraphQLEnumValue ()})
30
30
InputObjectType = GraphQLInputObjectType ("InputObject" , {})
31
31
ScalarType = GraphQLScalarType ("Scalar" , serialize = lambda : None )
32
+ NonNullScalarType = GraphQLNonNull (ScalarType )
33
+ ListOfScalarsType = GraphQLList (ScalarType )
34
+ NonNullListOfScalars = GraphQLNonNull (ListOfScalarsType )
35
+ ListOfNonNullScalarsType = GraphQLList (NonNullScalarType )
32
36
33
37
34
38
def schema_with_field_type (type_ : GraphQLOutputType ) -> GraphQLSchema :
@@ -100,19 +104,20 @@ def stringifies_simple_types():
100
104
assert str (UnionType ) == "Union"
101
105
assert str (EnumType ) == "Enum"
102
106
assert str (InputObjectType ) == "InputObject"
103
- assert str (GraphQLNonNull (GraphQLInt )) == "Int!"
104
- assert str (GraphQLList (GraphQLInt )) == "[Int]"
105
- assert str (GraphQLNonNull (GraphQLList (GraphQLInt ))) == "[Int]!"
106
- assert str (GraphQLList (GraphQLNonNull (GraphQLInt ))) == "[Int!]"
107
- assert str (GraphQLList (GraphQLList (GraphQLInt ))) == "[[Int]]"
107
+
108
+ assert str (NonNullScalarType ) == "Scalar!"
109
+ assert str (ListOfScalarsType ) == "[Scalar]"
110
+ assert str (NonNullListOfScalars ) == "[Scalar]!"
111
+ assert str (ListOfNonNullScalarsType ) == "[Scalar!]"
112
+ assert str (GraphQLList (ListOfScalarsType )) == "[[Scalar]]"
108
113
109
114
def prohibits_nesting_nonnull_inside_nonnull ():
110
115
with raises (TypeError ) as exc_info :
111
116
# noinspection PyTypeChecker
112
- GraphQLNonNull (GraphQLNonNull (GraphQLInt ))
117
+ GraphQLNonNull (GraphQLNonNull (NonNullScalarType ))
113
118
msg = str (exc_info .value )
114
119
assert msg == (
115
- "Can only create NonNull of a Nullable GraphQLType but got: Int !."
120
+ "Can only create NonNull of a Nullable GraphQLType but got: Scalar !."
116
121
)
117
122
118
123
def allows_a_thunk_for_union_member_types ():
@@ -622,15 +627,14 @@ def does_not_allow_is_deprecated():
622
627
def describe_type_system_list_must_accept_only_types ():
623
628
624
629
types = [
625
- GraphQLString ,
626
630
ScalarType ,
627
631
ObjectType ,
628
632
UnionType ,
629
633
InterfaceType ,
630
634
EnumType ,
631
635
InputObjectType ,
632
- GraphQLList ( GraphQLString ) ,
633
- GraphQLNonNull ( GraphQLString ) ,
636
+ ListOfScalarsType ,
637
+ NonNullScalarType ,
634
638
]
635
639
636
640
not_types = [{}, dict , str , object , None ]
@@ -642,7 +646,7 @@ def accepts_a_type_as_item_type_of_list(type_):
642
646
@mark .parametrize ("type_" , not_types , ids = lambda type_ : type_ .__class__ .__name__ )
643
647
def rejects_a_non_type_as_item_type_of_list (type_ ):
644
648
with raises (TypeError ) as exc_info :
645
- assert GraphQLList (type_ )
649
+ GraphQLList (type_ )
646
650
msg = str (exc_info .value )
647
651
assert msg == (
648
652
f"Can only create a wrapper for a GraphQLType, but got: { type_ } ."
@@ -652,18 +656,17 @@ def rejects_a_non_type_as_item_type_of_list(type_):
652
656
def describe_type_system_non_null_must_only_accept_non_nullable_types ():
653
657
654
658
nullable_types = [
655
- GraphQLString ,
656
659
ScalarType ,
657
660
ObjectType ,
658
661
UnionType ,
659
662
InterfaceType ,
660
663
EnumType ,
661
664
InputObjectType ,
662
- GraphQLList ( GraphQLString ) ,
663
- GraphQLList ( GraphQLNonNull ( GraphQLString )) ,
665
+ ListOfScalarsType ,
666
+ ListOfNonNullScalarsType ,
664
667
]
665
668
666
- not_nullable_types = [GraphQLNonNull ( GraphQLString ) , {}, dict , str , object , None ]
669
+ not_nullable_types = [NonNullScalarType , {}, dict , str , object , None ]
667
670
668
671
@mark .parametrize ("type_" , nullable_types )
669
672
def accepts_a_type_as_nullable_type_of_non_null (type_ ):
@@ -672,7 +675,7 @@ def accepts_a_type_as_nullable_type_of_non_null(type_):
672
675
@mark .parametrize ("type_" , not_nullable_types )
673
676
def rejects_a_non_type_as_nullable_type_of_non_null (type_ ):
674
677
with raises (TypeError ) as exc_info :
675
- assert GraphQLNonNull (type_ )
678
+ GraphQLNonNull (type_ )
676
679
msg = str (exc_info .value )
677
680
assert (
678
681
msg
0 commit comments