1import gql from 'graphql-tag';
2
3import { graphqlClient, withErrorHandlingAsync } from '../client';
4import { CurrentUserQuery } from '../generated';
5
6export const UserQuery = {
7  async currentUserAsync(): Promise<CurrentUserQuery['meActor']> {
8    const data = await withErrorHandlingAsync(
9      graphqlClient
10        .query<CurrentUserQuery>(
11          gql`
12            query CurrentUser {
13              meActor {
14                __typename
15                id
16                ... on User {
17                  username
18                }
19                ... on Robot {
20                  firstName
21                }
22                accounts {
23                  id
24                  name
25                }
26                isExpoAdmin
27              }
28            }
29          `,
30          /* variables */ undefined,
31          {
32            additionalTypenames: ['User'],
33          }
34        )
35        .toPromise()
36    );
37
38    return data.meActor;
39  },
40};
41