import { gql, useQuery } from '@apollo/client';
import { User } from '../../types/user';
import { useState, useEffect } from 'react';
import { useGraphQLData } from './helper';

export const QUERY_USER_PROFILE = gql`
query userProfile {
  userProfile {
    id,
    name,
    email,
    createdAt,
    connectedAt
  }
}`;

export function useUserProfileQuery() {
  return useQuery(QUERY_USER_PROFILE);
}

export function useUserProfile() {
  const { data, loading, error } = useGraphQLData<User>(
    QUERY_USER_PROFILE, 'userProfile', {id: '', email: ''}
  );
  return { user: data, loading, error };
}