Skip to content

Commit

Permalink
feat: derived loader docs (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj authored Jun 15, 2023
1 parent 1dcb3ba commit 4f367f9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions website/pages/en/developing/assemblyscript-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,33 @@ if (transfer == null) {

> 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.
#### Looking up derived entities

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.

This enables loading derived entity fields from within an event handler. For example, given the following schema:

```graphql
type Token @entity {
id: ID!
holder: Holder!
color: String
}

type Holder @entity {
id: ID!
tokens: [Token!]! @derivedFrom(field: "holder")
}
```

The following code will load the `Token` entity that the `Holder` entity was derived from:

```typescript
let holder = Holder.load('test-id')
// Load the Token entity that the Holder entity was derived from
let token = holder.tokens.load()
```

#### Updating existing entities

There are two ways to update an existing entity:
Expand Down

0 comments on commit 4f367f9

Please sign in to comment.