comedians.ts

import { fetchFromGraphQL } from '../../utility/lib/fetch';
import { comedianFields, videoFields } from './lib';

export async function getComedians(req) {
  const { referer } = req.headers;
  const query = `{
    comedians {
      ${comedianFields}
    }
  }`;
  const { comedians } = await fetchFromGraphQL({
    query,
    referer
  });
  return comedians;
}

export async function getComedian(req) {
  const { referer } = req.headers;
  const comedianId = req.params.comedianId;
  const query = `query getComedian($comedianId: String!) {
    comedian(comedianId: $comedianId) {
      basic {
        ${comedianFields}
      }
      videos {
        ${videoFields}
      }
    }
  }
  `;
  const variables = { comedianId };

  const { comedian } = await fetchFromGraphQL({
    query,
    variables,
    referer
  });

  return comedian;
}