在GraphQL中,我可以发送内容类型为application/graphql的变量吗? [英] in GraphQL, Can I send variables with Content-Type: application/graphql?

查看:113
本文介绍了在GraphQL中,我可以发送内容类型为application/graphql的变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将变量与graphql一起使用,但似乎无法通过'application/graphql'发送变量.

I've tried to use variables with graphql, but it seems impossible to send variables with 'application/graphql'.

我是否必须继续使用Content-Type:'application/json'?

Should i have to move on to Content-Type: 'application/json'?

推荐答案

http://graphql.org/learn/serving-over-http/#post-request

标准GraphQL POST请求应使用application/json内容类型,并包括以下形式的JSON编码主体:

A standard GraphQL POST request should use the application/json content type, and include a JSON-encoded body of the following form:

{
  "query": "...",
  "operationName": "...",
  "variables": { "myVariable": "someValue", ... }
}

operationName和变量是可选字段.仅当查询中存在多个操作时,才需要operationName.

operationName and variables are optional fields. operationName is only required if multiple operations are present in the query.

除上述内容外,我们建议支持其他两种情况:

In addition to the above, we recommend supporting two additional cases:

...如果存在"application/graphql" Content-Type标头,则将HTTP POST正文内容视为GraphQL查询字符串.

... If the "application/graphql" Content-Type header is present, treat the HTTP POST body contents as the GraphQL query string.

据我了解, Content-Type:"application/graphql" 是不带变量的查询的简写.

In my understanding, Content-Type: "application/graphql" is Shorthand for Querying without variables.

所以我的回答是是的,如果我想使用变量字段,则必须使用 Content-Type:"application/json" 标头

So my answer is "Yes, If I want to use variables field, I have to use Content-Type: "application/json" header

这篇关于在GraphQL中,我可以发送内容类型为application/graphql的变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