mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-02-02 16:22:50 +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);
|
const subgraphTypeDefsString = print(modifiedSchemaDocument);
|
||||||
this._composer.addTypeDefs(subgraphTypeDefsString);
|
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.
|
// Add subgraph-schema entity queries to the schema composer.
|
||||||
this._addSubgraphSchemaQueries(subgraphTypeDefs);
|
this._addSubgraphSchemaQueries(subgraphTypeDefs);
|
||||||
}
|
}
|
||||||
@ -178,7 +188,7 @@ export class Schema {
|
|||||||
type: this._composer.getAnyTC(subgraphType).NonNull,
|
type: this._composer.getAnyTC(subgraphType).NonNull,
|
||||||
args: {
|
args: {
|
||||||
id: 'String!',
|
id: 'String!',
|
||||||
blockHash: 'String!'
|
block: 'Block_height'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import BigInt from 'apollo-type-bigint';
|
import BigInt from 'apollo-type-bigint';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
import Decimal from 'decimal.js';
|
||||||
|
import { GraphQLScalarType } from 'graphql';
|
||||||
|
|
||||||
import { ValueResult, BlockHeight, StateKind } from '@vulcanize/util';
|
import { ValueResult, BlockHeight, StateKind } from '@vulcanize/util';
|
||||||
|
|
||||||
@ -23,6 +25,19 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return {
|
return {
|
||||||
BigInt: new BigInt('bigInt'),
|
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: {
|
Event: {
|
||||||
__resolveType: (obj: any) => {
|
__resolveType: (obj: any) => {
|
||||||
assert(obj.__typename);
|
assert(obj.__typename);
|
||||||
|
Loading…
Reference in New Issue
Block a user