GraphQL 绑定说明
GraphQL 绑定组件的详细说明文档
组件格式
要配置 GraphQL 绑定,请创建一个类型为 bindings.graphql
的组件。请参阅本指南了解如何创建和应用绑定配置。为了区分普通配置(如 endpoint)和 headers,header 名称前需加上 “header:” 前缀。
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: example.bindings.graphql
spec:
type: bindings.graphql
version: v1
metadata:
- name: endpoint
value: "http://localhost:8080/v1/graphql"
- name: header:x-hasura-access-key
value: "adminkey"
- name: header:Cache-Control
value: "no-cache"
警告
上述示例中使用了明文字符串来存储 secret。建议使用 secret 存储来保护 secret,详情请参阅此处。元数据字段说明
字段 | 必需 | 绑定支持 | 详情 | 示例 |
---|---|---|---|---|
endpoint |
Y | 输出 | GraphQL endpoint 字符串,详情见此处 | "http://localhost:4000/graphql/graphql" |
header:[HEADERKEY] |
N | 输出 | GraphQL header。在 name 中指定 header 键,在 value 中指定 header 值。 |
"no-cache" (见上文) |
variable:[VARIABLEKEY] |
N | 输出 | GraphQL 查询变量。在 name 中指定变量名,在 value 中指定变量值。 |
"123" (见下文) |
Endpoint 和 Header 格式
GraphQL 绑定内部使用 GraphQL 客户端。
绑定支持
此组件支持以下操作的输出绑定:
query
mutation
query
query
操作用于执行查询语句,返回的结果包含元数据和数据,以行值数组的形式呈现。
请求
in := &dapr.InvokeBindingRequest{
Name: "example.bindings.graphql",
Operation: "query",
Metadata: map[string]string{ "query": `query { users { name } }`},
}
如果 query
需要查询变量,请在 metadata
映射中添加键值对,每个查询变量的键需以 variable:
为前缀。
in := &dapr.InvokeBindingRequest{
Name: "example.bindings.graphql",
Operation: "query",
Metadata: map[string]string{
"query": `query HeroNameAndFriends($episode: string!) { hero(episode: $episode) { name } }`,
"variable:episode": "JEDI",
}
相关链接
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.