Add support for subgraph schema data types (#46)

* Fix packages build

* Add support for boolean type in subgraph schema

* Add BigDecimal fromString and toString implementation

* Add implementation for subgraph Bytes type

* Implement enum type for subgraph schema

* Add implementation for subgraph schema BigDecimal type

* JSON stringify and parse entity data for auto-diff
This commit is contained in:
nikugogoi
2021-12-28 16:08:05 +05:30
committed by nabarun
parent 73dcb882a6
commit 47cef8d5d7
13 changed files with 346 additions and 162 deletions
@@ -30,8 +30,12 @@ export function handleTest (event: Test): void {
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.paramString = event.params.param1;
entity.paramInt = event.params.param2;
entity.paramBoolean = true;
entity.paramBytes = event.address;
entity.paramEnum = 'choice1';
entity.paramBigDecimal = BigDecimal.fromString('123');
// Entities can be written to the store with `.save()`
entity.save();
@@ -129,6 +133,27 @@ export function testStringToH160 (): string {
return res;
}
export function testBigDecimalToString (): string {
log.debug('In test bigDecimalToString', []);
const bigInt = BigInt.fromString('1000000000000000000');
const bigDecimal = bigInt.toBigDecimal();
const res = bigDecimal.toString();
log.debug('typeConversion.bigIntToString from hex result: {}', [res]);
return res;
}
export function testBigDecimalFromString (value: string): string {
log.debug('In test bigDecimal.fromString', []);
const bigDecimal = BigDecimal.fromString(value);
const res = bigDecimal.toString();
log.debug('bigDecimal.FromString result: {}', [res]);
return res;
}
export function testBigDecimalDividedBy (): string {
log.debug('In test bigDecimal.dividedBy', []);
@@ -187,11 +212,10 @@ export function testBigIntDividedBy (): string {
return res.toString();
}
export function testBigIntFromString (): string {
export function testBigIntFromString (value: string): string {
log.debug('In test bigInt.fromString', []);
const string = '123';
const bigInt = BigInt.fromString(string);
const bigInt = BigInt.fromString(value);
const res = bigInt.toString();
log.debug('bigInt.FromString result: {}', [res]);