55from graphql .error import INVALID
66from graphql .type import (
77 GraphQLArgument ,
8+ GraphQLEnumValue ,
9+ GraphQLEnumType ,
810 GraphQLField ,
911 GraphQLFieldResolver ,
12+ GraphQLInputField ,
13+ GraphQLInputObjectType ,
1014 GraphQLInt ,
11- GraphQLString ,
12- GraphQLObjectType ,
15+ GraphQLInterfaceType ,
1316 GraphQLList ,
17+ GraphQLNonNull ,
18+ GraphQLObjectType ,
19+ GraphQLOutputType ,
1420 GraphQLScalarType ,
15- GraphQLInterfaceType ,
16- GraphQLUnionType ,
17- GraphQLEnumType ,
18- GraphQLEnumValue ,
19- GraphQLInputObjectType ,
2021 GraphQLSchema ,
21- GraphQLOutputType ,
22- GraphQLInputField ,
23- GraphQLNonNull ,
22+ GraphQLString ,
23+ GraphQLUnionType ,
2424)
2525
2626ObjectType = GraphQLObjectType ("Object" , {})
2929EnumType = GraphQLEnumType ("Enum" , {"foo" : GraphQLEnumValue ()})
3030InputObjectType = GraphQLInputObjectType ("InputObject" , {})
3131ScalarType = GraphQLScalarType ("Scalar" , serialize = lambda : None )
32+ NonNullScalarType = GraphQLNonNull (ScalarType )
33+ ListOfScalarsType = GraphQLList (ScalarType )
34+ NonNullListOfScalars = GraphQLNonNull (ListOfScalarsType )
35+ ListOfNonNullScalarsType = GraphQLList (NonNullScalarType )
3236
3337
3438def schema_with_field_type (type_ : GraphQLOutputType ) -> GraphQLSchema :
@@ -100,19 +104,20 @@ def stringifies_simple_types():
100104 assert str (UnionType ) == "Union"
101105 assert str (EnumType ) == "Enum"
102106 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]]"
108113
109114 def prohibits_nesting_nonnull_inside_nonnull ():
110115 with raises (TypeError ) as exc_info :
111116 # noinspection PyTypeChecker
112- GraphQLNonNull (GraphQLNonNull (GraphQLInt ))
117+ GraphQLNonNull (GraphQLNonNull (NonNullScalarType ))
113118 msg = str (exc_info .value )
114119 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 !."
116121 )
117122
118123 def allows_a_thunk_for_union_member_types ():
@@ -622,15 +627,14 @@ def does_not_allow_is_deprecated():
622627def describe_type_system_list_must_accept_only_types ():
623628
624629 types = [
625- GraphQLString ,
626630 ScalarType ,
627631 ObjectType ,
628632 UnionType ,
629633 InterfaceType ,
630634 EnumType ,
631635 InputObjectType ,
632- GraphQLList ( GraphQLString ) ,
633- GraphQLNonNull ( GraphQLString ) ,
636+ ListOfScalarsType ,
637+ NonNullScalarType ,
634638 ]
635639
636640 not_types = [{}, dict , str , object , None ]
@@ -642,7 +646,7 @@ def accepts_a_type_as_item_type_of_list(type_):
642646 @mark .parametrize ("type_" , not_types , ids = lambda type_ : type_ .__class__ .__name__ )
643647 def rejects_a_non_type_as_item_type_of_list (type_ ):
644648 with raises (TypeError ) as exc_info :
645- assert GraphQLList (type_ )
649+ GraphQLList (type_ )
646650 msg = str (exc_info .value )
647651 assert msg == (
648652 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_):
652656def describe_type_system_non_null_must_only_accept_non_nullable_types ():
653657
654658 nullable_types = [
655- GraphQLString ,
656659 ScalarType ,
657660 ObjectType ,
658661 UnionType ,
659662 InterfaceType ,
660663 EnumType ,
661664 InputObjectType ,
662- GraphQLList ( GraphQLString ) ,
663- GraphQLList ( GraphQLNonNull ( GraphQLString )) ,
665+ ListOfScalarsType ,
666+ ListOfNonNullScalarsType ,
664667 ]
665668
666- not_nullable_types = [GraphQLNonNull ( GraphQLString ) , {}, dict , str , object , None ]
669+ not_nullable_types = [NonNullScalarType , {}, dict , str , object , None ]
667670
668671 @mark .parametrize ("type_" , nullable_types )
669672 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_):
672675 @mark .parametrize ("type_" , not_nullable_types )
673676 def rejects_a_non_type_as_nullable_type_of_non_null (type_ ):
674677 with raises (TypeError ) as exc_info :
675- assert GraphQLNonNull (type_ )
678+ GraphQLNonNull (type_ )
676679 msg = str (exc_info .value )
677680 assert (
678681 msg
0 commit comments