From 45e9ebed191cc53abafefd1dc3a437f50a27dcae Mon Sep 17 00:00:00 2001 From: Abhinand C Date: Fri, 3 Mar 2023 23:48:35 +0530 Subject: [PATCH] fix(List Input Coercion): Adds validation code for nested list with multiple values --- src/utilities/coerceInputValue.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/utilities/coerceInputValue.ts b/src/utilities/coerceInputValue.ts index d1decf86a1..8fb010d1e1 100644 --- a/src/utilities/coerceInputValue.ts +++ b/src/utilities/coerceInputValue.ts @@ -76,8 +76,21 @@ function coerceInputValueImpl( if (isListType(type)) { const itemType = type.ofType; if (isIterableObject(inputValue)) { + const isNestedList = Boolean( + isListType(itemType) && Array.from(inputValue).length > 1, + ); return Array.from(inputValue, (itemValue, index) => { const itemPath = addPath(path, index, undefined); + if (isNestedList && !isIterableObject(itemValue)) { + // Input values should be iterable for nested list type with multiple values + onError( + pathToArray(itemPath), + itemValue, + new GraphQLError( + `Expected type "${inspect(itemType)}" to be a list.`, + ), + ); + } return coerceInputValueImpl(itemValue, itemType, onError, itemPath); }); }