GraphQL binding spec

Detailed documentation on the GraphQL binding component

Component format

To setup GraphQL binding create a component of type bindings.graphql. See this guide on how to create and apply a binding configuration. To separate normal config settings (e.g. endpoint) from headers, “header:” is used a prefix on the header names.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: example.bindings.graphql
  5. spec:
  6. type: bindings.graphql
  7. version: v1
  8. metadata:
  9. - name: endpoint
  10. value: "http://localhost:8080/v1/graphql"
  11. - name: header:x-hasura-access-key
  12. value: "adminkey"
  13. - name: header:Cache-Control
  14. value: "no-cache"

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.

Spec metadata fields

FieldRequiredBinding supportDetailsExample
endpointYOutputGraphQL endpoint string See here for more detailshttp://localhost:4000/graphql/graphql
header:[HEADERKEY]NOutputGraphQL header. Specify the header key in the name, and the header value in the value.“no-cache” (see above)
variable:[VARIABLEKEY]NOutputGraphQL query variable. Specify the variable name in the name, and the variable value in the value.“123” (see below)

Endpoint and Header format

The GraphQL binding uses GraphQL client internally.

Binding support

This component supports output binding with the following operations:

  • query
  • mutation

query

The query operation is used for query statements, which returns the metadata along with data in a form of an array of row values.

Request

  1. in := &dapr.InvokeBindingRequest{
  2. Name: "example.bindings.graphql",
  3. Operation: "query",
  4. Metadata: map[string]string{ "query": `query { users { name } }`},
  5. }

To use a query that requires query variables, add a key-value pair to the metadata map, wherein every key corresponding to a query variable is the variable name prefixed with variable:

  1. in := &dapr.InvokeBindingRequest{
  2. Name: "example.bindings.graphql",
  3. Operation: "query",
  4. Metadata: map[string]string{
  5. "query": `query HeroNameAndFriends($episode: string!) { hero(episode: $episode) { name } }`,
  6. "variable:episode": "JEDI",
  7. }