Skip to content

Commit

Permalink
remove
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 committed Sep 11, 2024
1 parent 91e29ed commit e41e715
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 25 deletions.
6 changes: 0 additions & 6 deletions projects/mehulmathur16/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion projects/mehulmathur16/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions projects/mehulmathur16/src/axios.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 0 additions & 4 deletions projects/mehulmathur16/src/dataLoader.ts
Original file line number Diff line number Diff line change
@@ -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<number, any>(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]));
Expand Down
7 changes: 2 additions & 5 deletions projects/mehulmathur16/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}`);
Expand Down
7 changes: 2 additions & 5 deletions projects/mehulmathur16/src/resolvers.ts
Original file line number Diff line number Diff line change
@@ -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;
},
Expand All @@ -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;
},
Expand All @@ -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;
}
Expand Down

0 comments on commit e41e715

Please sign in to comment.