问题描述
我尝试在 graphql 中使用变量,但似乎不可能用application/graphql"发送变量.
我是否应该继续使用 Content-Type: 'application/json'?
http://graphql.org/learn/serving-over-http/#post-request
标准的 GraphQL POST 请求应使用 application/json 内容类型,并包含以下形式的 JSON 编码主体:
{询问": "...","操作名称": "...","变量": { "myVariable": "someValue", ... }}
operationName 和 variables 是可选字段.仅当查询中存在多个操作时才需要 operationName.
除上述之外,我们建议支持另外两种情况:
...如果存在application/graphql"Content-Type 标头,则将 HTTP POST 正文内容视为 GraphQL 查询字符串.
在我的理解中,Content-Type: "application/graphql"
是无变量查询的简写.
所以我的回答是是的,如果我想使用变量字段,我必须使用 Content-Type: "application/json"
标头
I've tried to use variables with graphql,but it seems impossible to send variables with 'application/graphql'.
Should i have to move on to Content-Type: 'application/json'?
http://graphql.org/learn/serving-over-http/#post-request
{
"query": "...",
"operationName": "...",
"variables": { "myVariable": "someValue", ... }
}
In my understanding, Content-Type: "application/graphql"
is Shorthand for Querying without variables.
So my answer is "Yes, If I want to use variables field, I have to use Content-Type: "application/json"
header
这篇关于在 GraphQL 中,我可以使用 Content-Type: application/graphql 发送变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!