api
type_error
ai_generated
true
GraphQL 错误:参数“limit”的值无效:期望类型“Int!”,但得到“String”
GraphQL error: Argument "limit" has invalid value: expected type "Int!" but got "String"
ID: api/graphql-field-argument-type-mismatch
90%修复率
85%置信度
1证据数
2023-08-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| GraphQL June 2018 | active | — | — | — |
| Apollo Server v4 | active | — | — | — |
| graphql-js v16 | active | — | — | — |
根因分析
客户端发送的 GraphQL 查询或变更中使用了错误类型的参数值(例如字符串而非整数)。
English
The client sent a GraphQL query or mutation with an argument value of the wrong type (e.g., string instead of integer).
官方文档
https://graphql.org/learn/schema/#type-system解决方案
-
Ensure the client sends the correct type: for integers, avoid quoting (e.g., `{ "query": "query { items(limit: 10) { id } }" }`). -
Use a variable with a proper type definition: `query($limit: Int!) { items(limit: $limit) { id } }` and pass `{"limit": 10}` in the variables.
无效尝试
常见但无效的做法:
-
90% 失败
GraphQL strict typing rejects mismatched types unless coercion is explicitly defined.
-
60% 失败
Clients unaware of the custom scalar may still send strings.