|
9 | 9 | GraphQLInputField,
|
10 | 10 | GraphQLInputObjectType,
|
11 | 11 | GraphQLInt,
|
| 12 | + GraphQLList, |
12 | 13 | GraphQLNonNull,
|
13 | 14 | GraphQLString,
|
14 | 15 | )
|
@@ -199,13 +200,13 @@ def returns_no_error_for_a_valid_input():
|
199 | 200 | result = coerce_value({"foo": 123}, TestInputObject)
|
200 | 201 | assert expect_value(result) == {"foo": 123}
|
201 | 202 |
|
202 |
| - def returns_error_for_a_non_dict_value(): |
| 203 | + def returns_an_error_for_a_non_dict_value(): |
203 | 204 | result = coerce_value(123, TestInputObject)
|
204 | 205 | assert expect_error(result) == [
|
205 | 206 | "Expected type TestInputObject to be a dict."
|
206 | 207 | ]
|
207 | 208 |
|
208 |
| - def returns_error_for_an_invalid_field(): |
| 209 | + def returns_an_error_for_an_invalid_field(): |
209 | 210 | result = coerce_value({"foo": "abc"}, TestInputObject)
|
210 | 211 | assert expect_error(result) == [
|
211 | 212 | "Expected type Int at value.foo;"
|
@@ -239,3 +240,50 @@ def returns_error_for_a_misspelled_field():
|
239 | 240 | "Field 'bart' is not defined by type TestInputObject;"
|
240 | 241 | " did you mean bar?"
|
241 | 242 | ]
|
| 243 | + |
| 244 | + def describe_for_graphql_list(): |
| 245 | + TestList = GraphQLList(GraphQLInt) |
| 246 | + |
| 247 | + def returns_no_error_for_a_valid_input(): |
| 248 | + result = coerce_value([1, 2, 3], TestList) |
| 249 | + assert expect_value(result) == [1, 2, 3] |
| 250 | + |
| 251 | + def returns_an_error_for_an_invalid_input(): |
| 252 | + result = coerce_value([1, "b", True], TestList) |
| 253 | + assert expect_error(result) == [ |
| 254 | + "Expected type Int at value[1];" |
| 255 | + " Int cannot represent non-integer value: 'b'", |
| 256 | + "Expected type Int at value[2];" |
| 257 | + " Int cannot represent non-integer value: True", |
| 258 | + ] |
| 259 | + |
| 260 | + def returns_a_list_for_a_non_list_value(): |
| 261 | + result = coerce_value(42, TestList) |
| 262 | + assert expect_value(result) == [42] |
| 263 | + |
| 264 | + def returns_null_for_a_null_value(): |
| 265 | + result = coerce_value(None, TestList) |
| 266 | + assert expect_value(result) is None |
| 267 | + |
| 268 | + def describe_for_nested_graphql_list(): |
| 269 | + TestNestedList = GraphQLList(GraphQLList(GraphQLInt)) |
| 270 | + |
| 271 | + def returns_no_error_for_a_valid_input(): |
| 272 | + result = coerce_value([[1], [2], [3]], TestNestedList) |
| 273 | + assert expect_value(result) == [[1], [2], [3]] |
| 274 | + |
| 275 | + def returns_a_list_for_a_non_list_value(): |
| 276 | + result = coerce_value(42, TestNestedList) |
| 277 | + assert expect_value(result) == [[42]] |
| 278 | + |
| 279 | + def returns_null_for_a_null_value(): |
| 280 | + result = coerce_value(None, TestNestedList) |
| 281 | + assert expect_value(result) is None |
| 282 | + |
| 283 | + def returns_nested_list_for_nested_non_list_values(): |
| 284 | + result = coerce_value([1, 2, 3], TestNestedList) |
| 285 | + assert expect_value(result) == [[1], [2], [3]] |
| 286 | + |
| 287 | + def returns_nested_null_for_nested_null_values(): |
| 288 | + result = coerce_value([42, [None], None], TestNestedList) |
| 289 | + assert expect_value(result) == [[42], [None], None] |
0 commit comments