api type_error ai_generated true

GraphQL error: Argument "limit" has invalid value: expected type "Int!" but got "String"

ID: api/graphql-field-argument-type-mismatch

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2023-08-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
GraphQL June 2018 active
Apollo Server v4 active
graphql-js v16 active

Root Cause

The client sent a GraphQL query or mutation with an argument value of the wrong type (e.g., string instead of integer).

generic

中文

客户端发送的 GraphQL 查询或变更中使用了错误类型的参数值(例如字符串而非整数)。

Official Documentation

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

Workarounds

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

中文步骤

  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.

Dead Ends

Common approaches that don't work:

  1. 90% fail

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

  2. 60% fail

    Clients unaware of the custom scalar may still send strings.