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

其他格式: JSON · Markdown 中文 · English
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).

generic

官方文档

https://graphql.org/learn/schema/#type-system

解决方案

  1. Ensure the client sends the correct type: for integers, avoid quoting (e.g., `{ "query": "query { items(limit: 10) { id } }" }`).
  2. Use a variable with a proper type definition: `query($limit: Int!) { items(limit: $limit) { id } }` and pass `{"limit": 10}` in the variables.

无效尝试

常见但无效的做法:

  1. 90% 失败

    GraphQL strict typing rejects mismatched types unless coercion is explicitly defined.

  2. 60% 失败

    Clients unaware of the custom scalar may still send strings.