File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -295,7 +295,11 @@ def __getattr__(self, name: str) -> "DSLType":
295
295
if type_def is None :
296
296
raise AttributeError (f"Type '{ name } ' not found in the schema!" )
297
297
298
- assert isinstance (type_def , (GraphQLObjectType , GraphQLInterfaceType ))
298
+ if not isinstance (type_def , (GraphQLObjectType , GraphQLInterfaceType )):
299
+ raise AttributeError (
300
+ f'Type "{ name } ({ type_def !r} )" is not valid as an attribute of'
301
+ " DSLSchema. Only Object types or Interface types are accepted."
302
+ )
299
303
300
304
return DSLType (type_def , self )
301
305
Original file line number Diff line number Diff line change 14
14
NonNullTypeNode ,
15
15
NullValueNode ,
16
16
Undefined ,
17
+ build_ast_schema ,
18
+ parse ,
17
19
print_ast ,
18
20
)
19
21
from graphql .utilities import get_introspection_query
@@ -774,8 +776,6 @@ def test_dsl_query_all_fields_should_correspond_to_the_root_type(ds):
774
776
775
777
def test_dsl_root_type_not_default ():
776
778
777
- from graphql import parse , build_ast_schema
778
-
779
779
schema_str = """
780
780
schema {
781
781
query: QueryNotDefault
@@ -827,6 +827,41 @@ def test_invalid_type(ds):
827
827
ds .invalid_type
828
828
829
829
830
+ def test_invalid_type_union ():
831
+ schema_str = """
832
+ type FloatValue {
833
+ floatValue: Float!
834
+ }
835
+
836
+ type IntValue {
837
+ intValue: Int!
838
+ }
839
+
840
+ union Value = FloatValue | IntValue
841
+
842
+ type Entry {
843
+ name: String!
844
+ value: Value
845
+ }
846
+
847
+ type Query {
848
+ values: [Entry!]!
849
+ }
850
+ """
851
+
852
+ schema = build_ast_schema (parse (schema_str ))
853
+ ds = DSLSchema (schema )
854
+
855
+ with pytest .raises (
856
+ AttributeError ,
857
+ match = (
858
+ "Type \" Value \\ (<GraphQLUnionType 'Value'>\\ )\" is not valid as an "
859
+ "attribute of DSLSchema. Only Object types or Interface types are accepted."
860
+ ),
861
+ ):
862
+ ds .Value
863
+
864
+
830
865
def test_hero_name_query_with_typename (ds ):
831
866
query = """
832
867
hero {
You can’t perform that action at this time.
0 commit comments