def returns_an_error_for_an_invalid_input():
     result = coerce_value([1, "b", True, 4], TestList)
     assert expect_errors(result) == [
         "Expected type Int at value[1]."
         " Int cannot represent non-integer value: 'b'",
         "Expected type Int at value[2]."
         " Int cannot represent non-integer value: True",
     ]
 def returns_error_for_an_unknown_field():
     result = coerce_value({
         "foo": 123,
         "unknownField": 123
     }, TestInputObject)
     assert expect_errors(result) == [
         "Field 'unknownField' is not defined by type TestInputObject."
     ]
Ejemplo n.º 3
0
 def returns_multiple_errors_for_multiple_invalid_fields():
     result = coerce_value(
         {'foo': 'abc', 'bar': 'def'}, TestInputObject)
     assert expect_error(result) == [
         'Expected type Int at value.foo;'
         " Int cannot represent non-integer value: 'abc'",
         'Expected type Int at value.bar;'
         " Int cannot represent non-integer value: 'def'"]
Ejemplo n.º 4
0
 def returns_multiple_errors_for_multiple_invalid_fields():
     result = coerce_value({
         "foo": "abc",
         "bar": "def"
     }, TestInputObject)
     assert expect_error(result) == [
         "Expected type Int at value.foo;"
         " Int cannot represent non-integer value: 'abc'",
         "Expected type Int at value.bar;"
         " Int cannot represent non-integer value: 'def'",
     ]
 def transforms_values_with_out_type():
     # This is an extension of GraphQL.js.
     ComplexInputObject = GraphQLInputObjectType(
         "Complex",
         {
             "real": GraphQLInputField(GraphQLFloat),
             "imag": GraphQLInputField(GraphQLFloat),
         },
         out_type=lambda value: complex(value["real"], value["imag"]),
     )
     result = coerce_value({"real": 1, "imag": 2}, ComplexInputObject)
     assert expect_value(result) == 1 + 2j
 def transforms_names_using_out_name():
     # This is an extension of GraphQL.js.
     ComplexInputObject = GraphQLInputObjectType(
         "Complex",
         {
             "realPart":
             GraphQLInputField(GraphQLFloat, out_name="real_part"),
             "imagPart":
             GraphQLInputField(
                 GraphQLFloat, default_value=0, out_name="imag_part"),
         },
     )
     result = coerce_value({"realPart": 1}, ComplexInputObject)
     assert expect_value(result) == {"real_part": 1, "imag_part": 0}
Ejemplo n.º 7
0
 def returns_a_single_error_for_infinity_input():
     result = coerce_value(inf, GraphQLFloat)
     assert expect_error(result) == [
         "Expected type Float;"
         " Float cannot represent non numeric value: inf"
     ]
Ejemplo n.º 8
0
 def returns_error_for_an_invalid_field():
     result = coerce_value({"foo": "abc"}, TestInputObject)
     assert expect_error(result) == [
         "Expected type Int at value.foo;"
         " Int cannot represent non-integer value: 'abc'"
     ]
Ejemplo n.º 9
0
 def returns_a_single_error_for_2_32_input_as_int():
     result = coerce_value(1 << 32, GraphQLInt)
     assert expect_error(result) == [
         "Expected type Int; Int cannot represent"
         " non 32-bit signed integer value: 4294967296"
     ]
Ejemplo n.º 10
0
 def returns_null_for_null_value():
     result = coerce_value(None, GraphQLInt)
     assert expect_value(result) is None
Ejemplo n.º 11
0
 def returns_value_for_negative_int_input():
     result = coerce_value(-1, GraphQLInt)
     assert expect_value(result) == -1
Ejemplo n.º 12
0
 def returns_value_for_integer():
     result = coerce_value(1, GraphQLInt)
     assert expect_value(result) == 1
Ejemplo n.º 13
0
 def returns_error_for_array_input_as_string():
     result = coerce_value([1, 2, 3], GraphQLString)
     assert expect_error(result) == [
         f"Expected type String;"
         " String cannot represent a non string value: [1, 2, 3]"
     ]
