From e41e7155044b172ffd6e5d88e4253ad1494c4b44 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Wed, 11 Sep 2024 17:45:42 +0000 Subject: [PATCH] remove --- projects/mehulmathur16/package-lock.json | 6 ------ projects/mehulmathur16/package.json | 1 - projects/mehulmathur16/src/axios.ts | 4 ---- projects/mehulmathur16/src/dataLoader.ts | 4 ---- projects/mehulmathur16/src/index.ts | 7 ++----- projects/mehulmathur16/src/resolvers.ts | 7 ++----- 6 files changed, 4 insertions(+), 25 deletions(-) diff --git a/projects/mehulmathur16/package-lock.json b/projects/mehulmathur16/package-lock.json index dad6b0c..2e205b7 100644 --- a/projects/mehulmathur16/package-lock.json +++ b/projects/mehulmathur16/package-lock.json @@ -13,7 +13,6 @@ "dataloader": "^2.2.2", "fastify": "^4.28.1", "graphql": "^16.9.0", - "http": "^0.0.1-security", "mercurius": "^14.1.0", "mercurius-cache": "^6.0.1", "qs": "^6.13.0" @@ -969,11 +968,6 @@ "node": ">= 0.4" } }, - "node_modules/http": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", - "integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g==" - }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", diff --git a/projects/mehulmathur16/package.json b/projects/mehulmathur16/package.json index 71d33fe..b91f858 100644 --- a/projects/mehulmathur16/package.json +++ b/projects/mehulmathur16/package.json @@ -16,7 +16,6 @@ "dataloader": "^2.2.2", "fastify": "^4.28.1", "graphql": "^16.9.0", - "http": "^0.0.1-security", "mercurius": "^14.1.0", "mercurius-cache": "^6.0.1", "qs": "^6.13.0" diff --git a/projects/mehulmathur16/src/axios.ts b/projects/mehulmathur16/src/axios.ts index f4f6ca0..3841ae1 100644 --- a/projects/mehulmathur16/src/axios.ts +++ b/projects/mehulmathur16/src/axios.ts @@ -1,16 +1,12 @@ import axios from 'axios'; -import http from 'http' const qs = require('qs'); -const httpAgent = new http.Agent({ keepAlive: true }); - const axiosInstance = axios.create({ baseURL: 'http://localhost:3000', timeout: 1000, paramsSerializer: params => { return qs.stringify(params, { arrayFormat: 'repeat' }); }, - httpAgent, }); export default axiosInstance; diff --git a/projects/mehulmathur16/src/dataLoader.ts b/projects/mehulmathur16/src/dataLoader.ts index 9e8b932..ec8dec8 100644 --- a/projects/mehulmathur16/src/dataLoader.ts +++ b/projects/mehulmathur16/src/dataLoader.ts @@ -1,13 +1,9 @@ import DataLoader from 'dataloader'; -import http from 'http'; import axiosInstance from './axios'; -const httpAgent = new http.Agent({ keepAlive: true }); - export const userLoader = new DataLoader(async (ids) => { const response = await axiosInstance.get('/users', { params: { id: ids }, - httpAgent }); const users = response.data; const userMap = new Map(users.map((user: any) => [user.id, user])); diff --git a/projects/mehulmathur16/src/index.ts b/projects/mehulmathur16/src/index.ts index 31a55a4..49f339a 100644 --- a/projects/mehulmathur16/src/index.ts +++ b/projects/mehulmathur16/src/index.ts @@ -4,9 +4,6 @@ import schema from './schema' import resolvers from './resolvers' import axiosInstance from './axios' import DataLoader from 'dataloader' -import http from 'http'; - -const httpAgent = new http.Agent({ keepAlive: true }); const server = fastify({ logger: true @@ -21,7 +18,7 @@ server.register(mercurius, { const userDataLoader = new DataLoader(async function (ids: any) { const response = await axiosInstance.get('/users', { params: { id: ids }, - httpAgent + }); const users = response.data; let obj = {} as any @@ -36,7 +33,7 @@ server.register(mercurius, { const posts = await Promise.all( ids.map(async (id: any) => { try { - const response = await axiosInstance.get(`/posts/${id}`, { httpAgent }); + const response = await axiosInstance.get(`/posts/${id}`,); return response.data; } catch (error: any) { return new Error(`Failed to fetch post with id ${id}: ${error.message}`); diff --git a/projects/mehulmathur16/src/resolvers.ts b/projects/mehulmathur16/src/resolvers.ts index d9f8e65..4c7d369 100644 --- a/projects/mehulmathur16/src/resolvers.ts +++ b/projects/mehulmathur16/src/resolvers.ts @@ -1,15 +1,13 @@ import axiosInstance from './axios'; import http from 'http'; -const httpAgent = new http.Agent({ keepAlive: true }); - const resolvers = { Query: { posts: async (_: any, __: any, { cache }: any) => { if (cache['posts']) { return cache['posts']; } - const response = await axiosInstance.get('/posts', { httpAgent }); + const response = await axiosInstance.get('/posts'); cache['posts'] = response.data; return response.data; }, @@ -20,7 +18,7 @@ const resolvers = { if (cache['users']) { return cache['users']; } - const response = await axiosInstance.get('/users', { httpAgent }); + const response = await axiosInstance.get('/users'); cache['users'] = response.data; return response.data; }, @@ -38,7 +36,6 @@ const resolvers = { posts: async (user: { id: number }) => { const response = await axiosInstance.get('/posts', { params: { userId: user.id }, - httpAgent }); return response.data; }