mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 08:54:05 +00:00
Implement remaining graph-node host APIs for templates (#475)
* Implement createWithContext graph-node dataSource host API * Parse individual context entries * Implement graph-node dataSource context host API * Handle array type fields and refactor code * Resolve all values when parsing an array field * Fix wasm entity creation with array type fields * Required codegen changes
This commit is contained in:
@@ -101,7 +101,7 @@ export const instantiate = async (
|
||||
const dbEntity = await database.saveEntity(entityName, dbData);
|
||||
database.cacheUpdatedEntityByName(entityName, dbEntity);
|
||||
|
||||
// Update the in-memory subgraph state enabled
|
||||
// Update the in-memory subgraph state if enabled
|
||||
if (indexer.serverConfig.enableState) {
|
||||
// Prepare diff data for the entity update
|
||||
assert(indexer.getRelationsMap);
|
||||
@@ -698,10 +698,14 @@ export const instantiate = async (
|
||||
return Address.fromString(addressStringPtr);
|
||||
},
|
||||
'dataSource.context': async () => {
|
||||
// TODO: Implement use in data source templates.
|
||||
// https://thegraph.com/docs/en/developer/create-subgraph-hosted/#data-source-context
|
||||
assert(context.contractAddress);
|
||||
const contract = indexer.isWatchedContract(context.contractAddress);
|
||||
|
||||
return Entity.__new();
|
||||
if (!contract) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return database.toGraphContext(instanceExports, contract.context);
|
||||
},
|
||||
'dataSource.network': async () => {
|
||||
assert(dataSource);
|
||||
@@ -715,6 +719,18 @@ export const instantiate = async (
|
||||
assert(indexer.watchContract);
|
||||
assert(context.block);
|
||||
await indexer.watchContract(utils.getAddress(addressString), contractKind, true, Number(context.block.blockNumber));
|
||||
},
|
||||
'dataSource.createWithContext': async (name: number, params: number, dataSourceContext: number) => {
|
||||
const [addressStringPtr] = __getArray(params);
|
||||
const addressString = __getString(addressStringPtr);
|
||||
const contractKind = __getString(name);
|
||||
|
||||
const contextInstance = await Entity.wrap(dataSourceContext);
|
||||
const dbData = await database.fromGraphContext(instanceExports, contextInstance);
|
||||
|
||||
assert(indexer.watchContract);
|
||||
assert(context.block);
|
||||
await indexer.watchContract(utils.getAddress(addressString), contractKind, true, Number(context.block.blockNumber), dbData);
|
||||
}
|
||||
},
|
||||
json: {
|
||||
|
||||
Reference in New Issue
Block a user