ãã¡ãã¯ãã¤ã»ã«ãã¯ããã¸ã¼ãº Advent Calendar 2024ã®1æ¥ç®ã®è¨äºã§ãã
ããã«ã¡ã¯ãéçºï¼é¨ã§ããã¯ãªã¼ãããã¦ããæ©ç¬ã§ããæ®æ®µã¯ãªã¦ã¼ã¹ãã©ãããã©ã¼ã ã®ECåºå管çã·ã¹ãã ã®éçºãè¡ã£ã¦ãã¾ãã
ç§ã®ãã¼ã ã§ã¯ãECåºå管çã·ã¹ãã ï¼é称EXSï¼ã®éçºãè¡ãªã£ã¦ããã3å¹´éã«åã¶éçºã®æ«ã«ä»å¹´ã®9æã«ãã¼ã³ãããã¾ããã
ç§ã¯ãããã¯ãã®ç«ã¡ä¸ãæããåç»ãã¦ãããéçºåæã®æè¡é¸å®ããé¢ãã£ã¦ãã¾ããã
é·æã«åã¶éçºã®æ«ã«ãã¤ãã«ãã¼ã³ããããã®ã§ãä»åã¯ãã®ãããã¯ãã®æè¡é¸å®ã«ã¤ãã¦ã®æ¯ãè¿ããç´¹ä»ãããã¨æãã¾ãï¼
è¨äºã®ããªã¥ã¼ã ãããªãããã®ã§ãèå³ã®ããç®æã ãã§ãèªãã§ããã ããã¨å¬ããã§ãã
- ãããã¯ãã®æ¦è¦
- æè¡é¸å®ã®æ¯ãè¿ã
ãããã¯ãã®æ¦è¦
EXSã¯è¤æ°ã®ECãµã¤ãã¸ã®åºåã»å注æ¥åãä¸å
管çããWebã¢ããªã±ã¼ã·ã§ã³ã§ãã
å©ç¨è
ã¯ååã®è²©å£²æ©ä¼ãæ大åããããã«ãè¤æ°ã®ECãµã¤ãã«åæã«åºåãè¡ãã¾ãã
ãã®éã«ãEXSãåECãµã¤ãã®ä»æ§ã®éããå¸åãé£æºãè¡ããã¨ã§ãå©ç¨è
ã¯ãããã®å·®ç°ãæèãããã¨ãªããååã®åºåãå注æ¥åãä¸å
çã«ç®¡çã§ãã¾ãã
ã¾ãããªã¦ã¼ã¹ã®ååã¯å
¨ã¦1ç¹ãã®ãããè¤æ°ã®ECãµã¤ãã«åæã«åºåãè¡ããã©ããã§å£²ããå ´åã¯ãæ®ãã®ECãµã¤ãããã¯å³æã«åºåãåãä¸ããå¿
è¦ãããã¾ãã
ãããã®é£æºãEXSãåECãµã¤ãã§ã®å注ãæ¤ç¥ãã¦ããªã¢ã«ã¿ã¤ã ã§é£æºãè¡ãªã£ã¦ãã¾ãã
ç¾æç¹ã§ã¯8ã¤ã®ECãµã¤ãã«å¯¾å¿ãã¦ãããé£æºå ã¯ä»å¾ãæ¡å¤§äºå®ã§ãã
ãããã¯ãç¹æ§
EXSã¯ä¸è¨ã®ãããªç¹æ§ãããã¾ãã
- BtoBã·ã¹ãã ã§ãèªè¨¼ãããã¦ã¼ã¶ã¼ã®ã¿ãå©ç¨ãã
- ç¾å¨ã¯ãã¤ã»ã«ã°ã«ã¼ãå ã§ã®ã¿ã§å©ç¨
- å¤é¨ãµã¼ãã¹ã¨ã®é£æºãé常ã«å¤ã
- é£æºããAPIã®ç¨®é¡ã¯ãGraphQLã»RESTã»XMLã»SOAPãªã©ãå¤ç¨®å¤æ§
- ç¾æç¹ã§100以ä¸ã®å¤é¨APIã¨é£æºãã¦ãã
- æä¾å ãéãã®ã§ãããããã®ä»æ§ã«æºæ ãã追å¾ãç¶ããå¿ è¦ããã
- ä¸æ¬åºåãä¸æ¬å注å¦çã主ãªæ©è½ã§ãæ¤ç´¢ãã¦ä¸æ¬å¦çã¨ããæµãã®ããã¼ãå¤ã
- ååæ
å ±ãå¯å¤å±æ§ã®ãã¼ã¿ãæã¤
- ããã³ããååã«å¯¾ãã¦ãé
ç®ãé¸æè¢ãèªç±ã«å®ç¾©ã§ãã
- Jiraã®ã«ã¹ã¿ã ãã£ã¼ã«ãã¨åã
- å®ç¾©ããé ç®ãæ¤ç´¢ããããCSVã§åºåããããããã¨ãå¯è½
- ããã³ããååã«å¯¾ãã¦ãé
ç®ãé¸æè¢ãèªç±ã«å®ç¾©ã§ãã
- 主ã«PCã§å©ç¨ããã
- å°æ¥çã«ã¯ã¢ãã¤ã«ã«ã対å¿äºå®
æè¡æ§æ
æè¡æ§æã¯ä¸è¨ã®éãã§ãã
- API
- GraphQL
- REST
- ããã¯ã¨ã³ã
- Hasura
- Go
- gqlgen
- GORM
- ããã³ãã¨ã³ã
- Next.js
- TypeScript
- Apollo Client
- ã¤ã³ãã©
- Google Cloud
- Cloud Run
- PostgreSQLï¼Cloud SQLï¼
- Elasticsearch
åæå¦çç¨ã®ã³ã³ããï¼ä»¥éåæã³ã³ããï¼ã¨ãéåæå¦çç¨ã®ã³ã³ããï¼ä»¥ééåæã³ã³ããï¼ããããåæå¦çç¨ã®ã³ã³ããã¯GraphQLããããå¦çç¨ã®ã³ã³ããã¯RESTã使ç¨ãã¦ãã¾ãã
åã¢ã¼ã«ã¨ã®é£æºå¦çã¯ã主ã«éåæã³ã³ããã§è¡ã£ã¦ãã¾ãã
æè¡é¸å®ã®æ¯ãè¿ã
ããããã¯æè¡é¸å®ã«ã¤ãã¦ãããããããã®ã»ãããããªãã£ããã®ã«åãã¦ãããããç´¹ä»ãã¦ããããã¨æãã¾ãï¼
ããããããã®
Go
以åããã¤ã»ã«ã§ã¯Ruby on Railsãæ¡ç¨ããã¦ãã¾ãããã2021å¹´é ããGoã¸ã®ãªãã¬ã¤ã¹ãå§ã¾ããEXSããã¡ãã«åããã¦Goãæ¡ç¨ãããã¨ã«ãªãã¾ããã
æ¯ãè¿ã£ã¦ã¿ã¦ãGoã®æ¡ç¨ã¯é常ã«è¯ãã£ãã¨æãã¦ãã¾ãã
å¦ç¿ã³ã¹ãã®ä½ã
ãã®çç±ã®ä¸ã¤ãè¨èªä»æ§ã®ã·ã³ãã«ãã«ãããå¦ç¿ã³ã¹ãã®ä½ãã§ãã
éçºæéãé·ãã£ããããæ§ã
ãªçç±ã§ã¡ã³ãã¼ã®å
¥ãæ¿ããã度ã
ããã¾ããããã¤ã»ã«ã§ã¯æ°åæ¡ç¨ãç©æ¥µçã«è¡ã£ã¦ããã®ã§ãæ¯å¹´4æã«ã¯æ°åã®ã¡ã³ãã¼ããã¼ã ã«å ããã¾ãã
ãããªä¸ã§ãæ°ãã«å å
¥ããã¡ã³ãã¼å
¨å¡ã«Goã®éçºçµé¨ãããããã§ã¯ãªãã£ãã§ãããå¦ç¿ã³ã¹ããä½ãããã£ããã¢ããããããããããæ°ãã«åå ããã¡ã³ãã¼ã§ãæ¯è¼çæ©ãéçºã«åå ã§ãã¾ããã
以ä¸ã¯ä»å¹´å
¥ç¤¾ããæ°åã¡ã³ãã¼ã®PRä½ææ°ã®é·ç§»ã§ãã
æ°åã®å
¨ä½ç ä¿®ãçµãã¦6æãããã¼ã ã«å ããã¾ãããããã®æç¹ã§ã¯Goã®çµé¨ã¯ãã¡ããããµã¼ãã¼ãµã¤ãã®éçºçµé¨ãããã¾ããã§ããã
ãããããã£ããã¢ãããéå§ããé 調ã«PRä½ææ°ãå¢å ãã¦ãããå å
¥ããç´3ãæã§æ¢åã¡ã³ãã¼ã¨åç¨åº¦ã«éãã¦ãããã¨ãã°ã©ããã確èªã§ãã¾ãã
æ¯è¼çç°¡åãªã¿ã¹ã¯ãã¢ãµã¤ã³ãã¦ããã¼ã ã¡ã³ãã¼ãæåããµãã¼ããããã¨ãè¦å ã¨ãã¦æãããã¾ãããããã§ããã£ããã¢ãããé 調ã ã£ããã¨ããããã¨æãã¾ãã
éçºé度ã®åä¸
è¨èªä»æ§ã®ã·ã³ãã«ãã¯ãå¦ç¿ã³ã¹ãã®ä½ãã«å ãã¦ãå¯èªæ§ãå®è£ ã®ããããã«ãç¹ããã¾ãã
è¨èªä»æ§ãã·ã³ãã«ãªæ
ã«ãæ¸ãæ¹ãåé·ã«ãªããã¨ãå¤ã
ããã¾ããã誰ãæ¸ãã¦ãåããããªæ¸ãæ¹ã«ãªããããã³ã¼ãã追ããããã¬ãã¥ã¼ãããããã§ãã
使ç¨ãã¦ããããã±ã¼ã¸ã®ã³ã¼ãããæµæãªãèªããã®ã§ãå
é¨å®è£
ãç解ããä¸ã§ä½¿ç¨ã§ããé»éè¡çãªãã¨ãå°ãªããªãã¾ãã
ããã³ãã¨ã³ãã®å®è£
ãããéã¯ãTypeScriptã使ç¨ãã¦ãã¾ãããä¸é
æ¼ç®åã使ãã®ãè¯ãã®ããif-elseã使ãã®ãè¯ãã®ããè¥å¹²æ©ãå ´é¢ãããã¾ãã
Goã®å ´åã¯ä¸é
æ¼ç®åããªã*1ãããæ¸ãæ¹ã«è¿·ããã¨ãå°ãªããã¬ãã¥ã¼ã§ææãè¡ããã¨ãå°ãªãã§ãã
CLIã¨ã®è¦ªåæ§
ã¾ããCLIãä½æããããç¹ãGoãæ¡ç¨ãã¦ããã£ãç¹ã§ãã
ç§ã®ãã¼ã ã§ã¯ãcobraã使ã£ã¦ãéçºãå¹çåããããã®CLIãã¼ã«ãä½æãã¦ãã¾ãã
cobraã使ããã¨ã§ãæ軽ã«CLIãä½æã§ãããããéçºéç¨ã§å°ã£ããã¨ãããã°ãCLIãä½æãã¦è§£æ±ºããã¨ããæåãçã¾ãã¾ããã
ç¹ã«ãéçºæã®é£æºå
ãå¤ããå±äººåããããç¶æ³ã§ããã®æåãéçºçç£æ§ãåä¸ãããä¸å ã¨ãªã£ã¦ããã¨æãã¦ãã¾ãã
ä½æãããã¼ã«ã®ä¸ä¾ã¯ããã¡ãã®è¨äºã§ç´¹ä»ãã¦ããã®ã§ãèå³ã®ããæ¹ã¯ã覧ãã ããã
GraphQL
ããã³ãã¨ã³ãã»ããã¯ã¨ã³ãéã®APIã«ã¯GraphQLãæ¡ç¨ãã¾ããã
Fragment Colocationã®ãã¯ã¼
ç§ã¯æ¯è¼çããã³ãã¨ã³ãã®å®è£ ãè¡ããã¨ãå¤ãã®ã§ãããGraphQLãæ¡ç¨ãã¦ä¸çªè¯ãã£ãç¹ã¯ãFragment Colocationã«ãããã¼ã¿ãã§ããã®æé©åã¨éçºå¹çã®åä¸ã ã¨æãã¦ãã¾ãã
Fragment Colocationã¨ã¯GraphQLã«ãããè¨è¨ææ³ã§ãã³ã³ãã¼ãã³ãã®ãã¼ã¿è¦ä»¶ãFragmentã§å®ç¾©ããã³ã³ãã¼ãã³ãã¨ã»ããã§ç®¡çããã¨ãããã®ã§ãã
ã³ã³ãã¼ãã³ãã§ä½¿ç¨ãããã¼ã¿ãFragmentã§å®ç¾©ãããããã®ã³ã³ãã¼ãã³ããã¾ã¨ãä¸ãã親ã³ã³ãã¼ãã³ãã§Queryã¨ãã¦å®è¡ãã¾ãã
ãã¼ã¿ã®å®£è¨ã¨ã³ã³ãã¼ãã³ããã³ãã±ã¼ã·ã§ã³ããã¦ããã®ã§ããªã¼ãã¼ãã§ããã«æ°ã¥ãããããªãã¾ãã
å®éã«å®è£
ãã¬ãã¥ã¼ãããéã«ããUIããè¦ç´ ãåé¤ãã¦ããããFragmentå
ã®ãã£ã¼ã«ãã®åé¤æ¼ãã«æ°ã¥ãå ´é¢ãä½åº¦ãããããªã¼ãã¼ãã§ãããé²ãã®ã«å½¹ç«ã¡ã¾ããã
ã¾ããFragment Colocationã¯éçºå¹çã®åä¸ã«ãç¹ããã¾ãã ä¸è¨ã¯ã³ã¼ãä¸ä¾ã§ãã
import { graphql } from '~/gql'; import { useSuspenseQuery } from '@apollo/client'; import { OrderCustomerInfo } from './OrderCustomerInfo'; const OrderDetailQuery = graphql(/* GraphQL */ ` query OrderDetailQuery { order { ...OrderCustomerInfo_Order } } `); export const OrderDetail: React.FC = () => { const { data } = useSuspenseQuery(OrderDetailQuery); return ( <div> <h1>注æ詳細</h1> <OrderCustomerInfo orderRef={data.order} /> </div> ); };
import { FragmentType, graphql, useFragment } from '~/gql'; const OrderCustomerInfoFragment = graphql(/* GraphQL */ ` fragment OrderCustomerInfo_Order on Order { id orderedAt purchaser { id name address } } `); type OrderCustomerInfoProps = { orderRef: FragmentType<typeof OrderCustomerInfoFragment>; }; export const OrderCustomerInfo: React.FC<OrderCustomerInfoProps> = ({ orderRef, }) => { const order = useFragment(OrderCustomerInfoFragment, orderRef); return ( <div> <p>注ææ¥æ: {order.orderedAt}</p> <p>è³¼å ¥è : {order.purchaser.name}</p> <p>ä½æ: {order.purchaser.address}</p> </div> ); };
OrderCustomerInfo.txs
ã§Fragmentãå®ç¾©ãã¦ããã®åæ
å ±ããã®ã¾ã¾Propsã«æå®ãã¦ãã¾ãã
RESTãFragment Colocationã使ããªãGraphQLã®å ´åã¯ãOrderCustomerInfo
ã§å¿
è¦ãªæ
å ±ãPropsã§å®ç¾©ããOrderDetail
ã§åå¾ãããã¼ã¿ã¨Propsã®ãããã³ã°ãè¡ããã¨ã«ãªãã¨æãã¾ãã
ããã¨æ¯ã¹ã¦ãFragment Colocationã使ã£ãå ´åã¯ããã®ãããªãããã³ã°å¦çãä¸è¦ã«ãªãã¾ãã
ã¾ããOrderCustomerInfo
ã«å¤æ´ãå ããå ´åããOrderDetail
ã«å¤æ´ã¯ä¸è¦ã§OrderCustomerInfo
ã®ã¿å¤æ´ããã°è¯ããå½±é¿ç¯å²ãéå®ãããã®ã§ãå®è£
å·¥æ°ãé常ã«å°ãªãæ¸ã¿ã¾ããã
â¶ï¸ ä¿®æ£ä¾
--- a/OrderCustomerInfo.tsx +++ b/OrderCustomerInfo.tsx @@ -174,7 +174,6 @@ const OrderCustomerInfoFragment = graphql(/* GraphQL */ ` purchaser { id name - address } } `); @@ -192,7 +191,6 @@ export const OrderCustomerInfo: React.FC<OrderCustomerInfoProps> = ({ <div> <p>注ææ¥æ: {order.orderedAt}</p> <p>è³¼å ¥è : {order.purchaser.name}</p> - <p>ä½æ: {order.purchaser.address}</p> </div> ); };
å¥ç´ã¨ãã¦ã®ã¹ãã¼ããã¡ã¼ã¹ã
ããã³ãã¨ã³ãã»ããã¯ã¨ã³ãã§ãããããgraphql-code-generatorã¨gqlgenã使ç¨ãã¦ãã¹ãã¼ããã¡ã¼ã¹ãã§éçºãè¡ã£ã¦ãã¾ãã
ã¹ãã¼ããã¡ã¼ã¹ãã§éçºãããã¨ã§ãAPIè¨è¨ã®è°è«ãè¡ãããããããã³ãã¨ã³ãã¨ããã¯ã¨ã³ãã§ä¸¦è¡ãã¦éçºãé²ããããã®ç¹ãè¯ãã£ãã§ãã
ããã«ãGraphQLã§ã¯å®ç¾©ããã¹ãã¼ãã¨ç°ãªãã¬ã¹ãã³ã¹ãè¿ã£ã¦ãããã¨ã¯ããã¾ãããããã«ãããã¹ãã¼ãã¯ããã³ãã¨ã³ãã¨ããã¯ã¨ã³ãã®éã§ãå¥ç´ï¼Contractï¼ãã¨ãã¦æ©è½ãããããã¹ãã¼ãã¨å®éã®ã¬ã¹ãã³ã¹ãä¹é¢ãããã¨ããªãã§ãã
RESTã§OpenAPIãæ¡ç¨ããå ´åã§ããã¹ãã¼ããã¡ã¼ã¹ãã§ã®éçºèªä½ã¯å¯è½ã§ãã
ããããOoenAPIã®å®ç¾©ã¯ããã¾ã§ä»æ§æ¸ã§ãããAPIã®å®æ
ãä¿è¨¼ãããã®ã§ã¯ãªãããããå¥ç´ï¼Contractï¼ãã¨ãã¦ã¯æ©è½ãã¾ããã
OpenAPI Generatorã§oneof
ã使ç¨ããå ´åãä¾ã«æãã¾ãã
OpenAPIã§ã¯ãoneofã¨ãããè¤æ°ã®åã®ãã¡ã©ããä¸ã¤ã表ãè¨æ³ãããã¾ãã
paths: /pets: patch: requestBody: content: application/json: schema: oneOf: - $ref: "#/components/schemas/Cat" - $ref: "#/components/schemas/Dog" responses: "200": description: Updated
ããããOpenAPI Generatorã¯ãoneofã«å¯¾å¿ãã¦ããªããããoneOf
ãç¨ããä»æ§ã«åºã¥ãã³ã¼ããèªåçæãããã¨ãã§ãã¾ããã
ãã®çµæã対å¿ããã³ã¼ããæåã§å®è£
ããå¿
è¦ãçãã¾ããæåå®è£
ã§ã¯ãã¹ãã¼ãã¨å®è£
ã®éã§ç¸äºã«ä¿®æ£æ¼ããçºçãããªã¹ã¯ãé«ã¾ããçµæã¨ãã¦ã¹ãã¼ãã¨å®éã®ã¬ã¹ãã³ã¹ãä¹é¢ããå¯è½æ§ãçºçãã¦ãã¾ãã¾ãã
GraphQLãæ¡ç¨ããå ´åã¯ãä¸è¨ã®ãããªãªã¹ã¯ããªããã¹ãã¼ããã¡ã¼ã¹ãã§éçºãé²ãããããããå¹ççãã¤å®å¿ãã¦éçºãé²ãããã¨ãã§ãã¾ããã
ä¸è¬çãªGraphQLã®ãã¡ãªããã«ã¤ãã¦
GraphQLãæ¡ç¨ããã«ãããããã¡ãªããã¨ãã¦ãè¨è¨ã®é£ãããããã³ãã¨ã³ãã®Queryã®èªç±åº¦ã«ããããã©ã¼ãã³ã¹ã®åé¡ãªã©ãæãããã¾ãã
åè¿°ã®éããåæã³ã³ããã¨éåæã³ã³ããã«åããã¦ãããããã³ãã¨ã³ãã¨åæã³ã³ããã®éã§GraphQLãæ¡ç¨ãã¦ãã¾ãã
ã¢ã¼ã«ã¨ã®é£æºãªã©ã®ã³ã¢ãªãã¸ãã¯ã¯ã»ã¨ãã©éåæã³ã³ããã§è¡ããã¦ããã®ã§ããããã¯ãã®å
¨ä½ã®è¦æ¨¡ã¨æ¯ã¹ã¦ãGraphQLã®APIã®æ°ã¯ããã¾ã§å¤ãããã¾ããã
ãã®ãããç¾ç¶ã¯GraphQLã¹ãã¼ãã®è¤éæ§ã¯æ¯è¼çä½ããè¨è¨é£æ度ãåé¡ã«ãªã£ã¦ãã¾ããã
ä»®ã«é£æºå
ã®ã¢ã¼ã«ãå¢ããå ´åãã主ã«ä¿®æ£ãå ããã®ã¯éåæã³ã³ããã«ãªãã¾ãã
ããã³ãã¨ã³ãããã¯ããã§ã«å©ç¨ãã¦ããQueryãMutationã®å¼æ°ã«ã追å ãããã¢ã¼ã«ã®æ
å ±ãå¼æ°ã§æ¸¡ãã ãã§è¯ãã®ã§ãé£æºå
ãå¢ãã¦ããå ´åã§ããGraphQLã¹ãã¼ãã«å¤æ´ã¯ä¸è¦ã§ãã
ã¾ããQueryã®èªç±åº¦ã«é¢ãã¦ããã¬ãã¥ã¼ä½å¶ã¨Linterã®2ã¤ã®å´é¢ãã対çãè¡ã£ã¦ãã¾ãã
ããã³ãã¨ã³ãã»ããã¯ã¨ã³ãã¨ãã«ããã¼ã å
ã®ããã¯ãªã¼ã2人ãå¿
ãã³ã¼ãã¬ãã¥ã¼ãè¡ãä½å¶ã«ãªã£ã¦ãããå®ç¾©ããQueryã«åé¡ãããã°ãã³ã¼ãã¬ãã¥ã¼ã®æ®µéã§ææãã¦ãã¾ãã
ä½µãã¦graphql-eslintã«ããGraphQLã®Lintãè¡ã£ã¦ãã¾ãã
ä¸ä¾ã¨ãã¦ãselection-set-depthã¨ããã«ã¼ã«ã«ãããQueryã®ãã¹ãã®æ·±ããå¶éãããã¨ã§ããªãã¸ã§ã¯ãã®å¾ªç°åç
§ã«ããé«è² è·ãªQueryã®å®è¡ãé²ãã§ãã¾ãã
GraphQLã®æ¡ç¨ã¯ãããã¯ãã®è¦æ¨¡ãç¶æ³ã«ãã£ã¦ã¯ãã¡ãªããããã®éç¨ã³ã¹ãã大ãããªã£ã¦ãã¾ãã±ã¼ã¹ãããã¨æãã¾ãã
å®æ§çãªæè¦ã«ã¯ãªãã¾ãããä»åã®ãããã¯ãã«ããã¦ã¯ãç¾ç¶ãã®ããã«æãããã¨ã¯ãªããå
¨ä½çã«ã¿ã¦æ¡ç¨ããã¡ãªããã®æ¹ã大ããã£ãã¨æãã¦ãã¾ãã
OpenAPI Generator/genqlient
å¤é¨APIã®å¼ã³åºãå¦çã«é¢ãã¦ã¯ãèªåçæããã³ã¼ãã使ç¨ãã¦ãã¾ãã
RESTã®å ´åã¯OpenAPI GeneratorããGraphQLã®å ´åã¯genqlientãæ¡ç¨ãã¦ãã¾ãã
é£æºå
ã«ãã£ã¦APIã®ç¨®é¡ãç°ãªããGraphQLã®å ´åãããã°ãRESTã®å ´åãããã¾ããRESTã®ä¸ã§ãJOSNã»XMLã»multipart/form-dataãªã©å¤ç¨®å¤æ§ã§ãã
ãã®ãããªå ´åã§ããèªåçæãããã³ã¼ãã使ç¨ãããã¨ã§ãAPIã®ç¨®é¡ã«ãããå®è£
ããã¼ãä¸è¨ã®ããã«çµ±ä¸ãããã¨ãã§ãã¾ãã
- OpenAPI or Query/Mutationã®å®ç¾©
- ã¯ã©ã¤ã¢ã³ãã³ã¼ãã®èªåçæ
- èªåçæãããã³ã¼ããå©ç¨ãã¦ãã¡ã¤ã³ãã¸ãã¯ã®å®è£
ã¾ããå¤é¨APIã¯å®æçã«ä»æ§å¤æ´ãçºçãããããããã«è¿½å¾ããå¿
è¦ãããã¾ãã
ãã®éã«ããä¸è¨ã¨åãããã¼ã§å¯¾å¿ãããã¨ãã§ããèªåçæãç´ãã¦ãã³ã³ãã¤ã«ã¨ã©ã¼ãçºçããç®æãä¿®æ£ããã°è¯ããããå½±é¿ç¯å²ãæ確ã«ãªãã¾ãã
ããã«ãä¸é¨ã®é£æºå ã§ã¯ãAPIä»æ§æ¸ã¨ãã¦ãOpenAPIãæä¾ãã¦ããããå ´åãããã®ã§ã1ã®ã¹ããããçç¥ã§ãããã¨ãããããã®å ´åã¯å®è£ ã³ã¹ããå¤§å¹ ã«åæ¸ããã¾ãã
管çã³ã¹ãã»å®è£ ã³ã¹ãã®ã©ã¡ãã®é¢ã§ãã¡ãªããã大ããããããã¯æ¡ç¨ãã¦é常ã«ããã£ãã§ãã
Cloud Run
Goã§å®è£
ãããµã¼ãã¼ãCloud Runã«ãããã¤ãã¦ãã¾ãã
Dockerã¤ã¡ã¼ã¸ãpushããã ãã§ãããã¤ã§ããæ軽ãã«å ãããªã¯ã¨ã¹ãè² è·ã«å¿ãã¦ãèªåã§ã¹ã±ã¼ã«ã¤ã³ã»ã¢ã¦ããã¦ãããç¹ã«é
åãæãã¦æ¡ç¨ãã¾ããã
å®éã«æ¡ç¨ãã¦ã¿ã¦ããããã¤ã®æ軽ãã¯éçºé度ã®è¦³ç¹ãããé常ã«è¯ãã£ãã¨æãã¦ãã¾ãã
Cloud Runã«ã¯ããµã¼ãã¹ã¨ããæ¦å¿µãããããµã¼ãã¹ãã¨ã«ã¹ã±ã¼ãªã³ã°ãã¹ããã¯ãªã©ã®è¨å®ãåå¥ã«è¨å®ãããã¨ãå¯è½ã§ãã
è² è·è©¦é¨ãè¡ããªãããCPUãåæå®è¡æ°ãªã©ã®èª¿æ´ãããµã¼ãã¹ã®åå²ãªã©ãè¡ãã¾ãããããã®è¨å®ãæ¯è¼çç°¡åã«è¡ããã¨ãã§ããããã®å®è£
ã³ã¹ããæãããã¨ãã§ãã¾ããã
ã³ã¼ã«ãã¹ã¿ã¼ãã®åé¡ãããã¾ãããåæã³ã³ããã¯UXã«å½±é¿ãããããæå°ã¤ã³ã¹ã¿ã³ã¹ã1以ä¸ã«è¨å®ãããã¨ã§ãã³ã¼ã«ãã¹ã¿ã¼ããåé¿ãã¦ãã¾ãã
ä¸æ¹ãéåæã³ã³ããã§ã¯ãé·æéã®ãããå¦çã主ãªå½¹å²ã§ãUXã«å½±é¿ã¯ãªãã§ãããã®ãããã³ã¼ã«ãã¹ã¿ã¼ãã許容ç¯å²å
ã¨å¤æããæå°ã¤ã³ã¹ã¿ã³ã¹ã0ã«è¨å®ãã¦ãã©ã³ãã³ã°ã³ã¹ããæãã¦ãã¾ãã
ãã ãã¿ã¤ã ã¢ã¦ãã«é¢ãã¦ã¯èª²é¡ãããã¾ãã
Cloud Runã®ã¿ã¤ã ã¢ã¦ãã¯60åãªã®ã§ãããéåæã³ã³ããã¸ã®ãªã¯ã¨ã¹ãã¯ãCloud Tasksãçµç±ãã¦ãããCloud Tasksã®ã¿ã¤ã ã¢ã¦ãã¯30åã§ãã
ãã®ããããããå¦çã®ä¸éæéããCloud Tasksã®ã¿ã¤ã ã¢ã¦ãã®30åã«ãªã£ã¦ãã¾ãããããè¶
ããå¦çãè¡ãå ´åã¯ãéä¸ã§ã¿ã¤ã ã¢ã¦ããã¦ãã¾ãã¾ãã
ãããåé¿ããããã«ãDBã§ãããå¦çã®ç¶æ
ãä¿æãã¦ãéä¸ã§ã¿ã¤ã ã¢ã¦ããã¦ããåéã§ããããã«ãã¦ããã®ã§ããããã®è¾ºãã¯Cloud Run Jobsã使ããªããã¦ãDBã§ã®ç¶æ
管çããªããããã¨èãã¦ãã¾ãã
ãããããªãã£ããã®
Hasura
Hasuraã¨ã¯ãDBã®ã¹ãã¼ãããããGraphQL APIãèªåçæãã¦ãããOSSã§ãã
æ¡ç¨ã«è³ã£ãçç±ã¯ãä¸è¨ã®éãã§ãã
- DBã®ãã¼ãã«ããããã°APIãèªåçæã§ããã®ã§ãéçºå¹çã®åä¸ãæå¾ ã§ãã
- GUIã§ç°¡åã«èªå¯å¶å¾¡ã§ãã
- é«æ©è½ãªã³ã³ã½ã¼ã«ç»é¢ãçµã¿è¾¼ã¾ãã¦ããããã¤ã°ã¬ã¼ã·ã§ã³ãDBæä½ãGUIã§ç°¡åã«è¡ãã
ããããä¸è¨ã®ç¹ããHasuraã®æ¡ç¨ã¯ãããããªãã£ãã¨æãã¦ãã¾ãã
ãã¼ãã«æ§é ããã®ã¾ã¾GraphQLã¹ãã¼ãã«ãªã£ã¦ãã¾ã
Hasuraã§ã¯ããã¼ãã«æ§é ããã®ã¾ã¾GraphQL APIã®ã¹ãã¼ãã«ãªãã¾ãã
ãã®ãããããã³ãã¨ã³ãã§æ¬²ããå½¢ã§ãã¼ã¿ãåå¾ãããã¨ãã§ãããåå¾ãã¦ãããã¼ã¿ãå å·¥ããå¿
è¦ãããã®ã§ãããã³ãã¨ã³ãã§ã®å¦çãè¥å¤§åãããã¨ãå¤ãã£ãã§ãã
ããã³ãã¨ã³ãã§æ±ããããããã«ãã¼ã¿ã¢ããªã³ã°ãã§ããã®ããGraphQLã®ã¡ãªããã®1ã¤ã§ãããHasuraã使ããã¨ã§ãã®ã¡ãªãããèãã¦ãã¾ãã¾ããã
Hasuraããè¿å´ãããã¨ã©ã¼ã¡ãã»ã¼ã¸ããã¦ã¼ã¶ã¼ãã¬ã³ããªã¼ã§ã¯ãªãã®ã§ãã¦ã¼ã¶ã¼ã«è¡¨ç¤ºããã¡ãã»ã¼ã¸ãæ¯åããã³ãã¨ã³ãã§å¶å¾¡ããå¿
è¦ãããã¾ããã
ã¾ããããã³ãã¨ã³ãã§Queryãå®ç¾©ããéã«ã¯ããã¼ãã«æ§é ãå¿
è¦ã«ãªãã¾ãã
表示ããããã¼ã¿ããã©ã®ãã¼ãã«ã®ã©ã®ã«ã©ã ãªã®ããææ¡ãã¦ãªãã¨ãQueryãå®ç¾©ã§ããªãã§ãã
ãã¼ãã«æ§é ãææ¡ã§ãã¦ããã¨ã³ã¸ãã¢ã§ããã°åé¡ãªãã§ãããããã³ãã¨ã³ãå°ä»»ã®ã¨ã³ã¸ãã¢ã«ã¨ã£ã¦ã¯ããã®ãã£ããã¢ããã大ããªè² æ
ã«ãªããå®è£
ã«è¦æ¦ããå ´é¢ãå¤ãã£ãã§ãã
æ³å®ãããHasuraã®å©ç¨æ©ä¼ãå°ãªãã£ã
Hasuraã§ã¯ãå¤é¨ã®GraphQL APIãçµ±åããããã®ãRemote Schemasã¨ããæ©è½ãæä¾ããã¦ãã¾ãã
ç°¡åãªããªãã¼ã·ã§ã³ã§ããã°Hasuraã§å¯¾å¿ã§ãã¾ãããè¤éãªãã¸ãã¯ãå«ã¾ããå ´åã¯ãRemote Schemasã¨ãã¦çµ±åãã¦ããGraphQLãµã¼ãã¼ã®æ¹ã§å®è£
ãã¦ãã¾ããã
å¼ç¨: Remote Schemas Overview | Hasura GraphQL Docs
ãããã¯ãã®ç¹æ§ä¸ãRemote Schemasã§å¯¾å¿ãå¿ è¦ãªã±ã¼ã¹ãå¤ããªããã¨ã¯ããç¨åº¦äºæ¸¬ãã¦ãã¾ããããããã¯ä¸»ã«Mutationã§ãããQueryå ¨è¬ã¯Hasuraã§å¯¾å¿ãã§ããã¨èãã¦ãã¾ããã
ããããå®éã«ã¯Queryã§ããRemote Schemasã§å®è£
ãããã¨ãå¤ãã£ãã§ãã
ä¸è¨ã§è§¦ããããã«ãããã³ãã¨ã³ãã®å¦çãè¥å¤§åããããå®è£
ã³ã¹ããé«ãåé¡ãçºçãã¦ãã¾ããã
ãã®ãããQueryãRemote Schemasã§å®è£
ããæ¹ããå®è£
ã管çãããããã¨å¤æããQueryãRemote Schemasã§å®è£
ãããã¨ãå¢ãã¾ããã
ã¾ããããã©ã¼ãã³ã¹èµ·å ã§ãHasuraããRemote Schemasã«Queryã移è¡ããã±ã¼ã¹ãããã¾ããã Hasuraã¯ãGraphQLã®QueryãSQLã«å¤æãã¦ãã¼ã¿ã®åå¾ãå å·¥ãè¡ãªã£ã¦ãããçºè¡ãããSQLã¯è¤éã«ãªããã¡ã§ãã
ãã®ãããçºè¡ãããSQLãããã©ã¼ãã³ã¹çã«åé¡ã«ãªãã±ã¼ã¹ãããã¾ããã
ç¹ã«ãAggregation Queriesã¨è¨ãéè¨ç¨ã®Queryãé常ã«éããã¤ã³ããã¯ã¹ã®ä½æãªã©ã§ã¯è§£æ±ºã§ããªãã£ãããããã®å ´åãæçµçã«ã¯ãRemote Schemasã§Queryãå®è£
ãããã¨ã§è§£æ±ºãã¾ããã
ãããã®çç±ãããå½åã®æ³å®ã«æ¯ã¹ã¦Hasuraã®å©ç¨æ©ä¼ãéããã¦ãã¾ããæ¡ç¨ã«ããã¡ãªãããååã«æ´»ãããããªãã£ãã¨æãã¦ãã¾ãã
ãã¼ãã«è¨è¨ããããã«ã¼ã«ãªã
Hasuraã使ç¨ããå ´åã¯ããã¼ãã«ããªãã¨GraphQLã¹ãã¼ããçæããã¾ããã
ãã®ãããéçºæåæã§ã¯ãããã³ãã¨ã³ãã®å®è£
ããã¼ãã«è¨è¨å¾
ã¡ã«ãªã£ã¦ãã¾ããã¨ãããã¾ããã
ãã«ã¹ã¿ãã¯ã«éçºãé²ããå ´åã¯åé¡ãªãã¨æãã¾ãããããã³ãã¨ã³ãã¨ããã¯ã¨ã³ããåãã¦éçºãé²ããå ´åã¯ããã¼ãã«è¨è¨ã®ã¹ã±ã¸ã¥ã¼ã«ãããã³ãã¨ã³ãã®éçºã¹ã±ã¸ã¥ã¼ã«ã«ãã¤ã¬ã¯ãã«å½±é¿ãä¸ãã¦ãã¾ããããåæ¥ãã¦éçºãé²ããéã«ã¯æ³¨æãå¿
è¦ã§ãã
æ©æµãæãã¦ããç¹
å½åã®æ³å®éãã«Hasuraãæ´»ç¨ã§ããªããã¨ãå¤ãã£ãã§ãããæ¡ç¨ãã¦ããã£ãç¹ãããã¾ãã
ã³ã³ã½ã¼ã«ç»é¢ãé常ã«å¤æ©è½ã§ããã¤ã°ã¬ã¼ã·ã§ã³ãDBæä½ãAPIã®å®è¡ãªã©ãéçºã®éç¨ã§å¿
è¦ãªãã®ã¯ã»ã¼å
¨ã¦ã³ã³ã½ã¼ã«ä¸ã§å®çµããã®ã¯ãé常ã«ããã£ãã§ãã
ã¾ããèªå¯å¶å¾¡ã«é¢ãã¦ã¯ãRemote Schemasã¸ã®ãªã¯ã¨ã¹ããå«ãã¦GUIã§ç°¡åã«è¨å®ã§ãã¾ãããã®ãããèªå¯å¨ãã®å®è£
ãå
¨ãä¸è¦ã«ãªããå®è£
ã³ã¹ãã大å¹
ã«åæ¸ã§ãã¾ããã
å
¨ä½ã¨ãã¦ããããã¯ãã®ç¹æ§ã¨åã£ã¦ããªãã£ãã®ã¨ã使ç¨å ´é¢ã®æ³å®ãçãã£ãã®ãåå ã§ãHasuraã®æ¡ç¨ã¯ãããããªãã£ãã¨æãã¦ãã¾ãã
å®éã«æ¡ç¨ãã¦ã¿ã¦ãAPIã®èªåçæã«ããéçºã¹ãã¼ãã®åä¸ã¯é常ã«ãã¯ã¼ãæãã¾ãããPoCãã¹ã¿ã¼ãã¢ãããªã©ã§ã¹ãã¼ããæ±ããããå ´é¢ã§ã¯ãHasuraã®æ¡ç¨ã¯æç¨ã ã¨æãã¾ãã
ãã ãããã³ãã¨ã³ãã¨ã³ã¸ãã¢ã«å¯¾ãã¦ãããç¨åº¦ã®DBããã¼ãã«æ§é ã®ç¥èãæ±ããããã®ã§ãéçºä½å¶ãã¡ã³ãã¼ã®ã¹ãã«ãèæ
®ããå¿
è¦ãããããã§ãã
GORM
éçºå½æã¯ãGoèªä½ã®ç¥è¦ãå°ãªãã£ããããã·ã³ãã«ã§ä½¿ãããããæ¥æ¬èªã®ããã¥ã¡ã³ããå
å®ãã¦ããGORMãæ¡ç¨ãã¾ããã
GORMã«ã¯ããã¤ã°ã¬ã¼ã·ã§ã³æ©è½ãåãã£ã¦ãã¾ããããã¤ã°ã¬ã¼ã·ã§ã³ã¯Hasuraã§è¡ãªã£ã¦ããããããã¡ãã¯ä½¿ç¨ãã¦ãã¾ããã
å®è£ ãé²ãã¦ããä¸ã§ãGORMç¹æã®æåãéç¨ã«èª²é¡ãæããå ´é¢ãå¢ãã¦ãã¾ããã
å ·ä½çã«ã¯GORMã®ã¡ã½ããã使ãéã«ãå¼æ°ãå¼æ°ã«æ¸¡ããæ§é ä½ã®ãã£ã¼ã«ããã¼ãå¤ã®å ´åã«ãæå³ããªãæåã«ãªããã¨ãããã¾ãããä¸è¨ã¯ãã®ä¸ä¾ã§ãã
Find
ã§ç¬¬2å¼æ°ã«ç©ºé
åã渡ãã¨å
¨ä»¶åå¾ã«ãªã
var ids []int db.Find(&users, ids) // SELECT * FROM users;
Updates
ã§æ§é ä½ã®ãã£ã¼ã«ããã¼ãå¤ã ã¨æ´æ°ãããªã
db.Model(&user).Updates(User{Name: "hello", Age: 0, Active: false}) // UPDATE users SET name='hello' WHERE id = 111;
ãããã¯ãããããIssueã§è¨åããã¦ããããå
¬å¼ããã¥ã¡ã³ãã«ãè¨è¼ããã¦ããæåã§ãããæ£ããå®è£
ãã§ãããã©ããã¯å®è£
è
ã®ç¥èéã«ä¾åãã¦ãã¾ãã¾ãã
åä½ç¢ºèªãã¬ãã¥ã¼ã§æ¤ç¥ãããã¨ãå¯è½ã§ããã100%é²ããããã§ã¯ãªãã§ãããå ´åã«ãã£ã¦ã¯ãã°ãå«ãã ã¾ã¾ãããã¤ããã¦ãã¾ãå¯è½æ§ãããã¾ãã
ãã®ãããå®éã«çºè¡ãããSQLã確èªããªããå®è£
ããããæé»çãªæåã«æ³¨æããªããå®è£
ãã¬ãã¥ã¼ãè¡ãªã£ã¦ãã¾ãã
ãããããã§ããã°ãæåã«SQLãæ¸ãã¦ãããããã³ã¼ããçæãããããªsqlcãªã©ã®æ¹ããæåãæçã§æé»çãªæåã«ããåé¡ã¯çºçãã¥ããã®ã§ã¯ã¨æãã¾ããã
Next.js
ããã³ãã¨ã³ãã¯ãNext.jsã®Static Exportsã使ã£ã¦ãSPAãæ§ç¯ãã¦ãã¾ãã
SSR (Server Side Rendering)ãç»åæé©åãªã©ãNext.jsãæä¾ãã¦ããæ©è½ã®å¤ãã¯ããµã¼ãã¼ãå¿
è¦ã¨ãã¾ãã
æ¡ç¨å½æã®è¦ä»¶çã«ããããã®æ©è½ã¯å¿
è¦ãªãã£ãã®ã§ããµã¼ãã¼ãç¨æãã¦Next.jsã使ãã®ã¯ãéç¨ã³ã¹ãã®è¦³ç¹ããtoo matchã ã¨æãã¾ããã
ãã ããã¡ã¤ã«ãã¼ã¹ã«ã¼ãã£ã³ã°ãã¼ãã³ã³ãã£ã°ã§ã®éçºãªã©ããµã¼ãã¼ãç¨æããªãå ´åã§ããæ¡ç¨ããã¡ãªããã¯ããã¾ãã
ã¾ããå
¬å¼ããã¥ã¡ã³ãã®Static Exportsã®ãã¼ã¸ã«ã¯ä¸è¨ã®ãããªè¨è¼ãããã¾ãã
Next.js enables starting as a static site or Single-Page Application (SPA), then later optionally upgrading to use features that require a server.
ãã®è¨è¼ãããèªã¿åããããã«ãã¾ãã¯SPAã¨ãã¦éçºãé²ããå¿
è¦ã«å¿ãã¦ãµã¼ãã¼ã«ç§»è¡ãããã¨ãå¯è½ã§ãã
å°æ¥çã«SSRãªã©ã®æ©è½ãå¿
è¦ã«ãªã£ãéã«ãNext.jsãæ¡ç¨ãã¦ããã°ããã®ç§»è¡ãã¹ã ã¼ãºã«è¡ããã®ã§ã¯ã¨æããNext.js+Static Exportsã¨ããæ¡ãæ¡ç¨ãã¾ããã
ããããå®éã«éçºãé²ããä¸ã§èª²é¡ãããããã®é¸æã«ããã¡ãªããã¯å°ãªãã£ãã¨æãã¦ãã¾ãã
Dynamic Routesã使ããªã
Static Exportsã使ã£ãå ´åããã«ãæã«æ±ºå®ã§ããå ´åãã®ããã¦ãDynamic Routesã使ãã¾ããã
éå»ã®ããã¯ããã°ã§ããåæ§ã®åé¡ã«ã¤ãã¦è¨åããã¦ãã¾ãã
ããã¥ã¡ã³ãã®Supported Featuresã«ãDynamic Routes when using getStaticPathsãã¨ããéããã«ã¼ãã£ã³ã°å ãæéã§ãã«ãæã«æ±ºå®ã§ããã±ã¼ã¹ã§ããã°æå¹ã§ãããããã§ãªãå ´åã¯ã¢ã»ãããposts/[postId].htmlã®ããã«ãã«ãããã¦ãã¾ãã/posts/1ã«ã¢ã¯ã»ã¹ãã¦ããã¡ã¤ã«ãåå¨ããªããã¨ã«ãªã£ã¦ãã¾ãã¾ãã
ãã®ããããã¡ã¤ã«ãåå¨ããªãæ±ãã«ãªãã404.html
ãè¿å´ãããããããã®ä¸ã§ã«ã¼ãã£ã³ã°å¦çãè¡ããã¨ã§ãªãã¨ã解決ãã¦ãã¾ãããç°å¢ã«ãã£ã¦æåã«å·®ãçã¾ãã¦ãã¾ãã¾ãã
ä¸æ¹ã§ããã¼ã«ã«ã§ã¯Next.jsã®devãµã¼ãã¼ãé常éãã«ã¼ãã£ã³ã°ãè¡ããããããããåä½ã(ç¹æ®ãªéçºç°å¢ãç¨æããªãéã)åç¾ã§ãã¾ãããéçºæã«ã¯åç¾ã§ããªãæåãæ¬çªã§çºçãããã¨ã¯å¤§ããªæ¸å¿µç¹ã§ãã
ãã®åé¡ã¯éçºåæã«èªèã¯ãã¦ãã¾ããããåé¡ã«ãªãã±ã¼ã¹ã¯å°ãªãã®ã¨ãææªQAã§æ¤ç¥ã§ããã¨ããçç±ã§è»½è¦ãã¦ãã¾ããã
ããããã¡ããã©æè¿ãä¸è¨ã®ãªã¹ã¯ãé¡å¨åããã±ã¼ã¹ãããã¾ããã
å¤é¨ãµã¤ãããã®ãªãã¤ã¬ã¯ããçºçããæ©è½ã®å®è£
ãè¡ãªã£ãéã«ãå¤é¨ãµã¤ãããã®ãªãã¤ã¬ã¯ãå¾ã«router.pathname
ã使ç¨ããå¦çãããã¾ããã
ãã®éã«ããã®å¤ã404
ã«ãªããããæ£å¸¸ã«åä½ããªããã¨ããQAã®ã¿ã¤ãã³ã°ã§çºè¦ãã¾ããã
ä¿®æ£ããéã«ãããã¼ã«ã«ã§next build
ãããããæåã§stgç°å¢ã«ãããã¤ããå¿
è¦ããããåä½ç¢ºèªã«æéãããã£ã¦ãã¾ã£ã¦ãã¾ããã
ãã®åé¡ã¯æçµçã«QAã§æ¤ç¥ã§ãããã®ã®ãåä½ç¢ºèªã«æéããããã¾ãããä»å¾ããã®ãããªãªã¹ã¯ãæ±ãç¶ããã®ã¯ãã¯ãé¿ãããã¨æãã¾ããã
ãµã¼ãã¼ã¸ã®ç§»è¡ã³ã¹ã
å°æ¥çã«SSRãå¿ è¦ã«ãªã£ãå ´åãå å³ãã¦ãNext.jsãæ¡ç¨ãã¾ãããããã®èæ ®ãä¸è¦ã ã£ãã¨æãã¦ãã¾ãã
ä»®ã«SSRãå¿
è¦ã«ãªã£ãå ´åããµã¼ãã¼ãç¨æãã¦ããããã¤å
ãå¤æ´ããå¿
è¦ãããã¾ããã移è¡ã³ã¹ãã¯é«ãã§ãã
ãµã¼ãã¼ã®é¸å®ãè² è·è©¦é¨ãå
¨ä½çãªãã°ã¬ãã§ãã¯ãªã©ãããªã大æãããªä½æ¥ãå¿
è¦ã§ãNext.jsãæ¡ç¨ãã¦ããããã¨è¨ã£ã¦ãç°¡åã«ç§»è¡ã§ãããã®ã§ã¯ããã¾ããã
ã¡ããã©ãªãªã¼ã¹ã®å°ãåã«ã大éãã¼ã¿ã表示ããããã¤ããã©ã¦ã¶ã®Ctrl+Fã§ãã¼ã¸å
æ¤ç´¢ããããã¨ããè¦ä»¶ãããã¾ããã
åç´ã«ä»®æ³ã¹ã¯ãã¼ã«ãå°å
¥ããã ãã§ã¯ããã©ã¦ã¶ã®Ctrl+Fãæ©è½ããªãããããµã¼ãã¼ã«ç§»è¡ãã¦SSRã§å¯¾å¿ããæ¡ãæ¤è¨ãã¾ããããéçºå·¥æ°ã¨ã®å
¼ãåãã§ãã®æ¡ã¯è¦éãã¾ããã
ä»®ã«ãã¹ã±ã¸ã¥ã¼ã«ã«ä½è£ããã£ãã¨ãã¦ãã1ã¤ã®æ©è½ã®ããã«ãããã¤å
ãå¤æ´ããã¨ããææ決å®ãè¡ãã®ã¯ãªããªãé£ããã§ãã
ã¢ãããã¼ãã¸ã®è¿½å¾
Static Exportsã使ã£ã¦ããã¨ã¯ãããNext.jsèªä½ã®ã¢ãããã¼ãã¸ã®è¿½å¾ã¯å¿
è¦ã§ãã
ç¾å¨ã¯ãç¹ã«App Routerãå¿
è¦ã¨ããæ©è½ããªããããPages Routerã使ãç¶ãã¦ãã¾ãããä»®ã«Pages Routerãå»æ¢ããããã¨ãããã°ãApp Routerã¸ã®ç§»è¡ã¯é¿ãããã¾ããã
å
¨ä½çã«ã使ã£ã¦ããªãæ©è½ãå¤ããããNext.jsãæ¡ç¨ãã¦ããã¡ãªããã«æ¯ã¹ãã¨ãã¢ãããã¼ãã¸ã®è¿½å¾ã³ã¹ããé«ããªã£ã¦ããã¨æãã¦ãã¾ãã
ãããã®çç±ãããNext.jsã®æ¡ç¨ã¯ãããããªãã£ãã¨æãã¦ãã¾ãã
çµå±ã®ã¨ããããµã¼ãã¼ãå¿
è¦ã«ãªã£ãã¿ã¤ãã³ã°ã§ããããªãã®ç§»è¡ã³ã¹ããããããæ°è»½ã«ç§»è¡ãã§ããªããããä¸éå端ã«å
ãè¦æ®ãã¦æ¡ç¨ãã¦ãã¾ã£ããªã¨æãã¦ãã¾ãã
ããã§ããã°ãä¸è¨ã®ãããªãªã¹ã¯ãæ±ãã¦Next.jsã§SPAãæ§ç¯ããããããæåãããµã¼ãã¼ãç¨æãã¦éç¨ããããå¿
è¦ã«ãªãã¿ã¤ãã³ã°ã¾ã§ã¯ãã¬ã¼ã ã¯ã¼ã¯ã¯æ¡ç¨ãããReact+Viteãªã©ã§SPAãæ§ç¯ããã®ãè¯ãã¨æãã¾ãã
Apollo Client
GraphQLã¯ã©ã¤ã¢ã³ãã«ã¯ãApollo Clientãæ¡ç¨ãã¾ããã
æåãªã©ã¤ãã©ãªã§ããããæ
å ±éãå¤ããRelayã¨æ¯è¼ãã¦å¦ç¿ã³ã¹ããä½ãå°å
¥ããããç¹ã«é
åãæããæ¡ç¨ã«è³ãã¾ããã
éä¸ã§Relayã¸ã®ç§»è¡ãæ¤è¨ãã¾ããããHasuraã¨ã®å
¼ãåãã§æ¡ç¨ãè¦éã*2ãApollo Clientã使ãç¶ãã¦ãã¾ãã
å½åã¯Apollo Clientã®ãã£ãã·ã¥æ©æ§ãç©æ¥µçã«æ´»ç¨ãã¦ãä¸è¦ãªãªã¯ã¨ã¹ããæ¸ãããã¨ãã§ããã¨èãã¦ãã¾ããã
ãããããããã¯ãã®ç¹æ§ä¸ãæ¤ç´¢ãå¤ãã»ããã¦ã¼ã¶ã¼ãé¢ä¸ããªãã·ã¹ãã é£æºã§ãã¼ã¿ãä½æãããã±ã¼ã¹ãå¤ããææ°ã®ãã¼ã¿ã表示ãããã¨ã®éè¦åº¦ãé«ãã§ãããã®ããããã£ãã·ã¥ã使ããã«ããããã¯ã¼ã¯ãªã¯ã¨ã¹ããè¡ãå ´é¢ãæ³å®ãããå¤ããªãã¾ããã
ææ°ã®ãã¼ã¿ã®è¡¨ç¤ºãå¿
è¦ãªå ´é¢ã§ããã£ãã·ã¥ã使ããã¦ãã¾ããã¨ããããUXã«å½±é¿ãåºããã¨ãããã¾ããã
ã¾ãããã£ãã·ã¥æ©æ§ã«é¢é£ããæåã®å¤æ´ã度ã
ããç¹ã課é¡ã«æãã¦ãã¾ãã
ãã¡ãã®Issueã§ã¯ããã¼ã¸ã§ã³ã¢ããã«ãã£ã¦onComplete
ã®æåãå¤æ´ãããã®ããå¤ãæåããã°ã¨èªèãã¦ãã人ãããã°ãæ°ããæåããã°ã¨èªèãã¦ãã人ããã¾ãã
ãããã¯ãããã¥ã¡ã³ãã«ã¯æè¨ããã¦ããªããããæåãå¤ãã£ããã¨ã«æ°ã¥ããããã°ãå¼ãèµ·ããå¯è½æ§ãããã¾ãã
ãããã®èæ¯ãããéä¸ããå
¨ä½çã«ãã£ãã·ã¥ã使ããªãæ¹éã«å¤æ´ãã¾ããã
ããã«ãããä¸è¨ã®åé¡ã¯è§£æ¶ããã¾ãããããã£ãã·ã¥ã使ããªãå ´åãApollo Clientã使ãã¡ãªãããã»ã¨ãã©ãªããªã£ã¦ãã¾ãã¾ããã
éä¸ã§æ¹éãå¤ãã£ããã¨ããããApollo Clientã®æ©è½ãæ´»ç¨ãããã¨ãã§ãããæ¡ç¨ã«ããã¡ãªãããæ´»ãããããªãã£ãã¨æãã¦ãã¾ãã
ã¾ã¨ã
ä»åã¯ãæè¡é¸å®ã«é¢ããæ¯ãè¿ããç´¹ä»ãã¾ããã
大ã¯å°ãå
¼ããã®ã§ãå¿
è¦ã¨ãã¦ããæ©è½ä»¥ä¸ã®æè¡ãæ¡ç¨ãã¦ããè¦ä»¶ãæºãããã¨ã¯ã§ãã¾ãã
ãããããã®å ´åã¯ãéç¨ã³ã¹ããå¦ç¿ã³ã¹ããé«ããªããããç·åçã«å¤æããæã«ããããã®ã³ã¹ããæ¡ç¨ã«ããã¡ãªãããä¸åãå ´åãããã¾ãã
ç¹ã«ä»åç´¹ä»ããæè¡ã¯ãå¤æ´ã容æã§ã¯ãªããã®ãå¤ããæ¯ãè¿ã£ãçµæããããããªãã£ãã¨å¤æãã¦ããããã«å¤æ´ãããã¨ã¯ã§ããªãã§ãã
ãã®ãããæè¡é¸å®ã®éã¯ãè¦ä»¶ãæ£ç¢ºã«è¦æ¥µããä¸ã§ãã§ããã ãè¦ä»¶ã«ã¸ã£ã¹ããã£ããããæè¡ãé¸å®ãããã¨ãæ¹ãã¦éè¦ã ã¨æãã¾ããã
ä»åã®è¨äºã¯ãEXSã®è¦ä»¶ãåæã¨ãããã®ã«ãªãã®ã§ãããã¾ã§æè¡é¸å®ã®ä¸ä¾ã¨ãã¦åèã«ãã¦ããã ããã¨å¹¸ãã§ãï¼
æå¾ã«ããã¤ã»ã«ã§ã¯ã¨ã³ã¸ãã¢ãåéãã¦ãã¾ããå°ãã§ãæ°ã«ãªã£ãæ¹ã¯ãã²ãå¿åãå¾ ã¡ãã¦ãã¾ãã
https://herp.careers/v1/buyselltech/04-VP5QnJ0aM
ææ¥ã®ãã¤ã»ã«ãã¯ããã¸ã¼ãº Advent Calendar 2024ã¯è¤æ¾¤ããã®ãå°æ°ç²¾éã§ã¦ã¼ã¶ã¼ã®ä¿¡é ¼ãåã¡åãï¼å¤§è¦æ¨¡ãªãªã¼ã¹ãä¹ãè¶ããããã®ã·ã¹ãã ç£è¦ã¨ã¦ã¼ã¶ã¼ãµãã¼ããã§ãããã¡ãããã²ä½µãã¦èªãã§ã¿ã¦ãã ããï¼
*1:samber/loã使ãã°å¯è½ã§ãããçµ±ä¸æ§ãä¿ã¤ããã«å°å ¥ãã¦ãã¾ãã
*2:詳細ã¯ãã¡ãã®è¨äºã§è§£èª¬ãã¦ãã¾ã