Skip to content

Commit c955976

Browse files
committed
Input object coercion rejects arrays
Note that this was already correct in the Python port. Replicates graphql/graphql-js@5adeb7f7
1 parent 5f501ec commit c955976

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎tests/utilities/test_coerce_input_value.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,19 @@ def returns_an_error_for_incorrect_value_type():
150150
]
151151

152152
def describe_for_graphql_input_object():
153+
DeepObject = GraphQLInputObjectType(
154+
"DeepObject",
155+
{
156+
"foo": GraphQLInputField(GraphQLNonNull(GraphQLInt)),
157+
"bar": GraphQLInputField(GraphQLInt),
158+
},
159+
)
153160
TestInputObject = GraphQLInputObjectType(
154161
"TestInputObject",
155162
{
156163
"foo": GraphQLInputField(GraphQLNonNull(GraphQLInt)),
157164
"bar": GraphQLInputField(GraphQLInt),
165+
"deepObject": GraphQLInputField(DeepObject),
158166
},
159167
)
160168

@@ -224,6 +232,26 @@ def returns_error_for_a_misspelled_field():
224232
)
225233
]
226234

235+
def returns_an_error_for_an_array_type():
236+
result = _coerce_value([{"foo": 1}, {"bar": 1}], TestInputObject)
237+
assert expect_errors(result) == [
238+
(
239+
"Expected type 'TestInputObject' to be a mapping.",
240+
[],
241+
[{"foo": 1}, {"bar": 1}],
242+
)
243+
]
244+
245+
def returns_an_error_for_an_array_type_on_a_nested_field():
246+
result = _coerce_value({"foo": 1, "deepObject": [1, 2, 3]}, TestInputObject)
247+
assert expect_errors(result) == [
248+
(
249+
"Expected type 'DeepObject' to be a mapping.",
250+
["deepObject"],
251+
[1, 2, 3],
252+
)
253+
]
254+
227255
def transforms_names_using_out_name():
228256
# This is an extension of GraphQL.js.
229257
ComplexInputObject = GraphQLInputObjectType(

0 commit comments

Comments
 (0)