Skip to content

Commit

Permalink
Added subgraph domain field support
Browse files Browse the repository at this point in the history
  • Loading branch information
aminlatifi committed Jun 10, 2024
1 parent c21d86e commit ac01bb3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
9 changes: 1 addition & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ module.exports = {
},
},
],
"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid"
}
]
"prettier/prettier": [ "error" ]
},
};
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid"
}
16 changes: 15 additions & 1 deletion src/modules/subgraph/graphql-client-adapter.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import axios from 'axios';

export type SubgraphBalanceChangeEntity = {
Expand All @@ -12,6 +13,11 @@ export type SubgraphBalanceChangeEntity = {
};
@Injectable()
export class GraphqlClientAdapterService {
private origin;
constructor(readonly configService: ConfigService) {
this.origin =
this.configService.get<string>('SUBGRAPH_DOMAIN') || 'https://giveth.io';
}
async getBalanceChanges(params: {
subgraphUrl: string;
contractAddress: string;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/modules/subgraph/subgraph.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit ac01bb3

Please sign in to comment.