|
20 | 20 | is_scalar_type, |
21 | 21 | is_union_type, |
22 | 22 | ) |
23 | | -from .scalars import GraphQLBoolean, GraphQLString |
24 | 23 | from ..language import DirectiveLocation, print_ast |
| 24 | +from ..pyutils import inspect |
| 25 | +from .scalars import GraphQLBoolean, GraphQLString |
25 | 26 |
|
26 | 27 | __all__ = [ |
27 | 28 | "SchemaMetaFieldDef", |
@@ -258,7 +259,9 @@ def kind(type_, _info): |
258 | 259 | return TypeKind.LIST |
259 | 260 | if is_non_null_type(type_): |
260 | 261 | return TypeKind.NON_NULL |
261 | | - raise TypeError(f"Unknown kind of type: {type_}") |
| 262 | + |
| 263 | + # Not reachable. All possible types have been considered. |
| 264 | + raise TypeError(f"Unexpected type: '{inspect(type_)}'.") # pragma: no cover |
262 | 265 |
|
263 | 266 | @staticmethod |
264 | 267 | def name(type_, _info): |
@@ -336,39 +339,53 @@ def of_type(type_, _info): |
336 | 339 | ) |
337 | 340 |
|
338 | 341 |
|
339 | | -def _resolve_input_value_default_value(item, _info): |
340 | | - # Since ast_from_value needs graphql.type, it can only be imported later |
341 | | - from ..utilities import ast_from_value |
342 | | - |
343 | | - value_ast = ast_from_value(item[1].default_value, item[1].type) |
344 | | - return print_ast(value_ast) if value_ast else None |
345 | | - |
346 | | - |
347 | 342 | __InputValue: GraphQLObjectType = GraphQLObjectType( |
348 | 343 | name="__InputValue", |
349 | 344 | description="Arguments provided to Fields or Directives and the input" |
350 | 345 | " fields of an InputObject are represented as Input Values" |
351 | 346 | " which describe their type and optionally a default value.", |
352 | 347 | fields=lambda: { |
353 | 348 | "name": GraphQLField( |
354 | | - GraphQLNonNull(GraphQLString), resolve=lambda item, _info: item[0] |
| 349 | + GraphQLNonNull(GraphQLString), resolve=InputValueFieldResolvers.name |
355 | 350 | ), |
356 | 351 | "description": GraphQLField( |
357 | | - GraphQLString, resolve=lambda item, _info: item[1].description |
| 352 | + GraphQLString, resolve=InputValueFieldResolvers.description |
358 | 353 | ), |
359 | 354 | "type": GraphQLField( |
360 | | - GraphQLNonNull(__Type), resolve=lambda item, _info: item[1].type |
| 355 | + GraphQLNonNull(__Type), resolve=InputValueFieldResolvers.type |
361 | 356 | ), |
362 | 357 | "defaultValue": GraphQLField( |
363 | 358 | GraphQLString, |
364 | 359 | description="A GraphQL-formatted string representing" |
365 | 360 | " the default value for this input value.", |
366 | | - resolve=_resolve_input_value_default_value, |
| 361 | + resolve=InputValueFieldResolvers.default_value, |
367 | 362 | ), |
368 | 363 | }, |
369 | 364 | ) |
370 | 365 |
|
371 | 366 |
|
| 367 | +class InputValueFieldResolvers: |
| 368 | + @staticmethod |
| 369 | + def name(item, _info): |
| 370 | + return item[0] |
| 371 | + |
| 372 | + @staticmethod |
| 373 | + def description(item, _info): |
| 374 | + return item[1].description |
| 375 | + |
| 376 | + @staticmethod |
| 377 | + def type(item, _info): |
| 378 | + return item[1].type |
| 379 | + |
| 380 | + @staticmethod |
| 381 | + def default_value(item, _info): |
| 382 | + # Since ast_from_value needs graphql.type, it can only be imported later |
| 383 | + from ..utilities import ast_from_value |
| 384 | + |
| 385 | + value_ast = ast_from_value(item[1].default_value, item[1].type) |
| 386 | + return print_ast(value_ast) if value_ast else None |
| 387 | + |
| 388 | + |
372 | 389 | __EnumValue: GraphQLObjectType = GraphQLObjectType( |
373 | 390 | name="__EnumValue", |
374 | 391 | description="One possible value for a given Enum. Enum values are unique" |
|
0 commit comments