Implement Block_height input and definition for custom scalar BigDecimal (#91)

This commit is contained in:
nikugogoi 2021-12-23 11:09:17 +05:30 committed by nabarun
parent 2a204d8a32
commit 8b5d408f77
2 changed files with 26 additions and 1 deletions

View File

@ -156,6 +156,16 @@ export class Schema {
const subgraphTypeDefsString = print(modifiedSchemaDocument);
this._composer.addTypeDefs(subgraphTypeDefsString);
// Create the Block_height input needed in subgraph queries.
const typeComposer = this._composer.createInputTC({
name: 'Block_height',
fields: {
hash: 'Bytes',
number: 'Int'
}
});
this._composer.addSchemaMustHaveType(typeComposer);
// Add subgraph-schema entity queries to the schema composer.
this._addSubgraphSchemaQueries(subgraphTypeDefs);
}
@ -178,7 +188,7 @@ export class Schema {
type: this._composer.getAnyTC(subgraphType).NonNull,
args: {
id: 'String!',
blockHash: 'String!'
block: 'Block_height'
}
};

View File

@ -5,6 +5,8 @@
import assert from 'assert';
import BigInt from 'apollo-type-bigint';
import debug from 'debug';
import Decimal from 'decimal.js';
import { GraphQLScalarType } from 'graphql';
import { ValueResult, BlockHeight, StateKind } from '@vulcanize/util';
@ -23,6 +25,19 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
return {
BigInt: new BigInt('bigInt'),
BigDecimal: new GraphQLScalarType({
name: 'BigDecimal',
description: 'BigDecimal custom scalar type',
parseValue (value) {
// value from the client
return new Decimal(value);
},
serialize (value: Decimal) {
// value sent to the client
return value.toFixed();
}
}),
Event: {
__resolveType: (obj: any) => {
assert(obj.__typename);