mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
Implement list of Guilds in frontend
This commit is contained in:
@@ -53,3 +53,18 @@ export const PlayerFragment = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const GuildFragment = gql`
|
||||
fragment GuildFragment on Guild {
|
||||
id
|
||||
guildname
|
||||
description
|
||||
discord_invite_url
|
||||
join_button_url
|
||||
logo
|
||||
moloch_address
|
||||
name
|
||||
type
|
||||
website_url
|
||||
}
|
||||
`;
|
||||
|
||||
23
packages/web/graphql/getGuild.ts
Normal file
23
packages/web/graphql/getGuild.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import gql from 'fake-tag';
|
||||
|
||||
import { GetGuildQuery, GetGuildQueryVariables } from './autogen/types';
|
||||
import { client } from './client';
|
||||
import { GuildFragment } from './fragments';
|
||||
|
||||
const guildQuery = gql`
|
||||
query GetGuild($guildname: String!) {
|
||||
Guild(where: { guildname: { _eq: $guildname } }) {
|
||||
...GuildFragment
|
||||
}
|
||||
}
|
||||
${GuildFragment}
|
||||
`;
|
||||
|
||||
export const getGuild = async (guildname: string | undefined) => {
|
||||
if (!guildname) return null;
|
||||
const { data } = await client
|
||||
.query<GetGuildQuery, GetGuildQueryVariables>(guildQuery, { guildname })
|
||||
.toPromise();
|
||||
|
||||
return data?.Guild[0];
|
||||
};
|
||||
30
packages/web/graphql/getGuilds.ts
Normal file
30
packages/web/graphql/getGuilds.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import gql from 'fake-tag';
|
||||
|
||||
import { GetGuildsQuery, GetGuildsQueryVariables } from './autogen/types';
|
||||
import { client } from './client';
|
||||
import { GuildFragment } from './fragments';
|
||||
|
||||
const guildsQuery = gql`
|
||||
query GetGuilds($limit: Int) {
|
||||
Guild(limit: $limit) {
|
||||
...GuildFragment
|
||||
}
|
||||
}
|
||||
${GuildFragment}
|
||||
`;
|
||||
|
||||
export const getGuilds = async (limit = 50) => {
|
||||
const { data, error } = await client
|
||||
.query<GetGuildsQuery, GetGuildsQueryVariables>(guildsQuery, { limit })
|
||||
.toPromise();
|
||||
|
||||
if (!data) {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
return data.Guild;
|
||||
};
|
||||
Reference in New Issue
Block a user