{"id":18114,"date":"2022-10-08T18:10:33","date_gmt":"2022-10-08T09:10:33","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=18114"},"modified":"2023-05-27T17:43:08","modified_gmt":"2023-05-27T08:43:08","slug":"%e3%80%90next-js%e3%80%91ssg%e3%81%a7apollo-client%e3%82%92%e4%bd%bf%e3%81%86%e3%81%ab%e3%81%af%e3%80%82","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=18114","title":{"rendered":"\u3010Next.js\u3011SSG\u3067Apollo Client\u3092\u4f7f\u3046\u306b\u306f\u3002"},"content":{"rendered":"<h2>SSG(Static Site Generation)\u3068\u306f\uff1f<\/h2>\n<p>\u4e8b\u524d\u306b\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u306e\u3067\u30d6\u30e9\u30a6\u30b6\u306eJavaScript\u304c\u7121\u52b9\u306b\u306a\u3063\u3066\u3044\u3066\u3082\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u521d\u56de\u306e\u30d3\u30eb\u30c9\u3092\u524d\u3082\u3063\u3066\u3084\u3063\u3066\u304a\u304f\u306e\u3067\u30da\u30fc\u30b8\u306e\u63cf\u753b\u901f\u5ea6\u304c\u9ad8\u901f\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>page\u5185\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u88c5<\/h2>\n<pre class=\"lang:default decode:true\">import { GetStaticProps } from 'next'\r\nimport { GET_USERS } from '..\/queries\/queries'\r\nimport { GetUsersQuery } from '..\/types\/generated\/graphql'\r\n\r\nconst Test: VFC&lt;Props&gt; = ({ users }) =&gt; {\r\n  return (\r\n      {users?.map((user) =&gt; {\r\n        return (&lt;&gt;{user.name}&lt;\/&gt;)\r\n      })}\r\n  )\r\n}\r\nexport default Test\r\n\r\nexport const getStaticProps: GetStaticProps = async () =&gt; {\r\n  const apolloClient = initializeApollo()\r\n  const { data } = await apolloClient.query&lt;GetUsersQuery&gt;({\r\n    query: GET_USERS,\r\n  })\r\n  return {\r\n    props: { users: data.users },\r\n    revalidate: 1,\r\n  }\r\n}<\/pre>\n<p>\u306a\u304a\u3001\u30bd\u30fc\u30b9\u5185\u3067\u5229\u7528\u3057\u3066\u3044\u308bapollo Client\u306e\u5b9f\u88c5\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3059\u308b\u3068\u826f\u3044\u3067\u3059\u3002ApolloProvider\u3092\u4f7f\u308f\u305a\u306b\u305d\u306e\u307e\u307eapolloClient\u3067\u554f\u3044\u5408\u308f\u305b\u308b\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3067\u306fApolloProvider\u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u3092\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001Hasura(GraphQL\u3068SQL\u3092\u76f8\u4e92\u306b\u5909\u63db\u3057\u3066\u304f\u308c\u308b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\uff09\u3092\u4f7f\u3063\u3066\u3044\u308b\u30b5\u30f3\u30d7\u30eb\u306b\u3082\u306a\u308a\u307e\u3059\u3002\u901a\u5e38\u306eGraphQL\uff08\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u8a00\u8a9e\u3068\u3057\u3066\u306fNode.js\u3084Rails\u306a\u3069\u304c\u3042\u308b\u3067\u3057\u3087\u3046\u304b\uff09\u3067\u3082\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u306f\u307b\u307c\u4f3c\u305f\u3088\u3046\u306a\u5b9f\u88c5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"fqUXqvGHQ9\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=18087\">\u3010Next.js\u3011\u300cHasura\u300d\u3068\u300cApollo Client\u300d\u306e\u9023\u643a<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=18087&#038;embed=true#?secret=fqUXqvGHQ9\" data-secret=\"fqUXqvGHQ9\" width=\"500\" height=\"282\" title=\"&#8220;\u3010Next.js\u3011\u300cHasura\u300d\u3068\u300cApollo Client\u300d\u306e\u9023\u643a&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>Hasura\u3092\u4f7f\u7528\u3059\u308b\u3068\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u8a00\u8a9e\u306e\u77e5\u8b58\u304c\u3042\u307e\u308a\u306a\u3044\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u3067\u3082\u624b\u8efd\u306b\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9GraphQL\u3092\u4f5c\u6210\u3067\u304d\u308b\u306e\u3067\u5c0e\u5165\u3055\u308c\u3066\u3044\u308b\u6848\u4ef6\u3082\u5c11\u306a\u304f\u306a\u3044\u3067\u3059\u3002<\/p>\n<h2>\u30c6\u30b9\u30c8<\/h2>\n<p>SSG\u306f\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u52d5\u304f\u306e\u3067build\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">yarn build<\/pre>\n<h3>\u5b9f\u884c<\/h3>\n<pre class=\"lang:default decode:true  \">yarn start<\/pre>\n","protected":false},"excerpt":{"rendered":"SSG(Static Site Generation)\u3068\u306f\uff1f \u4e8b\u524d\u306b\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u306e\u3067\u30d6\u30e9\u30a6\u30b6\u306eJavaScript\u304c\u7121\u52b9\u306b\u306a\u3063\u3066\u3044\u3066\u3082\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u521d\u56de\u306e\u30d3\u30eb\u30c9\u3092\u524d\u3082\u3063\u3066\u3084\u3063\u3066\u304a\u304f [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[119],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18114"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18114"}],"version-history":[{"count":6,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18114\/revisions"}],"predecessor-version":[{"id":20064,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18114\/revisions\/20064"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}