【发布时间】:2021-02-23 19:45:01
【问题描述】:
我有一个 curl 脚本(作为真实代码的替代),它可以 POST 到我公司的 GraphQL endoint 并获取数据。它工作正常。
似乎也应该可以通过制作适当的请求来获取“模式”,但我还没有找到任何在 HTTP 级别上做到这一点的方法。
如果可能,卷曲会是什么样子(数据)?
除了“查询”之外,还有其他请求可以用来收集其他信息吗?
【问题讨论】:
标签: graphql
我有一个 curl 脚本(作为真实代码的替代),它可以 POST 到我公司的 GraphQL endoint 并获取数据。它工作正常。
似乎也应该可以通过制作适当的请求来获取“模式”,但我还没有找到任何在 HTTP 级别上做到这一点的方法。
如果可能,卷曲会是什么样子(数据)?
除了“查询”之外,还有其他请求可以用来收集其他信息吗?
【问题讨论】:
标签: graphql
您需要的主体与自省查询有关,但我认为您正在寻找类似的东西
introspection_query.json:
{
"query": "query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}"
}
然后你就可以了
curl -i -X POST http://localhost:8080/graphql -H "Content-Type: application/json" -d @introspection_query.json
可耻地从 https://gist.github.com/martinheld/9fe32b7e2c8fd932599d36e921a2a825
【讨论】: