2020-09-10 19:25:52 +02:00
|
|
|
import { gql, useQuery, QueryHookOptions } from '@apollo/client';
|
2020-07-31 17:36:10 +02:00
|
|
|
import { User } from '../../types/user';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
|
|
import { useGraphQLData } from './helper';
|
2020-07-21 22:25:39 +02:00
|
|
|
|
2020-07-31 18:04:31 +02:00
|
|
|
export const QUERY_USER_PROFILE = gql`
|
2020-07-21 22:25:39 +02:00
|
|
|
query userProfile {
|
|
|
|
userProfile {
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
email,
|
|
|
|
createdAt,
|
|
|
|
connectedAt
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
|
2020-09-10 19:25:52 +02:00
|
|
|
export function useUserProfileQuery<A = any, R = Record<string, any>>(options: QueryHookOptions<A, R> = {}) {
|
|
|
|
return useQuery(QUERY_USER_PROFILE, options);
|
2020-07-31 17:36:10 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 19:25:52 +02:00
|
|
|
export function useUserProfile<A = any, R = Record<string, any>>(options: QueryHookOptions<A, R> = {}) {
|
2020-07-31 17:36:10 +02:00
|
|
|
const { data, loading, error } = useGraphQLData<User>(
|
2020-09-10 19:25:52 +02:00
|
|
|
QUERY_USER_PROFILE, 'userProfile', {id: '', email: ''}, options
|
2020-07-31 17:36:10 +02:00
|
|
|
);
|
|
|
|
return { user: data, loading, error };
|
2020-07-21 22:25:39 +02:00
|
|
|
}
|