import { gql } from "@apollo/client";

export const BLOGS_AND_CATEGORIES_QUERY = gql`
  query BlogsAndCategories($category: String, $after: String) {
    
    # BLOG POSTS (PAGINATED)
    posts(
      where: {
        status: PUBLISH
        categoryName: $category
      }
      first: 100
      after: $after
    ) {
      pageInfo {
        hasNextPage
        endCursor
      }
      nodes {
        id
        title
        excerpt
        slug
        date
        author {
          node {
            name
            slug
          }
        }
        categories {
          nodes {
            name
            slug
          }
        }
        featuredImage {
          node {
            sourceUrl
            altText
          }
        }
      }
    }

    # BLOG CATEGORIES
    categories(where: { hideEmpty: true }) {
      nodes {
        id
        name
        slug
      }
    }
  }
`;
