{"id":18087,"date":"2022-10-08T02:59:56","date_gmt":"2022-10-07T17:59:56","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=18087"},"modified":"2023-05-27T17:43:35","modified_gmt":"2023-05-27T08:43:35","slug":"%e3%80%90react%e3%80%91%e3%80%8chasura%e3%80%8d%e3%81%a8%e3%80%8cgraphql%e3%80%8d%e3%81%ae%e9%80%a3%e6%90%ba","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=18087","title":{"rendered":"\u3010Next.js\u3011\u300cHasura\u300d\u3068\u300cApollo Client\u300d\u306e\u9023\u643a"},"content":{"rendered":"<p>Next.js\u3067\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u3068\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306e\u51e6\u7406\u3092\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067ApolloClient\u3092\u4f7f\u3046\u5834\u5408\u306f\u51e6\u7406\u306e\u5207\u308a\u5206\u3051\u304c\u91cd\u8981\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u5b9f\u884c\u3055\u308c\u308b\u7b87\u6240\uff08SSG\u3001ISR\uff1agetStaticProps\u3001getStaticPaths)<\/h2>\n<p>Next.js\u306f\u6bce\u56deApollo Client\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3057\u306a\u3055\u3044\u3068\u8b33\u3063\u3066\u3044\u307e\u3059\u3002\u3061\u3083\u3093\u3068\u3053\u306e\u90e8\u5206\u3092\u610f\u8b58\u3057\u306a\u3044\u3068Next.js\u306eSSG\u3084ISR\u304c\u5909\u306a\u6319\u52d5\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u610f\u8b58\u3057\u3066\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3067\u5b9f\u884c\u3055\u308c\u308b\u7b87\u6240<\/h2>\n<p>\u6700\u521d\u306b1\u56de\u3060\u3051Apollo Client\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308c\u3070\u826f\u3044\u3067\u3059\u3088\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>Apollo Client\u306e\u5b9f\u88c5\u4f8b<\/h2>\n<pre class=\"lang:default decode:true\">import {\r\n  ApolloClient,\r\n  HttpLink,\r\n  InMemoryCache,\r\n  NormalizedCacheObject,\r\n} from '@apollo\/client'\r\nimport 'cross-fetch\/polyfill'\r\n\r\nlet apolloClient: ApolloClient&lt;NormalizedCacheObject&gt; | undefined\r\nconst createApolloClient = () =&gt; {\r\n  return new ApolloClient({\r\n    ssrMode: typeof window === 'undefined',\r\n    link: new HttpLink({\r\n      uri: \"Hasura\u306eURL\",\r\n    }),\r\n    cache: new InMemoryCache(),\r\n  })\r\n}\r\nexport const initializeApollo = (initialState = null) =&gt; {\r\n  const _apolloClient = apolloClient ?? createApolloClient()\r\n  \/\/ For SSG and SSR always create a new Apollo Client\r\n  if (typeof window === 'undefined') return _apolloClient\r\n  \/\/ Create the Apollo Client once in the client\r\n  if (!apolloClient) apolloClient = _apolloClient\r\n\r\n  return _apolloClient\r\n}\r\n<\/pre>\n<h3>ssrMode: typeof window === 'undefined'<\/h3>\n<p>window\u306f\u30d6\u30e9\u30a6\u30b6\u3067\u5b9f\u884c\u3057\u3066\u3044\u308b\u304b\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u3058\u3083\u306a\u3044(\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9)\u306e\u5834\u5408\u306btrue\u304c\u5165\u308a\u307e\u3059\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u3067\u5b9f\u884c\u3059\u308b\u5834\u5408\u306ffalse\u304c\u5165\u308a\u307e\u3059\u3002<\/p>\n<h3>cache: new InMemoryCache(),<\/h3>\n<p>\u3053\u3061\u3089\u306f\u304a\u6c7a\u307e\u308a\u306e\u6587\u6cd5\u3067Apollo Client\u304c\u81ea\u52d5\u3067cache\u306b\u5024\u3092\u683c\u7d0d\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h3>initializeApollo\u95a2\u6570<\/h3>\n<p>window\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5229\u7528\u3057\u3066\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u306f\u6700\u521d\u306e1\u56de\u3060\u3051\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3057\u3066\u3001\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306e\u5834\u5408\u306f\u547c\u3073\u51fa\u3059\u305f\u3073\u306bApolliClient\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308b\u3068\u3044\u3046\u3088\u3046\u306a\u95a2\u6570\u5185\u5bb9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u547c\u3073\u51fa\u3057\u65b9<\/h3>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u300cApolloProvider\u300d\u3092\u4f7f\u3063\u3066Next.js\u306e_app.tsx\u306a\u3069\u306b\u6e21\u3057\u3066\u3042\u3052\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">import '..\/styles\/globals.css'\r\nimport { AppProps } from 'next\/app'\r\nimport { ApolloProvider } from '@apollo\/client'\r\nimport { initializeApollo } from '..\/lib\/apolloClient'\r\n\r\nfunction MyApp({ Component, pageProps }: AppProps) {\r\n  const client = initializeApollo()\r\n  return (\r\n    &lt;ApolloProvider client={client}&gt;\r\n      &lt;Component {...pageProps} \/&gt;\r\n    &lt;\/ApolloProvider&gt;\r\n  )\r\n}\r\n\r\nexport default MyApp\u3053<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5185\u306e\u3042\u3089\u3086\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067Apollo Client\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u304b\u3089\u306e\u547c\u3073\u51fa\u3057\uff1a\u30af\u30a8\u30ea<\/h3>\n<pre class=\"lang:default decode:true\">import { useQuery } from '@apollo\/client'\r\nimport { GET_USERS } from '..\/queries\/queries'\r\nimport { GetUsersQuery } from '..\/types\/generated\/graphql' \/\/ graphql-codegen\u3067\u4f5c\u3089\u308c\u305f\u578b\u30d5\u30a1\u30a4\u30eb\r\n\r\nconst FetchMain = () =&gt; {\r\n  const { data, error } = useQuery&lt;GetUsersQuery&gt;(GET_USERS, {\r\n    \/\/fetchPolicy: 'network-only',\r\n    fetchPolicy: 'cache-and-network',\r\n    \/\/fetchPolicy: 'cache-first',\r\n    \/\/fetchPolicy: 'no-cache',\r\n  })\r\n\r\n  return (\r\n    &lt;Main \/&gt;\r\n  )\r\n}\r\n\r\n<\/pre>\n<h4>fetchPolicy<\/h4>\n<p><span style=\"color: #ff0000;\"><strong>\u57fa\u672c\u6700\u521d\u306b\u8aad\u307f\u8fbc\u307f\u306b\u884c\u304f\u753b\u9762<\/strong><\/span>\u306b\u3064\u3051\u308b\u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th>\u5024<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>cache-first<\/td>\n<td>fetchPolicy\u306e\u6307\u5b9a\u3092\u7701\u7565\u3057\u305f\u5834\u5408\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u898b\u306b\u3044\u304f\u52d5\u304d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u6ce8\u610f\u70b9\u3068\u3057\u3066\u306f\u3001\u4eee\u306b\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u65b0\u3057\u3044\u30c7\u30fc\u30bf\u304c\u751f\u6210\u3055\u308c\u305f\u3068\u3057\u3066\u3082<span style=\"color: #ff0000;\"><strong>\u6700\u521d\u306b\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3060\u3051\u3092\u8868\u793a\u3057\u7d9a\u3051\u308b<\/strong><\/span>\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u30c7\u30fc\u30bf\u304c\u983b\u7e41\u306b\u5909\u308f\u308b\u3088\u3046\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u671b\u307e\u3057\u304f\u306a\u3044\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>network-only<\/td>\n<td>\u6bce\u56de\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u308f\u305aGraphQL\u306e\u30b5\u30fc\u30d0\u30fc\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002\u3055\u3089\u306b\u6bce\u56decache\u306b\u306f\u7d50\u679c\u3092\u683c\u7d0d\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>\u901a\u4fe1\u4e2d\u306f\u4f55\u3082\u30c7\u30fc\u30bf\u304c\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u3002\u901a\u4fe1\u5b8c\u4e86\u5f8c\u306b\u4e00\u6c17\u306b\u30c7\u30fc\u30bf\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>cache-and-network<\/td>\n<td>network-only\u3068\u3088\u304f\u4f3c\u3066\u3044\u307e\u3059\u3002\u4e00\u70b9\u9055\u3044\u304c\u3042\u308b\u3068\u3059\u308c\u3070\u901a\u4fe1\u4e2d\u306fcache\u306e\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u901a\u4fe1\u5b8c\u4e86\u5f8c\u306f\u6700\u65b0\u306e\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3057\u3066\u304f\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u591a\u304f\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u3053\u3061\u3089\u3092\u9078\u3093\u3067\u304a\u3051\u3070\u554f\u984c\u306a\u3044<\/strong><\/span>\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>no-cache<\/td>\n<td>\u3053\u308c\u306e\u5834\u5408\u3001\u305d\u3082\u305d\u3082cache\u306b\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3057\u306a\u3044\u306e\u3067\u3001\u5225\u753b\u9762\u3067@client\u3067cache\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3068\u3057\u3066\u3082\u5024\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002\u6bce\u56de\u3001\u30b5\u30fc\u30d0\u30fc\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u3067\u3001\u901a\u5e38\u306eJS\u306eaxios\u3067\u30b5\u30fc\u30d0\u30fc\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u624b\u6cd5\u3068\u4f3c\u305f\u624b\u6cd5\u306b\u306a\u308a\u307e\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u8aad\u307f\u8fbc\u3080\u304b\u3092\u30af\u30a8\u30ea\u5074\u3067\u5236\u5fa1\u3059\u308b\u65b9\u6cd5(@client)<\/h5>\n<p><span style=\"color: #ff0000;\"><strong>\u3059\u3067\u306bcache\u304c\u3042\u308b\u3053\u3068\u304c\u524d\u63d0\u306e\u753b\u9762<\/strong><\/span>\u306a\u3069\u3067\u4f7f\u3046\u624b\u6cd5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">export const GET_USERS_LOCAL = gql`\r\n  query GetUsers {\r\n    users(order_by: { created_at: desc }) @client {\r\n      id\r\n      name\r\n      created_at\r\n    }\r\n  }\r\n`<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>@client<\/strong><\/span>\u3068\u3044\u3046\u3082\u306e\u3092\u3064\u3051\u307e\u3059\u3002\u3053\u308c\u3092\u3064\u3051\u305f\u30af\u30a8\u30ea\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u3042\u308c\u3070\u305d\u308c\u3092\u8aad\u307f\u8fbc\u3093\u3067\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u5834\u5408\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u306efetchPolicy\u3092\u6307\u5b9a\u3057\u305f\u3068\u3057\u3066\u3082\u610f\u5473\u3092\u306a\u3055\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h4>data<\/h4>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b__typename\u306e\u90e8\u5206\u3082\u3084\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-18104\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-08-9.32.41-1024x103.png\" alt=\"\" width=\"1024\" height=\"103\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-08-9.32.41-1024x103.png 1024w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-08-9.32.41-300x30.png 300w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-08-9.32.41-768x77.png 768w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-08-9.32.41.png 1454w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>Apollo Client\u3067\u306f\u3053\u306e__typename\u3001id\u3092\u30ad\u30fc\u306b\u3057\u3066cache\u306b\u4fdd\u5b58\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u63a2\u3057\u306b\u304f\u3044\u30e1\u30ab\u30cb\u30ba\u30e0\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u304b\u3089\u306e\u547c\u3073\u51fa\u3057\uff1a\u767b\u9332\u7cfb<\/h3>\n<pre class=\"lang:default decode:true\">import { useMutation } from '@apollo\/client'\r\nimport {CREATE_USER\u3000} from '..\/queries\/queries'\r\nimport {\u3000CreateUserMutation\u3000} from '..\/types\/generated\/graphql'\r\n\r\n  const [insert_users_one] = useMutation&lt;CreateUserMutation&gt;(CREATE_USER, {\r\n    update(cache, { data: { insert_users_one } }) {\r\n      const cacheId = cache.identify(insert_users_one)\r\n      cache.modify({\r\n        fields: {\r\n          users(existingUsers, { toReference }) {\r\n            return [toReference(cacheId), ...existingUsers]\r\n          },\r\n        },\r\n      })\r\n    },\r\n  })\r\n\r\n\u3000\u3000\u3000\u3000\/\/ \u767b\u9332\u30dc\u30bf\u30f3\u62bc\u4e0b\u6642\u306e\u51e6\u7406\r\n  const handleSubmit = async (e: FormEvent&lt;HTMLFormElement&gt;) =&gt; {\r\n    e.preventDefault()\r\n     await insert_users_one({variables: {name: editedUser.name }})\r\n  }\r\n\r\n<\/pre>\n<p>insert\u306fApollo\u304c\u81ea\u52d5\u3067cache\u3092\u66f4\u65b0\u3057\u3066\u304f\u308c\u306a\u3044\u306e\u3067\u66f4\u65b0\u51e6\u7406\u3092\u5225\u9014update\u3068\u3044\u3046\u95a2\u6570\u3092\u4f7f\u3063\u3066\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<div>\n<h4>insert_users_one<\/h4>\n<div>Hasura\u304b\u3089\u8fd4\u3063\u3066\u304f\u308b\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<\/div>\n<div><\/div>\n<\/div>\n<h4>cache.identify<\/h4>\n<p>Apollo\u306e\u6a5f\u80fd\u3067\u3059\u3002\u65b0\u898f\u3067\u767b\u9332\u3057\u305f\u30c7\u30fc\u30bf\u306ecache\u306eid\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>cache.modify({fields: {<\/h4>\n<p>Apollo\u306ecache\u3092\u66f8\u304d\u63db\u3048\u307e\u3059\u3002\u7b2c\u4e00\u5f15\u6570\u306b\u66f8\u304d\u63db\u3048\u305f\u3044\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h4>toReference(cacheId)<\/h4>\n<p>Apollo\u306e\u6a5f\u80fd\u3067ID\u306b\u7d10\u3065\u3044\u305f\u30c7\u30fc\u30bf\u3092cache\u304b\u3089\u53c2\u7167\u3067\u304d\u307e\u3059\u3002\u65e2\u5b58\u306ecache\u306e\u914d\u5217\u306e\u5148\u982d\u306b\u4ecaHasura\u306b\u767b\u9332\u3057\u305f\u30c7\u30fc\u30bf\u3092\u8db3\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u304b\u3089\u306e\u547c\u3073\u51fa\u3057\uff1a\u66f4\u65b0\u7cfb<\/h3>\n<pre class=\"lang:default decode:true\">import { useMutation } from '@apollo\/client'\r\nimport {UPDATE_USER\u3000} from '..\/queries\/queries'\r\nimport {\u3000UpdateUserMutation\u3000} from '..\/types\/generated\/graphql'\r\n\r\n  const [update_users_by_pk] = useMutation&lt;UpdateUserMutation&gt;(UPDATE_USER)\r\n\r\n  const handleSubmit = async (e: FormEvent&lt;HTMLFormElement&gt;) =&gt; {\r\n    e.preventDefault()\r\n      try {\r\n        await update_users_by_pk({\r\n          variables: {\r\n            id: editedUser.id,\r\n            name: editedUser.name,\r\n          },\r\n        })\r\n     }\r\n }\r\n<\/pre>\n<p>update\u306fApollo\u304c\u81ea\u52d5\u3067cache\u3092\u66f4\u65b0\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h3>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5074\u304b\u3089\u306e\u547c\u3073\u51fa\u3057\uff1a\u524a\u9664\u7cfb<\/h3>\n<pre class=\"lang:default decode:true\">import { useMutation } from '@apollo\/client'\r\nimport {DELETE_USER\u3000} from '..\/queries\/queries'\r\nimport {\u3000DeleteUserMutation\u3000} from '..\/types\/generated\/graphql'\r\n\r\n  const [delete_users_by_pk] = useMutation&lt;DeleteUserMutation&gt;(DELETE_USER, {\r\n    update(cache, { data: { delete_users_by_pk } }) {\r\n      cache.modify({\r\n        fields: {\r\n          users(existingUsers, { readField }) {\r\n            return existingUsers.filter(\r\n              (user) =&gt; delete_users_by_pk.id !== readField('id', user)\r\n            )\r\n          },\r\n        },\r\n      })\r\n    },\r\n  })\r\n\r\n  \/\/ \u524a\u9664\u30dc\u30bf\u30f3\u62bc\u4e0b\u6642\u306e\u51e6\u7406\r\n  onClick={async () =&gt; {\r\n     await delete_users_by_pk({variables: {id: user.id\u3000}})\r\n   }}<\/pre>\n<p>delete\u306fApollo\u304c\u81ea\u52d5\u3067cache\u3092\u66f4\u65b0\u3057\u3066\u304f\u308c\u306a\u3044\u306e\u3067\u66f4\u65b0\u51e6\u7406\u3092\u5225\u9014update\u3068\u3044\u3046\u95a2\u6570\u3092\u4f7f\u3063\u3066\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>readField<\/h4>\n<p>Apollo\u306e\u6a5f\u80fd\u3067\u3001cache\u304b\u3089\u4efb\u610f\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u8aad\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Next.js\u3067\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u3068\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306e\u51e6\u7406\u3092\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067ApolloClient\u3092\u4f7f\u3046\u5834\u5408\u306f\u51e6\u7406\u306e\u5207\u308a\u5206\u3051\u304c\u91cd\u8981\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002 \u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u5b9f\u884c\u3055\u308c\u308b\u7b87\u6240\uff08SSG\u3001ISR\uff1agetStatic [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[125,151,119,116],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18087"}],"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=18087"}],"version-history":[{"count":22,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18087\/revisions"}],"predecessor-version":[{"id":20065,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/18087\/revisions\/20065"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18087"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}