import {apolloClient} from 'graphql/apolloClient';
import {GET_PRODUCTS} from 'graphql/queries/getProducts';
import {GetStaticProps} from 'next';
import {useRouter} from "next/router";

export const getStaticProps: GetStaticProps = async () => {
    const {data} = await apolloClient.query({
        query: GET_PRODUCTS,
        variables: {first: 10},
    });

    return {
        props: {
            products: data.products.edges.map((e: any) => e.node),
        },
        revalidate: 300,
    };
}

export default function Home({products}: { products: any[] }) {
    return (
        <div>
            {products.map(p => (
                <div key={p.uuid}>{p.name} — £{p.minPrice}</div>
            ))}
        </div>
    );
}
