Repository: graphql/graphql-js (ts)

Issue:
Input object coercion should reject arrays directly
If an array is fed into input object coercion it should be rejected directly, rather than passing the object check and then failing on the keys checks.

See this repro:

https://gist.github.com/benjie/58ba75340a85b0da4b403973bea2c5fb

Seems like adding a `!Array.isArray(...)` check should cover it?

Pull request description:
fix(coerce-input-value): input object coercion rejects arrays
This PR closes #4365 

Rejects arrays when input type is an object. Works for top level arrays and deep ones. 

Patch:
diff --git a/src/utilities/coerceInputValue.ts b/src/utilities/coerceInputValue.ts
index eeab0614..5263e925 100644
--- a/src/utilities/coerceInputValue.ts
+++ b/src/utilities/coerceInputValue.ts
@@ -86,7 +86,7 @@ function coerceInputValueImpl(
   }
 
   if (isInputObjectType(type)) {
-    if (!isObjectLike(inputValue)) {
+    if (!isObjectLike(inputValue) || Array.isArray(inputValue)) {
       onError(
         pathToArray(path),
         inputValue,


Test patch:
diff --git a/src/utilities/__tests__/coerceInputValue-test.ts b/src/utilities/__tests__/coerceInputValue-test.ts
index 3692ce26..03afca6a 100644
--- a/src/utilities/__tests__/coerceInputValue-test.ts
+++ b/src/utilities/__tests__/coerceInputValue-test.ts
@@ -183,11 +183,19 @@ describe('coerceInputValue', () => {
   });
 
   describe('for GraphQLInputObject', () => {
+    const DeepObject = new GraphQLInputObjectType({
+      name: 'DeepObject',
+      fields: {
+        foo: { type: new GraphQLNonNull(GraphQLInt) },
+        bar: { type: GraphQLInt },
+      },
+    });
     const TestInputObject = new GraphQLInputObjectType({
       name: 'TestInputObject',
       fields: {
         foo: { type: new GraphQLNonNull(GraphQLInt) },
         bar: { type: GraphQLInt },
+        deepObject: { type: DeepObject },
       },
     });
 
@@ -271,6 +279,31 @@ describe('coerceInputValue', () => {
         },
       ]);
     });
+
+    it('returns an error for an array type', () => {
+      const result = coerceValue([{ foo: 1 }, { bar: 1 }], TestInputObject);
+      expectErrors(result).to.deep.equal([
+        {
+          error: 'Expected type "TestInputObject" to be an object.',
+          path: [],
+          value: [{ foo: 1 }, { bar: 1 }],
+        },
+      ]);
+    });
+
+    it('returns an error for an array type on a nested field', () => {
+      const result = coerceValue(
+        { foo: 1, deepObject: [1, 2, 3] },
+        TestInputObject,
+      );
+      expectErrors(result).to.deep.equal([
+        {
+          error: 'Expected type "DeepObject" to be an object.',
+          path: ['deepObject'],
+          value: [1, 2, 3],
+        },
+      ]);
+    });
   });
 
   describe('for GraphQLInputObject that isOneOf', () => {