mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
48 lines
719 B
TypeScript
48 lines
719 B
TypeScript
|
import type { NextPage } from "next";
|
||
|
import { request, gql } from "graphql-request";
|
||
|
|
||
|
interface Props {
|
||
|
posts: {
|
||
|
id: string;
|
||
|
title: string;
|
||
|
content: string;
|
||
|
}[];
|
||
|
}
|
||
|
|
||
|
const query = gql`
|
||
|
{
|
||
|
post {
|
||
|
content
|
||
|
id
|
||
|
title
|
||
|
}
|
||
|
}
|
||
|
`;
|
||
|
|
||
|
export async function getStaticProps() {
|
||
|
const { post: posts } = await request(
|
||
|
"http://localhost:8080/v1/graphql",
|
||
|
query
|
||
|
);
|
||
|
return {
|
||
|
props: {
|
||
|
posts,
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
|
||
|
const Home: NextPage<Props> = ({ posts }) => {
|
||
|
return (
|
||
|
<main>
|
||
|
{posts.map((post) => (
|
||
|
<article key={post.id}>
|
||
|
<h2>{post.title}</h2>
|
||
|
<p>{post.content}</p>
|
||
|
</article>
|
||
|
))}
|
||
|
</main>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default Home;
|