@@ -153,74 +153,51 @@ def print_object(type_: GraphQLObjectType) -> str:
153
153
)
154
154
return (
155
155
print_description (type_ )
156
- + f"type { type_ .name } { implemented_interfaces } "
157
- + "{\n "
156
+ + f"type { type_ .name } { implemented_interfaces } "
158
157
+ print_fields (type_ )
159
- + "\n }"
160
158
)
161
159
162
160
163
161
def print_interface (type_ : GraphQLInterfaceType ) -> str :
164
- return (
165
- print_description (type_ )
166
- + f"interface { type_ .name } "
167
- + "{\n "
168
- + print_fields (type_ )
169
- + "\n }"
170
- )
162
+ return print_description (type_ ) + f"interface { type_ .name } " + print_fields (type_ )
171
163
172
164
173
165
def print_union (type_ : GraphQLUnionType ) -> str :
174
- return (
175
- print_description (type_ )
176
- + f"union { type_ .name } = "
177
- + " | " .join (t .name for t in type_ .types )
178
- )
166
+ types = type_ .types
167
+ possible_types = " = " + " | " .join (t .name for t in types ) if types else ""
168
+ return print_description (type_ ) + f"union { type_ .name } " + possible_types
179
169
180
170
181
171
def print_enum (type_ : GraphQLEnumType ) -> str :
182
- return (
183
- print_description (type_ )
184
- + f"enum { type_ .name } "
185
- + "{\n "
186
- + print_enum_values (type_ .values )
187
- + "\n }"
188
- )
189
-
190
-
191
- def print_enum_values (values : Dict [str , GraphQLEnumValue ]) -> str :
192
- return "\n " .join (
172
+ values = [
193
173
print_description (value , " " , not i ) + f" { name } " + print_deprecated (value )
194
- for i , (name , value ) in enumerate (values .items ())
195
- )
174
+ for i , (name , value ) in enumerate (type_ .values .items ())
175
+ ]
176
+ return print_description (type_ ) + f"enum { type_ .name } " + print_block (values )
196
177
197
178
198
179
def print_input_object (type_ : GraphQLInputObjectType ) -> str :
199
- fields = type_ .fields .items ()
200
- return (
201
- print_description (type_ )
202
- + f"input { type_ .name } "
203
- + "{\n "
204
- + "\n " .join (
205
- print_description (field , " " , not i )
206
- + " "
207
- + print_input_value (name , field )
208
- for i , (name , field ) in enumerate (fields )
209
- )
210
- + "\n }"
211
- )
180
+ fields = [
181
+ print_description (field , " " , not i ) + " " + print_input_value (name , field )
182
+ for i , (name , field ) in enumerate (type_ .fields .items ())
183
+ ]
184
+ return print_description (type_ ) + f"input { type_ .name } " + print_block (fields )
212
185
213
186
214
187
def print_fields (type_ : Union [GraphQLObjectType , GraphQLInterfaceType ]) -> str :
215
- fields = type_ .fields .items ()
216
- return "\n " .join (
188
+ fields = [
217
189
print_description (field , " " , not i )
218
190
+ f" { name } "
219
191
+ print_args (field .args , " " )
220
192
+ f": { field .type } "
221
193
+ print_deprecated (field )
222
- for i , (name , field ) in enumerate (fields )
223
- )
194
+ for i , (name , field ) in enumerate (type_ .fields .items ())
195
+ ]
196
+ return print_block (fields )
197
+
198
+
199
+ def print_block (items : List [str ]) -> str :
200
+ return " {\n " + "\n " .join (items ) + "\n }" if items else ""
224
201
225
202
226
203
def print_args (args : Dict [str , GraphQLArgument ], indentation = "" ) -> str :
0 commit comments