Skip to content

Commit

Permalink
feat: curlize all subgraph queries (dump to log)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshchur committed May 3, 2024
1 parent 77506b6 commit f044751
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@types/pg": "^8.6.1",
"axios": "0.24.0",
"axios-cache-adapter": "^2.7.3",
"axios-curlirize": "1.3.7",
"axios-rate-limit": "^1.3.0",
"axios-retry": "^3.2.4",
"bignumber.js": "9.0.1",
Expand Down
17 changes: 10 additions & 7 deletions src/lib/utils/data-providers-clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export const covalentClient = constructHttpClient({
},
});

export const thegraphClient = constructHttpClient({
axiosConfig: {
timeout: 30_000,
},
rateLimitOptions: {
maxRPS: 20,
export const thegraphClient = constructHttpClient(
{
axiosConfig: {
timeout: 30_000,
},
rateLimitOptions: {
maxRPS: 20,
},
},
});
true,
);
9 changes: 8 additions & 1 deletion src/lib/utils/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import axiosRetry, {
} from 'axios-retry';
import * as _rateLimit from 'axios-rate-limit';
import { IAxiosCacheAdapterOptions, setupCache } from 'axios-cache-adapter';
// @ts-ignore // was yelling at missing types, then an issue with ES mods
const axiosCurlirize = require('axios-curlirize');

type rateLimitOptions = {
maxRequests?: number;
Expand Down Expand Up @@ -45,7 +47,10 @@ type Options = {
cacheOptions?: IAxiosCacheAdapterOptions;
};

export const constructHttpClient = (options?: Options) => {
export const constructHttpClient = (
options?: Options,
shouldCurlize = false,
) => {
const httpsAgent = new https.Agent({
keepAlive: true,
...(options?.httpsAgent || {}),
Expand Down Expand Up @@ -77,5 +82,7 @@ export const constructHttpClient = (options?: Options) => {
...(options?.retryOptions || {}),
});

if (shouldCurlize) axiosCurlirize(client);

return client;
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,11 @@ axios-cache-adapter@^2.7.3:
cache-control-esm "1.0.0"
md5 "^2.2.1"

axios-curlirize@1.3.7:
version "1.3.7"
resolved "https://registry.yarnpkg.com/axios-curlirize/-/axios-curlirize-1.3.7.tgz#0153c51a5af0e92370169daea33f234d588baad1"
integrity sha512-csSsuMyZj1dv1fL0zRPnDAHWrmlISMvK+wx9WJI/igRVDT4VMgbf2AVenaHghFLfI1nQijXUevYEguYV6u5hjA==

axios-rate-limit@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/axios-rate-limit/-/axios-rate-limit-1.3.0.tgz#03241d24c231c47432dab6e8234cfde819253c2e"
Expand Down

0 comments on commit f044751

Please sign in to comment.