The documentation you are viewing is for Dapr v1.6 which is an older version of Dapr. For up-to-date documentation, see the latest version.

GraphQL 绑定规范

有关 GraphQL 绑定组件的详细文档

配置

要设置 GraphQL 绑定,请创建一个类型为 bindings.graphql 的组件。 请参阅本指南,了解如何创建和应用绑定配置。 为了将常规配置设置(例如 endpoint)与 header 分开,在 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

元数据字段规范

字段 必填 绑定支持 详情 示例
endpoint 输出 GraphQL endpoint 详细信息请参阅此处 "http://localhost:4000/graphql/graphql"
header:[HEADERKEY] 输出 GraphQL header. 指定 name 中的 header 键和 value 中的 header 值。 "no-cache" (见上文)

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 } }`},
}

相关链接