@@ -103,33 +103,22 @@ def report_error(
103
103
104
104
def validate_root_types (self ) -> None :
105
105
schema = self .schema
106
- query_type = schema .query_type
107
- if not query_type :
106
+ if not schema .query_type :
108
107
self .report_error ("Query root type must be provided." , schema .ast_node )
109
- elif not is_object_type (query_type ):
110
- self .report_error (
111
- f"Query root type must be Object type, it cannot be { query_type } ." ,
112
- get_operation_type_node (schema , OperationType .QUERY )
113
- or query_type .ast_node ,
114
- )
115
-
116
- mutation_type = schema .mutation_type
117
- if mutation_type and not is_object_type (mutation_type ):
118
- self .report_error (
119
- "Mutation root type must be Object type if provided,"
120
- f" it cannot be { mutation_type } ." ,
121
- get_operation_type_node (schema , OperationType .MUTATION )
122
- or mutation_type .ast_node ,
123
- )
124
-
125
- subscription_type = schema .subscription_type
126
- if subscription_type and not is_object_type (subscription_type ):
127
- self .report_error (
128
- "Subscription root type must be Object type if provided,"
129
- f" it cannot be { subscription_type } ." ,
130
- get_operation_type_node (schema , OperationType .SUBSCRIPTION )
131
- or subscription_type .ast_node ,
132
- )
108
+ for operation_type in OperationType :
109
+ root_type = schema .get_root_type (operation_type )
110
+ if root_type and not is_object_type (root_type ):
111
+ operation_type_str = operation_type .value .capitalize ()
112
+ root_type_str = inspect (root_type )
113
+ if_provided_str = (
114
+ "" if operation_type == operation_type .QUERY else " if provided"
115
+ )
116
+ self .report_error (
117
+ f"{ operation_type_str } root type must be Object type"
118
+ f"{ if_provided_str } , it cannot be { root_type_str } ." ,
119
+ get_operation_type_node (schema , operation_type )
120
+ or root_type .ast_node ,
121
+ )
133
122
134
123
def validate_directives (self ) -> None :
135
124
directives = self .schema .directives
0 commit comments