Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformInputValue chokes on queries that rely on array input coercion #4596

Open
4 tasks
Tracked by #5201 ...
leemhenson opened this issue Jul 25, 2022 · 2 comments
Open
4 tasks
Tracked by #5201 ...

Comments

@leemhenson
Copy link

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 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.

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

@leemhenson
Copy link
Author

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.

@ardatan
Copy link
Owner

ardatan commented Jul 25, 2022

You can create a PR that fixes it so maybe we can add unit tests with some transforms to reproduce that.
Thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants