-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add polygon and xdai chains when pulling DAO membership
This uses two new subgraphs to pull DAO memberships for Ethereum, xDai, and Polygon mainnets. The pulls are in parallel. The underlying data is structured the same way but seems to be missing some information, see HausDAO/daohaus-supergraph#44
- Loading branch information
Showing
5 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 29 additions & 4 deletions
33
packages/backend/src/handlers/remote-schemas/resolvers/daohaus/resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
import { daoHausClient } from '../../../../lib/daoHausClient'; | ||
import { QueryResolvers } from '../../autogen/types'; | ||
import { clientFactory } from '../../../../lib/daoHausClient'; | ||
import { Member, QueryResolvers } from '../../autogen/types'; | ||
|
||
const addChain = (memberAddress: string) => async (chain: string) => { | ||
const client = clientFactory(chain); | ||
const members = <Member[]>( | ||
(await client.GetDaoHausMemberships({ memberAddress })).members | ||
); | ||
|
||
return members.map((member: Member) => { | ||
const updatedMember: Member = { ...member }; | ||
updatedMember.moloch.chain = chain; | ||
return updatedMember; | ||
}); | ||
}; | ||
|
||
export const getDaoHausMemberships: QueryResolvers['getDaoHausMemberships'] = async ( | ||
_, | ||
{ memberAddress }, | ||
) => { | ||
if (!memberAddress) return []; | ||
const res = await daoHausClient.GetDaoHausMemberships({ memberAddress }); | ||
|
||
return res.members; | ||
const membershipsOn = addChain(memberAddress); | ||
|
||
const res = await Promise.all([ | ||
membershipsOn('ethereum'), | ||
membershipsOn('polygon'), | ||
membershipsOn('xdai'), | ||
]); | ||
|
||
const members: Member[] = res.reduce( | ||
(allMembers, networkMembers) => [...allMembers, ...networkMembers], | ||
<Member[]>[], | ||
); | ||
|
||
return members; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { GraphQLClient } from 'graphql-request'; | ||
|
||
import { CONFIG } from '../config'; | ||
import { getSdk } from './autogen/daohaus-sdk'; | ||
import { getSdk, Sdk } from './autogen/daohaus-sdk'; | ||
|
||
export const daoHausClient = getSdk( | ||
new GraphQLClient(CONFIG.daoHausGraphqlURL), | ||
); | ||
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2096,6 +2096,7 @@ type Member { | |
} | ||
|
||
type Moloch { | ||
chain: String! | ||
id: ID! | ||
summoner: String! | ||
title: String | ||
|