From ac01bb374e75e8f0db50e99d369c94bfbddf2906 Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Mon, 10 Jun 2024 19:36:19 +0330 Subject: [PATCH] Added subgraph domain field support --- .eslintrc.js | 9 +-------- .prettierrc.json | 5 +++++ .../subgraph/graphql-client-adapter.service.ts | 16 +++++++++++++++- src/modules/subgraph/subgraph.module.ts | 5 +++-- 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 .prettierrc.json diff --git a/.eslintrc.js b/.eslintrc.js index 059ea29..f8c69a3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -54,13 +54,6 @@ module.exports = { }, }, ], - "prettier/prettier": [ - "error", - { - "singleQuote": true, - "trailingComma": "all", - "arrowParens": "avoid" - } - ] + "prettier/prettier": [ "error" ] }, }; diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..9be2883 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "arrowParens": "avoid" +} \ No newline at end of file diff --git a/src/modules/subgraph/graphql-client-adapter.service.ts b/src/modules/subgraph/graphql-client-adapter.service.ts index b704374..374d4fa 100644 --- a/src/modules/subgraph/graphql-client-adapter.service.ts +++ b/src/modules/subgraph/graphql-client-adapter.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import axios from 'axios'; export type SubgraphBalanceChangeEntity = { @@ -12,6 +13,11 @@ export type SubgraphBalanceChangeEntity = { }; @Injectable() export class GraphqlClientAdapterService { + private origin; + constructor(readonly configService: ConfigService) { + this.origin = + this.configService.get('SUBGRAPH_DOMAIN') || 'https://giveth.io'; + } async getBalanceChanges(params: { subgraphUrl: string; contractAddress: string; @@ -56,7 +62,15 @@ export class GraphqlClientAdapterService { } `; - const result = await axios.post(subgraphUrl, { query }); + const result = await axios.post( + subgraphUrl, + { query }, + { + headers: { + Origin: this.origin, + }, + }, + ); const { balanceChanges, _meta } = result.data.data; return { balanceChanges, diff --git a/src/modules/subgraph/subgraph.module.ts b/src/modules/subgraph/subgraph.module.ts index e24abf3..f8475ad 100644 --- a/src/modules/subgraph/subgraph.module.ts +++ b/src/modules/subgraph/subgraph.module.ts @@ -1,9 +1,10 @@ import { Module } from '@nestjs/common'; +import { ConfigModule, ConfigService } from '@nestjs/config'; import { GraphqlClientAdapterService } from 'src/modules/subgraph/graphql-client-adapter.service'; @Module({ - imports: [], - providers: [GraphqlClientAdapterService], + imports: [ConfigModule], + providers: [GraphqlClientAdapterService, ConfigService], exports: [GraphqlClientAdapterService], }) export class SubgraphModule {}