mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-01-24 21:58:04 -05:00
fix: create clients once
Suggestion from @dan13ram on PR to cache the clients and avoid recreating on every request.
This commit is contained in:
committed by
dan13ram
parent
62d37b0ea8
commit
8cfd347a48
@@ -1,8 +1,8 @@
|
||||
import { clientFactory } from '../../../../lib/daoHausClient';
|
||||
import { getClient } from '../../../../lib/daoHausClient';
|
||||
import { Member, QueryResolvers } from '../../autogen/types';
|
||||
|
||||
const addChain = (memberAddress: string) => async (chain: string) => {
|
||||
const client = clientFactory(chain);
|
||||
const client = getClient(chain);
|
||||
const members = <Member[]>(
|
||||
(await client.GetDaoHausMemberships({ memberAddress })).members
|
||||
);
|
||||
|
||||
@@ -3,13 +3,13 @@ import { GraphQLClient } from 'graphql-request';
|
||||
import { CONFIG } from '../config';
|
||||
import { getSdk, Sdk } from './autogen/daohaus-sdk';
|
||||
|
||||
export function clientFactory(chain: string): Sdk {
|
||||
switch (chain) {
|
||||
case 'polygon':
|
||||
return getSdk(new GraphQLClient(CONFIG.daoHausPolygonGraphqlURL));
|
||||
case 'xdai':
|
||||
return getSdk(new GraphQLClient(CONFIG.daoHausXdaiGraphqlURL));
|
||||
default:
|
||||
return getSdk(new GraphQLClient(CONFIG.daoHausGraphqlURL));
|
||||
}
|
||||
const defaultGqlClient = new GraphQLClient(CONFIG.daoHausGraphqlURL);
|
||||
const clients = new Map([
|
||||
['polygon', new GraphQLClient(CONFIG.daoHausPolygonGraphqlURL)],
|
||||
['xdai', new GraphQLClient(CONFIG.daoHausXdaiGraphqlURL)],
|
||||
['ethereum', defaultGqlClient],
|
||||
]);
|
||||
|
||||
export function getClient(chain: string): Sdk {
|
||||
return getSdk(clients.get(chain) || defaultGqlClient);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user