graphql-tools
graphql-tools copied to clipboard
transformInputValue chokes on queries that rely on array input coercion
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generatein the terminal.Please make sure the GraphQL Tools package versions under
package.jsonmatches yours. - [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
transformInputValue fails with:
TypeError: value.map is not a function at transformInputValue (.../node_modules/@graphql-tools/utils/cjs/transformInputValue.js)
when the client is depending on the array input field coercion.
To Reproduce
I'm using graphql-tools to build a stitched schema using graphql-mesh. I have an upstream graphql server that accepts a query with an input type, and the input type contains a field with an array type. E.g.
query {
someField(input: SomeInput): String
}
input SomeInput {
fieldX: [String]
}
Some existing code in the application is sending fieldX: "valueY" instead of fieldX: ["valueY"], but now that I'm sending that query to my new graphql-mesh-based server it hits transformInputValue because I'm using a rename transform to rename the field.
Expected behavior
transformInputValue should check to see if the incoming value is an array before mapping over it.
Environment:
- OS: MacOS
@graphql-tools/utils:8.8.0- NodeJS: 16
Additional context
Here's the offending line:
https://github.com/ardatan/graphql-tools/blob/master/packages/utils/src/transformInputValue.ts#L20-L22
If I want to write a PR for this, what's the best test suite to add a test to? Nothing obviously directly targets that transformInputValue.ts file.
You can create a PR that fixes it so maybe we can add unit tests with some transforms to reproduce that. Thanks 🙏