mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-08 21:15:05 -05:00
31 lines
654 B
TypeScript
31 lines
654 B
TypeScript
import gql from 'fake-tag';
|
|
|
|
import { GetPlayersQuery, GetPlayersQueryVariables } from './autogen/types';
|
|
import { client } from './client';
|
|
import { PlayerFragment } from './fragments';
|
|
|
|
const playersQuery = gql`
|
|
query GetPlayers($limit: Int) {
|
|
player(order_by: { total_xp: desc }, limit: $limit) {
|
|
...PlayerFragment
|
|
}
|
|
}
|
|
${PlayerFragment}
|
|
`;
|
|
|
|
export const getPlayers = async (limit = 50) => {
|
|
const { data, error } = await client
|
|
.query<GetPlayersQuery, GetPlayersQueryVariables>(playersQuery, { limit })
|
|
.toPromise();
|
|
|
|
if (!data) {
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
return data.player;
|
|
};
|