Skip to content

Commit 58be4e0

Browse files
committed
Support for domain/origin header in subgraph queries
1 parent 9425c00 commit 58be4e0

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ dist
106106

107107
# TernJS port file
108108
.tern-port
109+
110+
# IDE
111+
.idea

.prettierrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"useTabs": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"arrowParens": "avoid",
6+
"printWidth": 80
7+
}

src/config.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import path from 'path';
33
import logger from './logger';
44

55
dotenv.config({
6-
path: path.resolve(
7-
__dirname,
8-
`../config/${process.env.NODE_ENV || ''}.env`,
9-
),
6+
path: path.resolve(__dirname, `../config/${process.env.NODE_ENV || ''}.env`),
107
});
118

129
if (!process.env.GIVPOWER_CONTRACT_ADDRESS) {
@@ -23,6 +20,7 @@ const config: {
2320
nodeUrl: string;
2421
pollPeriodSecond: number;
2522
subgraphEndpoint: string;
23+
subgraphDomain: string;
2624
givpowerContractAddress: string;
2725
privateKey: string;
2826
unlockPerTransaction: number;
@@ -32,6 +30,7 @@ const config: {
3230
nodeUrl: process.env.NODE_URL || 'https://rpc.gnosischain.com/',
3331
pollPeriodSecond: Number(process.env.POLL_PERIOD_SECOND) || 60,
3432
subgraphEndpoint: process.env.SUBGRAPH_ENDPOINT,
33+
subgraphDomain: process.env.SUBGRAPH_DOMAIN || 'https://giveth.io',
3534
givpowerContractAddress: process.env.GIVPOWER_CONTRACT_ADDRESS,
3635
privateKey: process.env.PRIVATE_KEY || '',
3736
unlockPerTransaction: Number(process.env.UNLOCK_PER_TRANSACTION) || 1,

src/subgraph.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ const getSubgraphData = async () => {
6464
query getUnlockablePositions($lastBlockTimeStamp: Int!) {
6565
tokenLocks(
6666
first: 100
67-
where: {
68-
unlocked: false
69-
unlockableAt_lte: $lastBlockTimeStamp
70-
}
67+
where: { unlocked: false, unlockableAt_lte: $lastBlockTimeStamp }
7168
orderBy: untilRound
7269
orderDirection: asc
7370
) {
@@ -85,11 +82,20 @@ const getSubgraphData = async () => {
8582
`;
8683

8784
try {
88-
subgraphResponse = await request(config.subgraphEndpoint, query, {
89-
lastBlockTimeStamp: currentBlock.timestamp,
90-
});
85+
console.log('subgraphEndpoint', config.subgraphEndpoint);
86+
subgraphResponse = await request(
87+
config.subgraphEndpoint,
88+
query,
89+
{
90+
lastBlockTimeStamp: currentBlock.timestamp,
91+
},
92+
{ origin: config.subgraphDomain },
93+
);
9194
} catch (e) {
92-
logger.error('Error getting locked positions from subgraph', e);
95+
logger.error(
96+
'Error getting locked positions from subgraph',
97+
JSON.stringify(e, null, 2),
98+
);
9399
return undefined;
94100
}
95101

0 commit comments

Comments
 (0)