|
1 | 1 | from pytest import raises
|
2 | 2 |
|
3 | 3 | from graphql.type import (
|
4 |
| - GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, |
5 |
| - GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, |
| 4 | + GraphQLArgument, GraphQLEnumType, GraphQLInputField, |
| 5 | + GraphQLInputObjectType, GraphQLInterfaceType, GraphQLList, |
| 6 | + GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, |
6 | 7 | GraphQLString, GraphQLUnionType,
|
7 | 8 | assert_abstract_type, assert_composite_type, assert_enum_type,
|
8 | 9 | assert_input_object_type, assert_input_type, assert_interface_type,
|
|
12 | 13 | assert_wrapping_type, get_named_type, get_nullable_type, is_abstract_type,
|
13 | 14 | is_composite_type, is_enum_type, is_input_object_type, is_input_type,
|
14 | 15 | is_interface_type, is_leaf_type, is_list_type, is_named_type,
|
| 16 | + is_required_argument, is_required_input_field, |
15 | 17 | is_non_null_type, is_nullable_type, is_object_type, is_output_type,
|
16 | 18 | is_scalar_type, is_type, is_union_type, is_wrapping_type)
|
17 | 19 |
|
@@ -370,3 +372,47 @@ def unwraps_wrapper_types():
|
370 | 372 | def unwraps_deeply_wrapper_types():
|
371 | 373 | assert get_named_type(GraphQLNonNull(GraphQLList(GraphQLNonNull(
|
372 | 374 | ObjectType)))) is ObjectType
|
| 375 | + |
| 376 | + def describe_is_required_argument(): |
| 377 | + |
| 378 | + def returns_true_for_required_arguments(): |
| 379 | + required_arg = GraphQLArgument(GraphQLNonNull(GraphQLString)) |
| 380 | + assert is_required_argument(required_arg) is True |
| 381 | + |
| 382 | + def returns_false_for_optional_arguments(): |
| 383 | + opt_arg1 = GraphQLArgument(GraphQLString) |
| 384 | + assert is_required_argument(opt_arg1) is False |
| 385 | + |
| 386 | + opt_arg2 = GraphQLArgument(GraphQLString, default_value=None) |
| 387 | + assert is_required_argument(opt_arg2) is False |
| 388 | + |
| 389 | + opt_arg3 = GraphQLArgument( |
| 390 | + GraphQLList(GraphQLNonNull(GraphQLString))) |
| 391 | + assert is_required_argument(opt_arg3) is False |
| 392 | + |
| 393 | + opt_arg4 = GraphQLArgument( |
| 394 | + GraphQLNonNull(GraphQLString), default_value='default') |
| 395 | + assert is_required_argument(opt_arg4) is False |
| 396 | + |
| 397 | + def describe_is_required_input_field(): |
| 398 | + |
| 399 | + def returns_true_for_required_input_field(): |
| 400 | + required_field = GraphQLInputField( |
| 401 | + GraphQLNonNull(GraphQLString)) |
| 402 | + assert is_required_input_field(required_field) is True |
| 403 | + |
| 404 | + def returns_false_for_optional_input_field(): |
| 405 | + opt_field1 = GraphQLInputField(GraphQLString) |
| 406 | + assert is_required_input_field(opt_field1) is False |
| 407 | + |
| 408 | + opt_field2 = GraphQLInputField( |
| 409 | + GraphQLString, default_value=None) |
| 410 | + assert is_required_input_field(opt_field2) is False |
| 411 | + |
| 412 | + opt_field3 = GraphQLInputField( |
| 413 | + GraphQLList(GraphQLNonNull(GraphQLString))) |
| 414 | + assert is_required_input_field(opt_field3) is False |
| 415 | + |
| 416 | + opt_field4 = GraphQLInputField( |
| 417 | + GraphQLNonNull(GraphQLString), default_value='default') |
| 418 | + assert is_required_input_field(opt_field4) is False |
0 commit comments