Skip to content

Commit 6844519

Browse files
committed
Added graphql @Bind doc
1 parent b942c01 commit 6844519

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/graphql/reference/bind.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: bind
3+
parent: GraphQL
4+
nav_order: 130
5+
layout: default
6+
---
7+
8+
## GraphQL Directive: `@bind`
9+
10+
The `@bind` directive is used to associate a field in your GraphQL query or schema with a SPARQL expression. Note that [`@pattern`](pattern) is for graph patterns rather than expressions.
11+
As bind only produces a single value from the input binding, its cardinality defaults to `@one`. Explicitly adding `@many` will cause the value to be wrapped in an array.
12+
13+
### Purpose
14+
15+
The directive allows one to compute values for a field based on variables that are mentioned in any ancestor node. The most common use is to expose an entity's IRI (or blank node) as an `id` field.
16+
17+
#### Usage
18+
19+
The `@bind` directive supports the following arguments:
20+
21+
- **`of`** (`String`): The value of `of` is a SPARQL expression. The mentioned variables must be defined in any ancestor or at the annotated field.
22+
- **`as`** (`String`): (optional) The variable for the expression result can be specified explicitly (by default an internal name is generated).
23+
- **`target`** (`Boolean`): (optional, defaults to `true`) Whether the `@bind` expression produces the target values for the annotated field.
24+
If `target` is `false` then the field introduces the specified variable that can be referenced from descendants without it becoming a target of the field.
25+
Multiple target variables are combined into a tuple based on the order of their appearance.
26+
27+
#### Example
28+
29+
Here is an example demonstrating how to define a `MusicalArtists` field using the `@bind` directive:
30+
31+
```graphql
32+
{
33+
MusicalArtists @pattern(of: "?s a <http://dbpedia.org/ontology/MusicalArtist>") {
34+
id @bind(of: "?s")
35+
}
36+
}
37+
```
38+

0 commit comments

Comments
 (0)