mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-01-14 08:58:02 -05:00
70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import {
|
|
GetQuestDocument,
|
|
GetQuestQuery,
|
|
GetQuestQueryVariables,
|
|
GetQuestWithCompletionsDocument,
|
|
GetQuestWithCompletionsQuery,
|
|
GetQuestWithCompletionsQueryVariables,
|
|
} from 'graphql/autogen/hasura-sdk';
|
|
import {
|
|
PlayerFragment,
|
|
QuestFragment,
|
|
QuestWithCompletionFragment,
|
|
} from 'graphql/fragments';
|
|
import { Client } from 'urql';
|
|
|
|
import { client as defaultClient } from '#graphql/client';
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
/* GraphQL */ `
|
|
query GetQuest($id: uuid!) {
|
|
quest_by_pk(id: $id) {
|
|
...QuestFragment
|
|
}
|
|
}
|
|
${QuestFragment}
|
|
`;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
/* GraphQL */ `
|
|
query GetQuestWithCompletions(
|
|
$id: uuid!
|
|
) {
|
|
quest_by_pk(id: $id) {
|
|
...QuestWithCompletionFragment
|
|
player {
|
|
...PlayerFragment
|
|
}
|
|
}
|
|
}
|
|
${QuestWithCompletionFragment}
|
|
${PlayerFragment}
|
|
`;
|
|
|
|
export const getQuest = async (
|
|
id: string | undefined,
|
|
client: Client = defaultClient,
|
|
) => {
|
|
if (!id) return null;
|
|
const { data } = await client
|
|
.query<GetQuestQuery, GetQuestQueryVariables>(GetQuestDocument, { id })
|
|
.toPromise();
|
|
|
|
return data?.quest_by_pk;
|
|
};
|
|
|
|
export const getQuestWithCompletions = async (
|
|
id: string | undefined,
|
|
client: Client = defaultClient,
|
|
) => {
|
|
if (!id) return null;
|
|
const { data } = await client
|
|
.query<GetQuestWithCompletionsQuery, GetQuestWithCompletionsQueryVariables>(
|
|
GetQuestWithCompletionsDocument,
|
|
{ id },
|
|
)
|
|
.toPromise();
|
|
|
|
return data?.quest_by_pk;
|
|
};
|