ITADN

Fix Incorrect Boolean Argument Handling in GraphQL Delegate

#9344ClosedCStre 创建于 2026-03-20
C
CStrecommented
Hi! 👋 Firstly, thanks for your work on this project! 🙂 Today I used [patch-package](https://github.com/ds300/patch-package) to patch `@graphql-tools/delegate` for the project I'm working on. <!-- 🔺️🔺️🔺️ PLEASE REPLACE THIS BLOCK with a description of your problem, and any other relevant context 🔺️🔺️🔺️ --> Here is the diff that solved my problem: ```diff --git a/node_modules/@graphql-tools/delegate/dist/index.cjs b/node_modules/@graphql-tools/delegate/dist/index.cjs index 285d4b1..e603499 100644 --- a/node_modules/@graphql-tools/delegate/dist/index.cjs +++ b/node_modules/@graphql-tools/delegate/dist/index.cjs @@ -1974,7 +1974,8 @@ function projectArgumentValue(argValue, argType) { return projectedValue; } if (argType.name === "Boolean") { - return Boolean(argValue); + if (typeof argValue === "boolean") return argValue; + return argValue === "false" ? false : Boolean(argValue); } if (argType.name === "Int" || argType.name === "Float") { return Number(argValue); diff --git a/node_modules/@graphql-tools/delegate/dist/index.js b/node_modules/@graphql-tools/delegate/dist/index.js index 75eda9a..2476e9c 100644 --- a/node_modules/@graphql-tools/delegate/dist/index.js +++ b/node_modules/@graphql-tools/delegate/dist/index.js @@ -1974,7 +1974,8 @@ function projectArgumentValue(argValue, argType) { return projectedValue; } if (argType.name === "Boolean") { - return Boolean(argValue); + if (typeof argValue === "boolean") return argValue; + return argValue === "false" ? false : Boolean(argValue); } if (argType.name === "Int" || argType.name === "Float") { return Number(argValue); ``` ### The current implementation converts any truthy value to true using Boolean(argValue), including strings like "false", which leads to unexpected behavior. **Problem:** When argType.name is "Boolean", the function projectArgumentValue erroneously casts the argument to a boolean using Boolean(argValue). This approach converts any value that's not explicitly false or 0 to true, including strings such as "false". Users passing the string "false" as input to a boolean argument expect it to be treated as false, but it is interpreted as true. **Solution:** The provided fix checks if argValue is already a boolean and returns it directly. If argValue is the string "false", the function should correctly interpret it as false. All other values fall back to the existing conversion logic (Boolean(argValue)). <em>This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).</em>
关闭于 2026-03-22 0 条评论