From f0447513e2826ab67db4f7b043cb38d96d224f2c Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Fri, 3 May 2024 13:25:45 +0300 Subject: [PATCH] feat: curlize all subgraph queries (dump to log) --- package.json | 1 + src/lib/utils/data-providers-clients.ts | 17 ++++++++++------- src/lib/utils/http-client.ts | 9 ++++++++- yarn.lock | 5 +++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index bb1f62ef..795516e9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/utils/data-providers-clients.ts b/src/lib/utils/data-providers-clients.ts index 51d19bac..dd80c0d3 100644 --- a/src/lib/utils/data-providers-clients.ts +++ b/src/lib/utils/data-providers-clients.ts @@ -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, +); diff --git a/src/lib/utils/http-client.ts b/src/lib/utils/http-client.ts index 96a3dd3e..ed3fff04 100644 --- a/src/lib/utils/http-client.ts +++ b/src/lib/utils/http-client.ts @@ -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; @@ -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 || {}), @@ -77,5 +82,7 @@ export const constructHttpClient = (options?: Options) => { ...(options?.retryOptions || {}), }); + if (shouldCurlize) axiosCurlirize(client); + return client; }; diff --git a/yarn.lock b/yarn.lock index d601d0b6..ef8de50d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"