Ejemplo n.º 14
0
 def returns_error_for_a_missing_required_field():
     result = coerce_value({"bar": 123}, TestInputObject)
     assert expect_error(result) == [
         "Field value.foo"
         " of required type Int! was not provided."
     ]
Ejemplo n.º 15
0
 def returns_error_for_numeric_looking_string():
     result = coerce_value("1", GraphQLFloat)
     assert expect_error(result) == [
         "Expected type Float;"
         " Float cannot represent non numeric value: '1'"
     ]
Ejemplo n.º 16
0
 def returns_no_error_for_exponent_input():
     result = coerce_value(1e3, GraphQLFloat)
     assert expect_value(result) == 1000
Ejemplo n.º 17
0
 def returns_value_for_decimal():
     result = coerce_value(1.1, GraphQLFloat)
     assert expect_value(result) == 1.1
Ejemplo n.º 18
0
 def returns_a_single_error_for_string_input():
     result = coerce_value("meow", GraphQLInt)
     assert expect_error(result) == [
         "Expected type Int;"
         " Int cannot represent non-integer value: 'meow'"
     ]
Ejemplo n.º 19
0
 def returns_error_for_a_misspelled_field():
     result = coerce_value({"foo": 123, "bart": 123}, TestInputObject)
     assert expect_error(result) == [
         "Field 'bart' is not defined"
         " by type TestInputObject; did you mean bar?"
     ]
Ejemplo n.º 20
0
 def returns_a_single_error_for_string_input():
     result = coerce_value("meow", GraphQLFloat)
     assert expect_error(result) == [
         "Expected type Float;"
         " Float cannot represent non numeric value: 'meow'"
     ]
Ejemplo n.º 21
0
 def returns_error_for_array_input_as_string():
     result = coerce_value([1, 2, 3], GraphQLID)
     assert expect_error(result) == [
         f"Expected type ID;"
         " ID cannot represent value: [1, 2, 3]"
     ]
Ejemplo n.º 22
0
        def returns_no_error_for_a_known_enum_name():
            foo_result = coerce_value("FOO", TestEnum)
            assert expect_value(foo_result) == "InternalFoo"

            bar_result = coerce_value("BAR", TestEnum)
            assert expect_value(bar_result) == 123456789
Ejemplo n.º 23
0
 def returns_no_error_for_numeric_looking_string():
     result = coerce_value("1", GraphQLInt)
     assert expect_error(result) == [
         f"Expected type Int;"
         " Int cannot represent non-integer value: '1'"
     ]
Ejemplo n.º 24
0
 def results_error_for_misspelled_enum_value():
     result = coerce_value("foo", TestEnum)
     assert expect_error(result) == [
         "Expected type TestEnum; did you mean FOO?"
     ]
Ejemplo n.º 25
0
 def returns_value_for_exponent_input():
     result = coerce_value(1e3, GraphQLInt)
     assert expect_value(result) == 1000
Ejemplo n.º 26
0
        def results_error_for_incorrect_value_type():
            result1 = coerce_value(123, TestEnum)
            assert expect_error(result1) == ["Expected type TestEnum."]

            result2 = coerce_value({"field": "value"}, TestEnum)
            assert expect_error(result2) == ["Expected type TestEnum."]
Ejemplo n.º 27
0
 def returns_a_single_error_for_empty_string_as_value():
     result = coerce_value("", GraphQLInt)
     assert expect_error(result) == [
         "Expected type Int; Int cannot represent"
         " non-integer value: ''"
     ]
Ejemplo n.º 28
0
 def returns_no_error_for_a_valid_input():
     result = coerce_value({"foo": 123}, TestInputObject)
     assert expect_value(result) == {"foo": 123}
Ejemplo n.º 29
0
 def returns_a_single_error_for_infinity_input_as_int():
     result = coerce_value(inf, GraphQLInt)
     assert expect_error(result) == [
         "Expected type Int;"
         " Int cannot represent non-integer value: inf"
     ]
Ejemplo n.º 30
0
 def returns_error_for_a_non_dict_value():
     result = coerce_value(123, TestInputObject)
     assert expect_error(result) == [
         "Expected type TestInputObject to be a dict."
     ]