You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GraphQL查询在GraphiQL可用但Postman报错“no operation provided”

解决Postman执行GraphQL变更时"no operation provided"错误

常见原因及修复方案

1. 未指定operationName参数

你的mutation定义了名称CreateAnswer,Postman需要明确指定这个操作名,否则服务无法识别要执行的操作。

修复方法:
在Postman的请求体中,除了query和variables字段,添加operationName字段,完整请求体如下:

{
  "operationName": "CreateAnswer",
  "query": "mutation CreateAnswer($answer: NewAnswer!) { createAnswer(input: $answer) { id key value } }",
  "variables": {
    "answer": {
      "key": "this3",
      "value": "that"
    }
  }
}

2. 请求头或请求格式错误

确保Postman的请求配置符合以下要求:

  • 请求方法设置为POST
  • 请求头添加Content-Type: application/json
  • 请求体选择raw格式,并切换为JSON类型,不要使用form-data等其他格式

3. 服务端配置校验问题

部分Golang GraphQL库在处理POST请求时会严格校验operationName字段,而GraphiQL会自动填充该参数。如果是服务端配置导致的问题,可调整GraphQL handler的校验逻辑,允许未指定operationName的请求(但从规范角度,建议始终携带该参数)。

验证步骤

  • 复制上述完整JSON请求体到Postman的raw JSON区域
  • 确认请求方法、请求头和请求体格式正确
  • 重新发送请求,即可正常执行mutation操作

内容的提问来源于stack exchange,提问作者Yoker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 10:36:51