|
1 | | -from graphql.utilities import build_schema, print_schema, lexicographic_sort_schema |
| 1 | +from typing import cast |
| 2 | + |
| 3 | +from graphql.type import ( |
| 4 | + GraphQLArgument, |
| 5 | + GraphQLField, |
| 6 | + GraphQLInputField, |
| 7 | + GraphQLInputObjectType, |
| 8 | + GraphQLObjectType, |
| 9 | + GraphQLSchema, |
| 10 | + GraphQLString, |
| 11 | +) |
| 12 | +from graphql.utilities import build_schema, lexicographic_sort_schema, print_schema |
2 | 13 |
|
3 | 14 | from ..utils import dedent |
4 | 15 |
|
@@ -342,3 +353,102 @@ def sort_recursive_types(): |
342 | 353 | fooC: FooC |
343 | 354 | } |
344 | 355 | """) |
| 356 | + |
| 357 | + def describe_input_field_properties(): |
| 358 | + def preserves_input_field_deprecation_reason(): |
| 359 | + input_type = GraphQLInputObjectType( |
| 360 | + "TestInput", |
| 361 | + { |
| 362 | + "zField": GraphQLInputField(GraphQLString), |
| 363 | + "aField": GraphQLInputField( |
| 364 | + GraphQLString, deprecation_reason="Use bField instead" |
| 365 | + ), |
| 366 | + "mField": GraphQLInputField( |
| 367 | + GraphQLString, deprecation_reason="Deprecated field" |
| 368 | + ), |
| 369 | + }, |
| 370 | + ) |
| 371 | + query_type = GraphQLObjectType( |
| 372 | + "Query", |
| 373 | + { |
| 374 | + "dummy": GraphQLField( |
| 375 | + GraphQLString, args={"input": GraphQLArgument(input_type)} |
| 376 | + ) |
| 377 | + }, |
| 378 | + ) |
| 379 | + schema = GraphQLSchema(query=query_type, types=[input_type]) |
| 380 | + sorted_schema = lexicographic_sort_schema(schema) |
| 381 | + |
| 382 | + sorted_input_type = cast( |
| 383 | + GraphQLInputObjectType, sorted_schema.type_map["TestInput"] |
| 384 | + ) |
| 385 | + field_names = list(sorted_input_type.fields) |
| 386 | + assert field_names == ["aField", "mField", "zField"] |
| 387 | + |
| 388 | + assert ( |
| 389 | + sorted_input_type.fields["aField"].deprecation_reason |
| 390 | + == "Use bField instead" |
| 391 | + ) |
| 392 | + assert ( |
| 393 | + sorted_input_type.fields["mField"].deprecation_reason |
| 394 | + == "Deprecated field" |
| 395 | + ) |
| 396 | + assert sorted_input_type.fields["zField"].deprecation_reason is None |
| 397 | + |
| 398 | + def preserves_input_field_extensions(): |
| 399 | + input_type = GraphQLInputObjectType( |
| 400 | + "TestInput", |
| 401 | + { |
| 402 | + "zField": GraphQLInputField(GraphQLString, extensions={"x": 1}), |
| 403 | + "aField": GraphQLInputField( |
| 404 | + GraphQLString, extensions={"custom": "value"} |
| 405 | + ), |
| 406 | + }, |
| 407 | + ) |
| 408 | + query_type = GraphQLObjectType( |
| 409 | + "Query", |
| 410 | + { |
| 411 | + "dummy": GraphQLField( |
| 412 | + GraphQLString, args={"input": GraphQLArgument(input_type)} |
| 413 | + ) |
| 414 | + }, |
| 415 | + ) |
| 416 | + schema = GraphQLSchema(query=query_type, types=[input_type]) |
| 417 | + sorted_schema = lexicographic_sort_schema(schema) |
| 418 | + sorted_input_type = cast( |
| 419 | + GraphQLInputObjectType, sorted_schema.type_map["TestInput"] |
| 420 | + ) |
| 421 | + |
| 422 | + field_names = list(sorted_input_type.fields) |
| 423 | + assert field_names == ["aField", "zField"] |
| 424 | + |
| 425 | + assert sorted_input_type.fields["aField"].extensions == {"custom": "value"} |
| 426 | + assert sorted_input_type.fields["zField"].extensions == {"x": 1} |
| 427 | + |
| 428 | + def preserves_input_field_out_name(): |
| 429 | + input_type = GraphQLInputObjectType( |
| 430 | + "TestInput", |
| 431 | + { |
| 432 | + "zField": GraphQLInputField(GraphQLString, out_name="z_field"), |
| 433 | + "aField": GraphQLInputField(GraphQLString, out_name="a_field"), |
| 434 | + }, |
| 435 | + ) |
| 436 | + query_type = GraphQLObjectType( |
| 437 | + "Query", |
| 438 | + { |
| 439 | + "dummy": GraphQLField( |
| 440 | + GraphQLString, args={"input": GraphQLArgument(input_type)} |
| 441 | + ) |
| 442 | + }, |
| 443 | + ) |
| 444 | + schema = GraphQLSchema(query=query_type, types=[input_type]) |
| 445 | + sorted_schema = lexicographic_sort_schema(schema) |
| 446 | + sorted_input_type = cast( |
| 447 | + GraphQLInputObjectType, sorted_schema.type_map["TestInput"] |
| 448 | + ) |
| 449 | + |
| 450 | + field_names = list(sorted_input_type.fields) |
| 451 | + assert field_names == ["aField", "zField"] |
| 452 | + |
| 453 | + assert sorted_input_type.fields["aField"].out_name == "a_field" |
| 454 | + assert sorted_input_type.fields["zField"].out_name == "z_field" |
0 commit comments