index.ts 745 Bytes
import { gql } from '@apollo/client';
import { get } from 'lodash/fp';
import apolloClient from '../../../store/apolloClient';

export const FIND_USER_CURRENT_NFL_SEASON_FRANCHISE = gql`
  query FindNflSeasonFranchises($userId: String!) {
    currentNflSeason {
      id
      franchises(filter: { ownerId: { eq: $userId } }) {
        nodes {
          id
          name
          fzCash
        }
      }
    }
  }
`;

export default async (userId: string) => {
  try {
    const { data } = await apolloClient.query({
      query: FIND_USER_CURRENT_NFL_SEASON_FRANCHISE,
      variables: { userId },
      fetchPolicy: 'network-only'
    });
    return get('currentNflSeason.franchises.nodes.0', data);
  } catch (e) {
    return null;
  }
};