videos.ts

import { fetchFromGraphQL } from '../../utility/lib/fetch';
import { videoSearchFields } from './lib';

export async function getVideo(req) {
  const { referer } = req.headers;
  const videoId = req.params.videoId;
  const query = `query getVideo($videoId: String!) {
    video(videoId: $videoId) {
      ${videoSearchFields}
    }
  }
  `;
  const variables = { videoId };

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

export async function getVideos(req) {
  const { referer } = req.headers;
  const query = `{
    videos {
      ${videoSearchFields}
    }
  }
  `;
  const { videos } = await fetchFromGraphQL({
    query,
    referer
  });
  return videos;
}