|  | 
| 13 | 13 | import { expect } from 'chai'; | 
| 14 | 14 | import { describe, it } from 'mocha'; | 
| 15 | 15 | import { execute } from '../execute'; | 
|  | 16 | +import { coerceValue } from '../values'; | 
| 16 | 17 | import { parse } from '../../language'; | 
| 17 | 18 | import { | 
| 18 | 19 |   GraphQLSchema, | 
| @@ -592,6 +593,56 @@ describe('Execute: Handles inputs', () => { | 
| 592 | 593 |       }); | 
| 593 | 594 |     }); | 
| 594 | 595 | 
 | 
|  | 596 | +    it('reports error for array passed into string input', async () => { | 
|  | 597 | +      const doc = ` | 
|  | 598 | +        query SetsNonNullable($value: String!) { | 
|  | 599 | +          fieldWithNonNullableStringInput(input: $value) | 
|  | 600 | +        } | 
|  | 601 | +      `; | 
|  | 602 | +      const ast = parse(doc); | 
|  | 603 | +      const variables = {value: [ 1, 2, 3 ]}; | 
|  | 604 | + | 
|  | 605 | +      expect( | 
|  | 606 | +        await execute(schema, ast, null, null, variables) | 
|  | 607 | +      ).to.deep.equal({ | 
|  | 608 | +        errors: [ { | 
|  | 609 | +          message: | 
|  | 610 | +            'Variable "$value" got invalid value [1,2,3].\nExpected type ' + | 
|  | 611 | +            '"String", found [1,2,3]: String cannot represent an array value: [1,2,3]', | 
|  | 612 | +          locations: [ { line: 2, column: 31 } ], | 
|  | 613 | +          path: undefined, | 
|  | 614 | +        } ] | 
|  | 615 | +      }); | 
|  | 616 | +    }); | 
|  | 617 | + | 
|  | 618 | +    it('coercing an array to GraphQLString throws TypeError', async () => { | 
|  | 619 | +      let caughtError; | 
|  | 620 | +      try { | 
|  | 621 | +        coerceValue(GraphQLString, [ 1, 2, 3 ]); | 
|  | 622 | +      } catch (error) { | 
|  | 623 | +        caughtError = error; | 
|  | 624 | +      } | 
|  | 625 | + | 
|  | 626 | +      expect(caughtError instanceof TypeError).to.equal(true); | 
|  | 627 | +      expect(caughtError && caughtError.message).to.equal( | 
|  | 628 | +        'String cannot represent an array value: [1,2,3]' | 
|  | 629 | +      ); | 
|  | 630 | +    }); | 
|  | 631 | + | 
|  | 632 | +    it('serializing an array via GraphQLString throws TypeError', async () => { | 
|  | 633 | +      let caughtError; | 
|  | 634 | +      try { | 
|  | 635 | +        GraphQLString.serialize([ 1, 2, 3 ]); | 
|  | 636 | +      } catch (error) { | 
|  | 637 | +        caughtError = error; | 
|  | 638 | +      } | 
|  | 639 | + | 
|  | 640 | +      expect(caughtError instanceof TypeError).to.equal(true); | 
|  | 641 | +      expect(caughtError && caughtError.message).to.equal( | 
|  | 642 | +        'String cannot represent an array value: [1,2,3]' | 
|  | 643 | +      ); | 
|  | 644 | +    }); | 
|  | 645 | + | 
| 595 | 646 |     it('reports error for non-provided variables for non-nullable inputs', async () => { | 
| 596 | 647 |       // Note: this test would typically fail validation before encountering | 
| 597 | 648 |       // this execution error, however for queries which previously validated | 
|  | 
0 commit comments