hydra
v3
v3
  • Hydra
  • Hydra CLI
  • Hydra Indexer
  • Hydra Indexer Gateway
  • Hydra Processor
  • Hydra Typegen
  • Overview
    • Query Node Manifest
    • Graphql Queries
    • Pagination
    • Sorting
    • Mappings
      • Context interfaces
      • Mapping Filters
      • Mapping Types
    • Schema
      • The Goodies
      • Entities
      • Enums
      • Interfaces
      • Algebraic types
      • Full-text queries
      • Entity Relationships
      • Cross filtering
      • Variant relations
    • Architecture
  • Install Hydra
  • Migration to Hydra v2
  • What's new in Hydra v3
  • FAQ
  • Quickstart
Powered by GitBook
On this page
  • StoreContext
  • BlockContext
  • EventContext
  • ExtrinsicContext

Was this helpful?

  1. Overview
  2. Mappings

Context interfaces

A closer look at the Context types passed to the mappers

StoreContext

StoreContext is a type indicating that the mappings context is aware of the store property of type DatabaseManager . DatabaseManager is a wrapper interface incapsulating the persistence layer:

export interface StoreContext {
  store: DatabaseManager
}

/**
 * Database access interface. Use typeorm transactional entity manager to perform get/save/remove operations.
 */
export default interface DatabaseManager {
  /**
   * Save given entity instance, if entity is exists then just update
   * @param entity
   */
  save<T>(entity: DeepPartial<T>): Promise<void>;

  /**
   * Removes a given entity from the database.
   * @param entity: DeepPartial<T>
   */
  remove<T>(entity: DeepPartial<T>): Promise<void>;

  /**
   * Finds first entity that matches given options.
   * @param entity: T
   * @param options: FindOneOptions<T>
   */
  get<T>(entity: { new (...args: any[]): T }, options: FindOneOptions<T>): Promise<T | undefined>;

  /**
   * Finds entities that match given options.
   * @param entity: T
   * @param options: FindOneOptions<T>
   */
  getMany<T>(entity: { new (...args: any[]): T }, options: FindOneOptions<T>): Promise<T[]>;
}

BlockContext

Contains information about the block: timestamp, height, hash, as well as the list of all events and extrinsics.

export interface BlockContext {
  block: SubstrateBlock
}

EventContext

Contains info about the event being handled and the extrinsic emitted the event. Since some events are emitted without an extrinsic (system event), the extrinsic parameter is optional.

export interface EventContext extends BlockContext {
  event: SubstrateEvent
  extrinsic?: SubstrateExtrinsic
}

ExtrinsicContext

Passed to extrinsic handlers. Similar to EventContext but extrinsic is now a mandatory property.

export interface ExtrinsicContext extends BlockContext {
  event: SubstrateEvent
  extrinsic: SubstrateExtrinsic
}
PreviousMappingsNextMapping Filters

Last updated 3 years ago

Was this helpful?