Skip to content

Commit

Permalink
fix(List Input Coercion): Adds validation code for nested list with m…
Browse files Browse the repository at this point in the history
…ultiple values
  • Loading branch information
abhinand-c committed Mar 3, 2023
1 parent e171a14 commit 45e9ebe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/utilities/coerceInputValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down

0 comments on commit 45e9ebe

Please sign in to comment.