mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-08 12:28:05 +00:00
Implement Block_height input and definition for custom scalar BigDecimal (#91)
This commit is contained in:
parent
2a204d8a32
commit
8b5d408f77
@ -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'
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user