ardatan / ardatan/graphql-tools
transformInputValue chokes on queries that rely on array input coercion
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
### Issue workflow progress
_Progress of the issue based on the [Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_
- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure the GraphQL Tools package versions under `package.json` matches 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.
```graphql
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**
Contributor guide
Research direction
Start by locating transformInputValue.js in the GraphQL Tools utilities and inspect the path that handles renamed input fields. Reproduce the single-value input for fieldX: [String], then verify that array coercion no longer causes a value.map error and that array inputs still transform correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100