Add Remote Schema for DAOHaus / Moloch Dao memberships

Uses the ethereum address of a specific player to fetch the Moloch DAOs that player is a member of
This commit is contained in:
Hammad Jutt
2020-08-19 01:07:56 -06:00
parent 475ec3f4a3
commit caca26b1ce
10 changed files with 117 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
interface IConfig {
port: number;
graphqlURL: string;
daoHausGraphqlURL: string;
adminKey: string;
ipfsEndpoint: string;
}
@@ -23,6 +24,10 @@ export const CONFIG: IConfig = {
process.env.GRAPHQL_URL,
'http://localhost:8080/v1/graphql',
),
daoHausGraphqlURL: parseEnv(
process.env.DAOHAUS_GRAPHQL_URL,
'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus',
),
adminKey: parseEnv(
process.env.HASURA_GRAPHQL_ADMIN_SECRET,
'metagame_secret',

View File

@@ -8,7 +8,7 @@ import {
Player_Rank_Enum,
Player_Update_Column,
Scalars,
} from '../../../lib/autogen/sdk';
} from '../../../lib/autogen/hasura-sdk';
import { client } from '../../../lib/hasuraClient';
import { AddressBookEntry, SCAccountsData } from './types';

View File

@@ -0,0 +1,27 @@
import { gql } from 'graphql-request/dist';
export const GetDaoHausMemberships = gql`
query GetDaoHausMemberships($memberAddress: Bytes!) {
members(
where: { memberAddress: $memberAddress, didRagequit: false, exists: true }
) {
id
shares
molochAddress
createdAt
memberAddress
loot
exists
kicked
moloch {
id
title
version
summoner
totalShares
totalLoot
}
delegateKey
}
}
`;

View File

@@ -0,0 +1,12 @@
import { daoHausClient } from '../../../../lib/daoHausClient';
import { QueryResolvers } from '../../autogen/types';
export const getDaoHausMemberships: QueryResolvers['getDaoHausMemberships'] = async (
_,
{ memberAddress },
) => {
if (!memberAddress) return [];
const res = await daoHausClient.GetDaoHausMemberships({ memberAddress });
return res.members;
};

View File

@@ -1,11 +1,13 @@
import { makeExecutableSchema } from 'graphql-tools';
import { getDaoHausMemberships } from './resolvers/daohaus/resolver';
import { getBoxProfile } from './resolvers/getBoxProfile/resolver';
import { typeDefs } from './typeDefs';
const resolvers = {
Query: {
getBoxProfile,
getDaoHausMemberships,
},
};

View File

@@ -1,16 +1,40 @@
export const typeDefs = `
type Query {
getBoxProfile(address: String): BoxProfile
}
import { gql } from 'graphql-request/dist';
type BoxProfile {
ethereumAddress : String
name : String
description : String
location : String
job : String
emoji : String
imageUrl : String
}
export const typeDefs = gql`
type Query {
getBoxProfile(address: String): BoxProfile
getDaoHausMemberships(memberAddress: String): [Member!]!
}
type BoxProfile {
ethereumAddress: String
name: String
description: String
location: String
job: String
emoji: String
imageUrl: String
}
type Moloch {
id: ID!
summoner: String!
title: String
version: String
totalShares: Int!
totalLoot: Int!
}
type Member {
id: ID!
createdAt: String!
moloch: Moloch!
molochAddress: String!
memberAddress: String!
delegateKey: String!
shares: Int!
loot: Int
exists: Boolean!
kicked: Boolean
}
`;

View File

@@ -0,0 +1,8 @@
import { GraphQLClient } from 'graphql-request';
import { CONFIG } from '../config';
import { getSdk } from './autogen/daohaus-sdk';
export const daoHausClient = getSdk(
new GraphQLClient(CONFIG.daoHausGraphqlURL),
);

View File

@@ -1,7 +1,7 @@
import { GraphQLClient } from 'graphql-request';
import { CONFIG } from '../config';
import { getSdk } from './autogen/sdk';
import { getSdk } from './autogen/hasura-sdk';
export const client = getSdk(
new GraphQLClient(CONFIG.graphqlURL, {