Skip to content

feat: derived loader docs #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on this comment it is available graphprotocol/graph-tooling#1190 (comment) in graph-node


Given a derived entity type, yuo can load the entity field was derived from. 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