Implement subgraph store host API (#35)

* Implement store get api without blockHash and blockNumber

* Pass database instance to GraphWatcher

* Implement store set without block data

* Store blockHash and blockNumber in database entity table

* Implement getting entity in subgraph from store.get

* Add block data present in postgraphile

* Pass db and context to instantiate method in tests

* GQL API in graph-test-watcher to test store.set

* Remove contract address from subgraph file

* Fix block in dummy event data

* Pass just blockHash to get an entity from the database

* Review changes and add TODOs

Co-authored-by: prathamesh <prathamesh.musale0@gmail.com>
This commit is contained in:
2021-12-28 16:08:05 +05:30
committed by nabarun
co-authored by prathamesh
parent 43d64f9e4b
commit 83775608ec
23 changed files with 486 additions and 79 deletions
@@ -4,36 +4,37 @@ import {
Example1,
Test
} from '../generated/Example1/Example1';
// import { ExampleEntity } from '../generated/schema';
import { ExampleEntity } from '../generated/schema';
export function handleTest (event: Test): void {
log.debug('event.address: {}', [event.address.toHexString()]);
log.debug('event.params.param1: {}', [event.params.param1]);
log.debug('event.params.param2: {}', [event.params.param2.toString()]);
log.debug('event.block.hash: {}', [event.block.hash.toHexString()]);
log.debug('event.block.stateRoot: {}', [event.block.stateRoot.toHexString()]);
// Entities can be loaded from the store using a string ID; this ID
// needs to be unique across all entities of the same type
// let entity = ExampleEntity.load(event.transaction.from.toHex());
let entity = ExampleEntity.load(event.transaction.from.toHex());
// Entities only exist after they have been saved to the store;
// `null` checks allow to create entities on demand
// if (!entity) {
// entity = new ExampleEntity(event.transaction.from.toHex());
if (!entity) {
entity = new ExampleEntity(event.transaction.from.toHex());
// // Entity fields can be set using simple assignments
// entity.count = BigInt.fromI32(0);
// }
// Entity fields can be set using simple assignments
entity.count = BigInt.fromString('0');
}
// BigInt and BigDecimal math are supported
// entity.count = entity.count + BigInt.fromI32(1)
entity.count = entity.count + BigInt.fromString('1');
// Entity fields can be set based on event parameters
// entity.param1 = event.params.param1;
// entity.param2 = event.params.param2;
entity.param1 = event.params.param1;
entity.param2 = event.params.param2;
// Entities can be written to the store with `.save()`
// entity.save();
entity.save();
// Note: If a handler doesn't require existing field values, it is faster
// _not_ to load the entity from the store. Instead, create it fresh with