def test_object_type_field_names_are_converted_from_snake_case_to_camel_case(): graph_type = g.ObjectType("Obj", fields=( g.field("field_name", type=g.String), )) assert_that(to_graphql_type(graph_type), is_graphql_non_null( is_graphql_object_type( fields=is_mapping({ "fieldName": anything, }), ), ))
def test_recursive_object_type_is_converted_to_non_null_graphql_object_type(): graph_type = g.ObjectType("Obj", fields=lambda: ( g.field("self", type=graph_type), )) assert_that(to_graphql_type(graph_type), is_graphql_non_null( is_graphql_object_type( name="Obj", fields=is_mapping({ "self": is_graphql_field(type=is_graphql_non_null(is_graphql_object_type(name="Obj"))), }), ), ))
def test_object_type_is_converted_to_non_null_graphql_object_type(): graph_type = g.ObjectType("Obj", fields=( g.field("value", type=g.String), )) assert_that(to_graphql_type(graph_type), is_graphql_non_null( is_graphql_object_type( name="Obj", fields=is_mapping({ "value": is_graphql_field(type=is_graphql_non_null(is_graphql_string)), }), ), ))
def test_when_input_field_has_default_then_input_field_type_is_nullable(): graph_type = g.InputObjectType("Obj", fields=( g.input_field("value", type=g.String, default=""), )) assert_that(to_graphql_type(graph_type), is_graphql_non_null( is_graphql_input_object_type( name="Obj", fields=is_mapping({ "value": is_graphql_input_field(type=is_graphql_string), }), ), ))
def test_when_param_has_default_then_param_is_converted_to_nullable_graphql_arg(): graph_type = g.ObjectType("Obj", fields=( g.field("value", type=g.String, params=( g.param("arg", g.Int, default=42), )), )) assert_that(to_graphql_type(graph_type), is_graphql_non_null( is_graphql_object_type( fields=is_mapping({ "value": is_graphql_field(args=is_mapping({ "arg": is_graphql_argument(type=is_graphql_int), })), }), ), ))
def test_enum_is_converted_to_non_null_enum_type(): class Season(enum.Enum): winter = "WINTER" spring = "SPRING" summer = "SUMMER" autumn = "AUTUMN" SeasonGraphType = g.EnumType(Season) graphql_type = to_graphql_type(SeasonGraphType) assert_that(graphql_type, is_graphql_non_null(is_graphql_enum_type( name="Season", values=contains_exactly( is_graphql_enum_value(name="WINTER", value="WINTER"), is_graphql_enum_value(name="SPRING", value="SPRING"), is_graphql_enum_value(name="SUMMER", value="SUMMER"), is_graphql_enum_value(name="AUTUMN", value="AUTUMN"), ), )))
def test_object_type_interfaces_are_converted_to_graphql_interfaces(): graph_interface_type = g.InterfaceType("Interface", fields=( g.field("value", type=g.String), )) graph_object_type = g.ObjectType( "Obj", fields=( g.field("value", type=g.String), ), interfaces=(graph_interface_type, ), ) assert_that(to_graphql_type(graph_object_type), is_graphql_non_null( is_graphql_object_type( interfaces=contains_exactly( is_graphql_interface_type(name="Interface"), ), ), ))
def test_boolean_is_converted_to_non_null_graphql_boolean(): assert_that(to_graphql_type(g.Boolean), is_graphql_non_null(is_graphql_boolean))
def test_nullable_type_is_converted_to_graphql_type_without_non_null(): assert_that(to_graphql_type(g.NullableType(g.Boolean)), is_graphql_boolean)
def test_list_type_is_converted_to_non_null_list_type(): assert_that(to_graphql_type(g.ListType(g.Boolean)), is_graphql_list(is_graphql_non_null(is_graphql_boolean)))
def test_string_is_converted_to_non_null_graphql_string(): assert_that(to_graphql_type(g.String), is_graphql_non_null(is_graphql_string))
def test_int_is_converted_to_non_null_graphql_int(): assert_that(to_graphql_type(g.Int), is_graphql_non_null(is_graphql_int))
def test_float_is_converted_to_non_null_graphql_float(): assert_that(to_graphql_type(g.Float), is_graphql_non_null(is_graphql_float))