@verax-attestation-registry/verax-sdk
Version:
Verax Attestation Registry SDK to interact with the subgraph and the contracts
48 lines • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const graphClientHelper_1 = require("../utils/graphClientHelper");
class BaseDataMapper {
constructor(_conf, _web3Client, _veraxSdk, _walletClient) {
this.conf = _conf;
this.web3Client = _web3Client;
this.veraxSdk = _veraxSdk;
this.walletClient = _walletClient;
}
async findOneById(id) {
const query = `query get_${this.typeName} { ${this.typeName}(id: "${id}") ${this.gqlInterface} }`;
const { data, status } = await (0, graphClientHelper_1.subgraphCall)(query, this.conf.subgraphUrl);
if (status != 200) {
throw new Error(`Error(s) while fetching ${this.typeName}`);
}
return data?.data ? data.data[`${this.typeName}`] : undefined;
}
async findBy(first, skip, where, orderBy, orderDirection) {
const query = `
query get_${this.typeName}s{
${this.typeName}s(
first: ${first || 100}
skip: ${skip || 0}
where: ${where ? (0, graphClientHelper_1.stringifyWhereClause)(where) : null}
orderBy: ${orderBy || null}
orderDirection: ${orderDirection || null}
)
${this.gqlInterface}
}
`;
const { data, status } = await (0, graphClientHelper_1.subgraphCall)(query, this.conf.subgraphUrl);
if (status != 200) {
throw new Error(`Error(s) while fetching ${this.typeName}s`);
}
return data?.data ? data.data[`${this.typeName}s`] : [];
}
async findTotalCount() {
const query = `query get_${this.typeName}_Counter { counters { ${this.typeName}s } }`;
const { data, status } = await (0, graphClientHelper_1.subgraphCall)(query, this.conf.subgraphUrl);
if (status != 200) {
throw new Error(`Error(s) while fetching total count of ${this.typeName}s`);
}
return data?.data ? data.data["counters"][0][`${this.typeName}s`] : 0;
}
}
exports.default = BaseDataMapper;
//# sourceMappingURL=BaseDataMapper.js.map