BUG: Omitted optional args become "" or 0 in upstream variables
### Issue workflow progress
<!-- PLEASE DO NOT REMOVE THIS SECTION -->
_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](https://github.com/ardatan/graphql-mesh/tree/master/examples/hello-world),
[Stackblitz](https://stackblitz.com/github/ardatan/graphql-mesh/tree/master/examples/hello-world)
or
[CodeSandbox](https://codesandbox.io/s/github/ardatan/graphql-mesh/tree/master/examples/hello-world)
> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure Mesh 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
---
Hi, I am using Mesh Compose + Hive Gateway. If some values in a GraphQL request are not defined, I get incorrect interpolation, such as channel: "" or filter: "".
In Mesh Compose, I’m using the `createPrefixTransform` and `createEncapsulateTransform` transformers.
**To Reproduce** Steps to reproduce the behavior
1. Create the supergraph:
`npx mesh-compose -o supergraph.graphql`
2. Run Hive Gateway with the generated graph:
`npx hive-gateway supergraph`
3. Execute a query via Hive Gateway without providing the optional arguments.
**Observed behavior**
When I send the query `products(first: 100)`, the upstream receives:
{
"filter": "",
"where": "",
"sortBy": "",
"last": 0
}
**Expected behavior**
If an argument is not provided in the GraphQL query, it should be omitted from the upstream request variables. It should not be coerced into an empty string (`""`) or `0`, as this breaks the schema.
## Additional context
Problematic part of the generated supergraph:
sourceArgs: {
filter: "{args.filter}",
where: "{args.where}",
sortBy: "{args.sortBy}",
search: "{args.search}",
channel: "{args.channel}",
first: "{args.first}",
last: "{args.last}"
}
Has anyone encountered this problem? Is there a workaround?
关闭于 2026-01-19 2 条评论