mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-09 05:25:15 -05:00
31 lines
611 B
TypeScript
31 lines
611 B
TypeScript
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;
|
|
};
|