diff --git a/website/pages/en/developing/assemblyscript-api.mdx b/website/pages/en/developing/assemblyscript-api.mdx index b8d735f029d6..f618606334cf 100644 --- a/website/pages/en/developing/assemblyscript-api.mdx +++ b/website/pages/en/developing/assemblyscript-api.mdx @@ -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: