Skip to content

Commit 4f367f9

Browse files
authored
feat: derived loader docs (#404)
1 parent 1dcb3ba commit 4f367f9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

website/pages/en/developing/assemblyscript-api.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,33 @@ if (transfer == null) {
298298

299299
> Note: If there is no entity created in the given block, `loadInBlock` will return `null` even if there is an entity with the given ID in the store.
300300
301+
#### Looking up derived entities
302+
303+
As of `graph-node` v0.31.0, `@graphprotocol/graph-ts` v0.31.0 and `@graphprotocol/graph-cli` v0.51.0 the `loadRelated` method is available.
304+
305+
This enables loading derived entity fields from within an event handler. For example, given the following schema:
306+
307+
```graphql
308+
type Token @entity {
309+
id: ID!
310+
holder: Holder!
311+
color: String
312+
}
313+
314+
type Holder @entity {
315+
id: ID!
316+
tokens: [Token!]! @derivedFrom(field: "holder")
317+
}
318+
```
319+
320+
The following code will load the `Token` entity that the `Holder` entity was derived from:
321+
322+
```typescript
323+
let holder = Holder.load('test-id')
324+
// Load the Token entity that the Holder entity was derived from
325+
let token = holder.tokens.load()
326+
```
327+
301328
#### Updating existing entities
302329

303330
There are two ways to update an existing entity:

0 commit comments

Comments
 (0)