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."
     ]
 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'"]
Exemple #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}
Exemple #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"
     ]
Exemple #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'"
     ]
Exemple #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"
     ]
Exemple #10
0
 def returns_null_for_null_value():
     result = coerce_value(None, GraphQLInt)
     assert expect_value(result) is None
Exemple #11
0
 def returns_value_for_negative_int_input():
     result = coerce_value(-1, GraphQLInt)
     assert expect_value(result) == -1
Exemple #12
0
 def returns_value_for_integer():
     result = coerce_value(1, GraphQLInt)
     assert expect_value(result) == 1
Exemple #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]"
     ]
Exemple #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."
     ]
Exemple #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'"
     ]
Exemple #16
0
 def returns_no_error_for_exponent_input():
     result = coerce_value(1e3, GraphQLFloat)
     assert expect_value(result) == 1000
Exemple #17
0
 def returns_value_for_decimal():
     result = coerce_value(1.1, GraphQLFloat)
     assert expect_value(result) == 1.1
Exemple #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'"
     ]
Exemple #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?"
     ]
Exemple #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'"
     ]
Exemple #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]"
     ]
Exemple #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
Exemple #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'"
     ]
Exemple #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?"
     ]
Exemple #25
0
 def returns_value_for_exponent_input():
     result = coerce_value(1e3, GraphQLInt)
     assert expect_value(result) == 1000
Exemple #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."]
Exemple #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: ''"
     ]
Exemple #28
0
 def returns_no_error_for_a_valid_input():
     result = coerce_value({"foo": 123}, TestInputObject)
     assert expect_value(result) == {"foo": 123}
Exemple #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"
     ]
Exemple #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."
     ]