Skip to content

Commit

Permalink
Merge pull request #6 from Giveth/hotfix/subgraph-domain
Browse files Browse the repository at this point in the history
Support for domain/origin header in subgraph queries
  • Loading branch information
aminlatifi authored Jun 10, 2024
2 parents 9425c00 + 58be4e0 commit 6854cb7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ dist

# TernJS port file
.tern-port

# IDE
.idea
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid",
"printWidth": 80
}
7 changes: 3 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import path from 'path';
import logger from './logger';

dotenv.config({
path: path.resolve(
__dirname,
`../config/${process.env.NODE_ENV || ''}.env`,
),
path: path.resolve(__dirname, `../config/${process.env.NODE_ENV || ''}.env`),
});

if (!process.env.GIVPOWER_CONTRACT_ADDRESS) {
Expand All @@ -23,6 +20,7 @@ const config: {
nodeUrl: string;
pollPeriodSecond: number;
subgraphEndpoint: string;
subgraphDomain: string;
givpowerContractAddress: string;
privateKey: string;
unlockPerTransaction: number;
Expand All @@ -32,6 +30,7 @@ const config: {
nodeUrl: process.env.NODE_URL || 'https://rpc.gnosischain.com/',
pollPeriodSecond: Number(process.env.POLL_PERIOD_SECOND) || 60,
subgraphEndpoint: process.env.SUBGRAPH_ENDPOINT,
subgraphDomain: process.env.SUBGRAPH_DOMAIN || 'https://giveth.io',
givpowerContractAddress: process.env.GIVPOWER_CONTRACT_ADDRESS,
privateKey: process.env.PRIVATE_KEY || '',
unlockPerTransaction: Number(process.env.UNLOCK_PER_TRANSACTION) || 1,
Expand Down
22 changes: 14 additions & 8 deletions src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ const getSubgraphData = async () => {
query getUnlockablePositions($lastBlockTimeStamp: Int!) {
tokenLocks(
first: 100
where: {
unlocked: false
unlockableAt_lte: $lastBlockTimeStamp
}
where: { unlocked: false, unlockableAt_lte: $lastBlockTimeStamp }
orderBy: untilRound
orderDirection: asc
) {
Expand All @@ -85,11 +82,20 @@ const getSubgraphData = async () => {
`;

try {
subgraphResponse = await request(config.subgraphEndpoint, query, {
lastBlockTimeStamp: currentBlock.timestamp,
});
console.log('subgraphEndpoint', config.subgraphEndpoint);
subgraphResponse = await request(
config.subgraphEndpoint,
query,
{
lastBlockTimeStamp: currentBlock.timestamp,
},
{ origin: config.subgraphDomain },
);
} catch (e) {
logger.error('Error getting locked positions from subgraph', e);
logger.error(
'Error getting locked positions from subgraph',
JSON.stringify(e, null, 2),
);
return undefined;
}

Expand Down

0 comments on commit 6854cb7

Please sign in to comment.