Skip to content

Commit

Permalink
Add 'Handling of entities with identical IDs' section (#597)
Browse files Browse the repository at this point in the history
* Add 'handling of entities with identical IDs' section

* Update handling of entities with identical IDs

* Updated to include if no data is passed into field
  • Loading branch information
marcusrein authored Feb 14, 2024
1 parent 33d2436 commit 45280e6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions website/pages/en/developing/creating-a-subgraph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,14 @@ Every entity has to have an `id` that is unique among all entities of the same t

We provide the [Graph Typescript Library](https://github.com/graphprotocol/graph-ts) which contains utilities for interacting with the Graph Node store and conveniences for handling smart contract data and entities. You can use this library in your mappings by importing `@graphprotocol/graph-ts` in `mapping.ts`.

### Handling of entities with identical IDs

When creating and saving a new entity, if an entity with the same ID already exists, the properties of the new entity are always preferred during the merge process. This means that the existing entity will be updated with the values from the new entity.

If a null value is intentionally set for a field in the new entity with the same ID, the existing entity will be updated with the null value.

If no value is set for a field in the new entity with the same ID, the field will result in null as well.

## Code Generation

In order to make it easy and type-safe to work with smart contracts, events and entities, the Graph CLI can generate AssemblyScript types from the subgraph's GraphQL schema and the contract ABIs included in the data sources.
Expand Down

0 comments on commit 45280e6

Please sign in to comment.