<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>QUARTETCOM TECH BLOG</title>
    <atom:link href="https://tech.quartetcom.co.jp/feed.xml" rel="self" type="application/rss+xml"/>
    <link>https://tech.quartetcom.co.jp/</link>
    <description>カルテットコミュニケーションズ開発部ブログ</description>
    <pubDate>Mon, 16 Mar 2026 09:12:44 +0900</pubDate>
    
    
    
      



      <item>
        <title>Symfonyの.envファイルをうっかり git プッシュから守る方法 | QUARTETCOM TECH BLOG</title>
        
        
        <category>Symfony</category>
        
        <link>https://tech.quartetcom.co.jp/2026/03/16/protect-symfony-credential/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2026/03/16/protect-symfony-credential/</guid>
        <description>
&lt;p&gt;Symfony でアプリ開発をしていると &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; にクレデンシャルをハードコードすることがありますが、センシティブな情報をプレーンテキストで扱うことに若干の怖さを感じています。かんたんにリネームもファイルコピーもできますし GitHub リポジトリに間違えてプッシュしちゃったら怖いですよね。&lt;/p&gt;

&lt;p&gt;そんなうっかり操作のヒヤリハットを何らかの仕組みで防止できないか調べてみました。&lt;/p&gt;

&lt;h2 id=&quot;はじめに&quot;&gt;はじめに&lt;/h2&gt;

&lt;p&gt;この記事の「クレデンシャル」とは Symfony アプリ内でクローズドに利用する接続情報やトークンのことを示しています。パラメータを経由してサービスクラスに注入しサードパーティベンダーの認証などに使用するイメージです。&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# .env.local&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;APY_KEY=1234abcd&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;SLACK_TOKEN=xoxb-000000000000-EXAMPLE-TOKEN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# config/services.yaml&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;apiKey&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;%env(APY_KEY)%&apos;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;slackToken&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;%env(SLACK_TOKEN)%&apos;&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;App\Command\SomeService&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;arguments&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;$apiKey&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;%apiKey%&apos;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;$slackToken&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;%slackToken%&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;クレデンシャルは API キー / OAuth 認証トークン / デベロッパートークンなどさまざまな種類があり、ハードコード先も &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.*&lt;/code&gt; だけでなく &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.key&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.yaml&lt;/code&gt; などバリエーションがあります。広範囲に散らばっているクレデンシャルを守るには、いくつかの方法を組み合わせて多層防御するのがベターと言えそうです。&lt;/p&gt;

&lt;h2 id=&quot;envlocal-を-git-で追跡しないgitignore&quot;&gt;.env.local を git で追跡しない：.gitignore&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://git-scm.com/docs/gitignore&quot;&gt;gitignore&lt;/a&gt; は基本的でシンプルな方法です。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt; に書いたパターンにマッチすると git で追跡されず、ステージもコミットもされません。&lt;a href=&quot;https://symfony.com/doc/current/setup/symfony_cli.html&quot;&gt;Symfony CLI&lt;/a&gt; でプロジェクトを作成するとプロジェクトに最適な &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt; が作成されます。&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# .gitignore&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;###&amp;gt; symfony/framework-bundle ###&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;/.env.local&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;/.env.local.php&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;/.env.*.local&lt;/span&gt;
&lt;span class=&quot;nn&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;けれどもプロジェクトは常に Symfony CLI で構築されるとは限りません。別プロジェクトからソースコードを流用したり、ゼロベースからディレクトリを構成することもあるでしょう。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/github/gitignore&quot;&gt;https://github.com/github/gitignore&lt;/a&gt; のようなテンプレートを使って &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt; を作成した場合 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.*&lt;/code&gt; はその対象に含まれていないかもしれません。記事執筆時点の Symfony 最新バージョンは &lt;a href=&quot;https://symfony.com/blog/symfony-8-0-6-released&quot;&gt;v8.0.6&lt;/a&gt; ですがテンプレートは v4 以降のリリースに追随していないように見えます。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/github/gitignore/blob/b4105e73e493bb7a20b5d7ea35efd5780ca44938/Symfony.gitignore&quot;&gt;gitignore
/Symfony.gitignore&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;グローバル設定の &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.config/git/ignore&lt;/code&gt; に &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.*&lt;/code&gt; と書いてあるから安全！という思い込みもうっかりミスを誘発します。新しいデバイスをセットアップした時、このディレクトリの同期作業をうっかり忘れてしまうかもしれないからです。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt; による追跡防止は &lt;strong&gt;開発の基本であって過信しないこと&lt;/strong&gt; というのが私の考えです。&lt;/p&gt;

&lt;h2 id=&quot;envlocal-をコミットしない1password-local-env-files&quot;&gt;.env.local をコミットしない：1Password Local .env files&lt;/h2&gt;

&lt;p&gt;1Password は有償のパスワードマネージャーです。&lt;br /&gt;
2025/10 に「Local .env files」というベータ版機能がリリースされました。この機能は &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env&lt;/code&gt; ファイルを安全な場所に退避し、プロセスからの読み取りに開発者の許可を必要とします。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://1password.com/blog/1password-environments-env-files-public-beta&quot;&gt;Introducing new .env file support in 1Password environments | 1Password&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1Password アプリで「環境」を追加しプロジェクトを判別する任意の名前を付与します。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2026-03-protect-symfony-credential/image-7.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;追加した環境に &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; をインポートします。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2026-03-protect-symfony-credential/image-1.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;プロジェクトの既存の &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; を削除し、替わりに 1Password のファイルを保存（マウント）します。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2026-03-protect-symfony-credential/image-3.png&quot; width=&quot;800&quot; /&gt;
&lt;img src=&quot;/assets/img/2026-03-protect-symfony-credential/image-6.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;マウントした &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; はファイルの実体ではなく UNIX の &lt;a href=&quot;https://ja.wikipedia.org/wiki/%E5%90%8D%E5%89%8D%E4%BB%98%E3%81%8D%E3%83%91%E3%82%A4%E3%83%97&quot;&gt;名前付きパイプ&lt;/a&gt; です。その内容は 1Password によって保護されているため、プロセスが読み取ろうとすると認証ダイアログが表示されます。許可すると 1Password アプリのロックがかかるまでアクセスが可能になります。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2026-03-protect-symfony-credential/image-4.png&quot; width=&quot;800&quot; /&gt;
&lt;img src=&quot;/assets/img/2026-03-protect-symfony-credential/image-5.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;この仕組みは「うっかりプッシュ」の観点で良い副作用をもたらします。&lt;strong&gt;ファイルの実体ではないため git でコミットできない&lt;/strong&gt; のです。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt; にうっかり書き忘れても、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.locall&lt;/code&gt; とファイル名をタイポしても、コミット時点でブロックされます。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git add .env.local
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; error: .env.local: can only add regular files, symbolic links or git-directories
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; fatal: updating files failed
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;そして &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; を一元管理できるメリットもあります。自宅とオフィスで PC を使い分けているような場合、どのデバイスでも 1Password からマウントしておけば「自宅の PC で変更した内容をオフィスの PC に反映し忘れた」なんてことがなくなります。&lt;/p&gt;

&lt;p&gt;ただし落とし穴もあります。一時的なバックアップのために &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cp .env.local .env.local.bak&lt;/code&gt; を実行すると &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local.bak&lt;/code&gt; はファイルの実体として作成され、うっかりコミットが可能になります。&lt;/p&gt;

&lt;h2 id=&quot;envlocal-を作らないsymfonys-secrets-management-system&quot;&gt;.env.local を作らない：Symfony’s secrets management system&lt;/h2&gt;

&lt;p&gt;そもそもクレデンシャルを &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; にハードコードしない手段についても検討の余地があります。Symfony 公式で紹介されている「Symfony’s secrets management system」はそのひとつです。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://symfony.com/doc/current/configuration/secrets.html&quot;&gt;How to Keep Sensitive Information Secret | Symfony docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;この方法は PHP 7.2+ でバンドルされているモジュール &lt;a href=&quot;https://www.php.net/manual/ja/book.sodium.php&quot;&gt;sodium&lt;/a&gt; を使ってクレデンシャルを暗号化し &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config/secrets/*&lt;/code&gt; に格納します。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# モジュールが含まれているか調べる&lt;/span&gt;
php &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep &lt;/span&gt;sodium
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; sodium
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;クレデンシャルの登録や削除はコマンドで行います。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 暗号化・復号化のためのキーペアを作成（初回のみ）&lt;/span&gt;
php bin/console secrets:generate-keys

&lt;span class=&quot;c&quot;&gt;# クレデンシャルを登録&lt;/span&gt;
php bin/console secrets:set API_KEY
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;プロダクション環境用にはプレフィクス &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APP_RUNTIME_ENV=prod&lt;/code&gt; を付与してコマンドを実行します。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 暗号化・復号化のためのキーペアを作成（初回のみ）&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;APP_RUNTIME_ENV&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;prod php bin/console secrets:generate-keys

&lt;span class=&quot;c&quot;&gt;# クレデンシャルを登録&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;APP_RUNTIME_ENV&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;prod php bin/console secrets:set API_KEY
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;一部のクレデンシャルをローカル開発用にカスタマイズする時は &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--local&lt;/code&gt; オプションを使用します。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bin/console secrets:set API_KEY &lt;span class=&quot;nt&quot;&gt;--local&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dev&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prod&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;local&lt;/code&gt; それぞれの環境用に生成されたファイル群は以下のように格納されます。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config/secrets
├── dev
│   ├── dev.API_KEY.b58958.php &lt;span class=&quot;c&quot;&gt;# 個別のクレデンシャル&lt;/span&gt;
│   ├── dev.decrypt.private.php &lt;span class=&quot;c&quot;&gt;# 復号化の秘密鍵&lt;/span&gt;
│   ├── dev.encrypt.public.php &lt;span class=&quot;c&quot;&gt;# 暗号化の公開鍵&lt;/span&gt;
│   ├── dev.list.php &lt;span class=&quot;c&quot;&gt;# クレデンシャルのリスト&lt;/span&gt;
└── prod
    ├── prod.API_KEY.b58958.php &lt;span class=&quot;c&quot;&gt;# 個別のクレデンシャル&lt;/span&gt;
    ├── prod.decrypt.private.php &lt;span class=&quot;c&quot;&gt;# 復号化の秘密鍵&lt;/span&gt;
    ├── prod.encrypt.public.php &lt;span class=&quot;c&quot;&gt;# 暗号化の公開鍵&lt;/span&gt;
    └── prod.list.php &lt;span class=&quot;c&quot;&gt;# クレデンシャルのリスト&lt;/span&gt;

.env.dev.local &lt;span class=&quot;c&quot;&gt;# ローカル開発用にカスタマイズした値&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これらのファイルのうち、プロダクション環境の秘密鍵 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prod.decrypt.private.php&lt;/code&gt; だけはコミットしてはいけません。秘密鍵を直接サーバーに置くか、サーバーの環境変数 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SYMFONY_DECRYPTION_SECRET&lt;/code&gt; に登録します。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# (A) サーバーに直接配置&lt;/span&gt;
config/secrets/prod/prod.decrypt.private.php

&lt;span class=&quot;c&quot;&gt;# (B) 環境変数に登録&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;SYMFONY_DECRYPTION_SECRET&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;={&lt;/span&gt;Base64 エンコードした鍵&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;登録したクレデンシャルはコマンドでリストアップできます。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# --reveal オプションで値の表示ができる&lt;/span&gt;
php bin/console secrets:list &lt;span class=&quot;nt&quot;&gt;--reveal&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;------------&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;----------&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-------------&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  Secret       Value      Local Value  
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;------------&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;----------&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-------------&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  API_KEY      &lt;span class=&quot;s2&quot;&gt;&quot;123abc&quot;&lt;/span&gt;   &lt;span class=&quot;s2&quot;&gt;&quot;111aaa&quot;&lt;/span&gt;    
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  DB_PASSWORD  &lt;span class=&quot;s2&quot;&gt;&quot;123def&quot;&lt;/span&gt;   &lt;span class=&quot;s2&quot;&gt;&quot;222bbb&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;------------&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;----------&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-------------&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;この仕組みは &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.*&lt;/code&gt; を使用せず &lt;strong&gt;「うっかりプッシュ」対象を「プッシュしても良い情報」&lt;/strong&gt; に置き換えます。ただしローカル開発用にカスタマイズした &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.dev.local&lt;/code&gt; は依然としてうっかりコミットの可能性が残ります。&lt;/p&gt;

&lt;h2 id=&quot;プッシュをブロックgithub-push-protection&quot;&gt;プッシュをブロック：GitHub Push protection&lt;/h2&gt;

&lt;p&gt;クレデンシャルの格納先は &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.*&lt;/code&gt; とは限りません。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.key&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.yaml&lt;/code&gt; にハードコードした内容を無害なファイルパスとして &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; に渡すことがあります。GitHub の Push protection はそのようなケースで有効です。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.github.com/ja/code-security/how-tos/secure-your-secrets/prevent-future-leaks/push-protection-for-users&quot;&gt;ユーザーのプッシュ保護 | GitHub ドキュメント&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Organization に属さない個人アカウント配下でパブリックなリポジトリを作成したところ、デフォルトで Push protection が有効になっていました。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2026-03-protect-symfony-credential/image-8.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;試しに AWS アカウントなどダミーのクレデンシャルを書いたファイルをプッシュすると Push protection によってデータ転送がブロックされました。&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# config/keys/sample.key&lt;/span&gt;

&lt;span class=&quot;s&quot;&gt;DUMMY_GITHUB_TOKEN=ghp_dummy12341234nopqrstuvwxyz....&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;DUMMY_AWS_KEY=AKIAQA2IFJE3MPUDUMMY&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;DUMMY_AWS_SECRET=gsDummyyGtzLXigRMVcDHeuS7Neg6vd....&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 主要な部分のみ抜粋&lt;/span&gt;
git push origin main

Enumerating objects: 8, &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
Counting objects: 100% &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;8/8&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;, &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
remote: Resolving deltas: 100% &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;2/2&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;, completed with 2 &lt;span class=&quot;nb&quot;&gt;local &lt;/span&gt;objects.
remote: error: GH013: Repository rule violations found &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;refs/heads/main.
remote: 
remote: - GITHUB PUSH PROTECTION
remote:   —————————————————————————————————————————
remote:     Resolve the following violations before pushing again
remote:     - Push cannot contain secrets
remote:     
remote:       —— Amazon AWS Access Key ID ——————————————————————————
remote:        locations:
remote:          - commit: 0a000111222...
remote:            path: config/keys/sample.key:4
remote:     
remote:       —— Amazon AWS Secret Access Key ——————————————————————
remote:        locations:
remote:          - commit: 0a000111222...
remote:            path: config/keys/sample.key:5
remote: 
 &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;remote rejected] main -&amp;gt; main &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;push declined due to repository rule violations&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# ブロックしてくれた ☺️&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ダミーの RSA 秘密鍵も試したところ、こちらは Push protection が反応せずプッシュが完了しました。&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# config/keys/sample.key（実在しないクレデンシャル）&lt;/span&gt;

&lt;span class=&quot;s&quot;&gt;-----BEGIN RSA PRIVATE KEY-----&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;MIIEowIBAAKCAQEArandomrandomrandomrandomrandomrandomrandomrandom&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;....&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;-----END RSA PRIVATE KEY-----&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git push origin main
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Total 0 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;delta 0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;, reused 0 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;delta 0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;, pack-reused 0 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;from 0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; + 1234c7c...4567ccc main -&amp;gt; main

&lt;span class=&quot;c&quot;&gt;# プッシュ完了...🙄&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;GitHub ドキュメントの &lt;a href=&quot;https://docs.github.com/ja/code-security/reference/secret-security/supported-secret-scanning-patterns#supported-secrets&quot;&gt;Supported secrets&lt;/a&gt; を読むと Push protection は単純なパターンマッチングのようなチェックではないことが分かります。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;トークン提供元のプロバイダ（AWS / Google など）によるチェックと、非プロバイダ（Generic）に分かれる&lt;/li&gt;
  &lt;li&gt;プロバイダにクレデンシャルを送信してトークンの有効性をチェックすることがある&lt;/li&gt;
  &lt;li&gt;トークンやプロバイダによってチェック内容の網羅度合いが異なる&lt;/li&gt;
  &lt;li&gt;個人アカウントのパブリックリポジトリに適用されるチェックと GitHub Team / Enterprise の GitHub Secret Protection で適用されるチェックに違いがある&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;偽物のクレデンシャルとほんの数回のプッシュ確認では、ブロック可能なパターンを帰納的に洗い出すことはできませんでした。&lt;/p&gt;

&lt;p&gt;しかしながら、あらゆるクレデンシャルを対象に GitHub がスキャンしてくれる機能はとても強力です。ブロックが成功した AWS アクセスキーについてはファイルから削除するだけではダメで、コミットログも完全に消し去らないとプッシュができませんでした。&lt;/p&gt;

&lt;p&gt;GitHub Push protection は &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env.local&lt;/code&gt; の &lt;strong&gt;外に漏れ出てしまった情報の監視役&lt;/strong&gt; として有効に機能してくれそうです。&lt;/p&gt;

&lt;h2 id=&quot;まとめ&quot;&gt;まとめ&lt;/h2&gt;

&lt;p&gt;Symfony や GitHub など、それぞれがうっかりプッシュの防止策を提供してくれています。どれもすべてのクレデンシャルやユースケースを網羅できる仕組みではありませんが、組み合わせれば高い効果が期待できそうです。&lt;/p&gt;

&lt;p&gt;これさえやっておけば大丈夫！と慢心せず、ローカルでもクラウドでも電子的に保存したデータは常に漏洩リスクを孕んでいることを念頭に開発していきたいと思っています。&lt;/p&gt;

</description>
        <pubDate>Mon, 16 Mar 2026 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>Claude Code 入門: 導入から基本操作・コスト管理まで | QUARTETCOM TECH BLOG</title>
        
        
        <category>ClaudeCode</category>
        
        <link>https://tech.quartetcom.co.jp/2026/02/24/claude-code-guide/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2026/02/24/claude-code-guide/</guid>
        <description>
&lt;p&gt;開発部では最近、開発効率を向上させる施策の一環として、Anthropic 社の CLI 型 AI エージェント「&lt;strong&gt;Claude Code&lt;/strong&gt;」を導入しました。&lt;/p&gt;

&lt;p&gt;本記事は、これから Claude Code を触ってみたいエンジニアや、AI ツールによる開発効率化に関心のある方に向けた実践ガイドです。&lt;/p&gt;

&lt;p&gt;今回は、「基本概念」から、コストを抑える運用まで共有します。&lt;/p&gt;

&lt;h2 id=&quot;1-まず押さえたい基本概念-セッションとコンテキスト&quot;&gt;1. まず押さえたい基本概念: 「セッション」と「コンテキスト」&lt;/h2&gt;

&lt;p&gt;Claude Code を使いこなす上で、以下の 2 つの概念を理解しておくとスムーズです。&lt;/p&gt;

&lt;h3 id=&quot;セッション作業のまとまり&quot;&gt;セッション（作業のまとまり）&lt;/h3&gt;

&lt;p&gt;Claude Code は、起動してから終了するまでの一連のやり取りを「セッション」として管理します。&lt;/p&gt;

&lt;p&gt;最も重要な仕様は、&lt;strong&gt;セッションは「起動ディレクトリ（フォルダ）」に紐付いて管理される&lt;/strong&gt;という点です。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[プロジェクトAのディレクトリ] ⇔ [セッションA（Aの記憶）]
        ｜
    (ディレクトリ移動)
        ↓
[プロジェクトBのディレクトリ] ⇔ [セッションB（Bの記憶）]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;つまり、ディレクトリを移動して&lt;strong&gt;新しく &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;claude&lt;/code&gt; を起動すれば、別のセッションとして扱われます&lt;/strong&gt;（前のディレクトリのコンテキストを引きずりません）。&lt;/p&gt;

&lt;p&gt;履歴は保存されているため、完全に消失するわけではありません。&lt;/p&gt;

&lt;p&gt;後述の &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/resume&lt;/code&gt; コマンドを使えば、過去のセッション一覧から再開したい作業を選んで元の状態を復元できます。&lt;/p&gt;

&lt;h3 id=&quot;コンテキストai-の短期記憶&quot;&gt;コンテキスト（AI の短期記憶）&lt;/h3&gt;

&lt;p&gt;AI が一度に覚えられる情報量のことです。
会話が長くなると、この「コンテキスト」が溜まっていきます。&lt;/p&gt;

&lt;p&gt;コンテキストが溜まると、AI が処理すべき情報量が増えるため、結果として利用料（コスト）も上がってしまいます。&lt;/p&gt;

&lt;h2 id=&quot;2-初期設定-init-と-claudemd&quot;&gt;2. 初期設定: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/init&lt;/code&gt; と &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt;&lt;/h2&gt;

&lt;h3 id=&quot;プロジェクトの記憶を作る-init&quot;&gt;プロジェクトの「記憶」を作る &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/init&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;初めて Claude Code を使うディレクトリでは、最初に以下のコマンドを実行します。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; /init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これを実行すると &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt; というファイルが生成されます。
ここにはビルドコマンドやコーディング規約などを記述します。
Claude Code は起動時にこのファイルを読み込み、プロジェクトのルールを理解します。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;チーム開発での運用ルール&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;共有設定（Git 管理する）&lt;/strong&gt;: プロジェクトルートの &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt; は&lt;strong&gt;Git にコミット&lt;/strong&gt;します。これにより、チーム全員が同じルール（ビルド手順や規約）を共有でき、通常は他のメンバーが &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/init&lt;/code&gt; を実行する必要がなくなります（既に設定ファイルが存在するため）。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;要件定義ファイルなどの扱い&quot;&gt;要件定義ファイルなどの扱い&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt; はあくまで「ルールブック」です。機能ごとの仕様書などは &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docs/spec.md&lt;/code&gt; などのファイルに分け、指示出しの際に &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@docs/spec.md&lt;/code&gt; のように参照させます。&lt;/p&gt;

&lt;h2 id=&quot;3-うまく伝わらない時は-コンテキスト管理のコツ&quot;&gt;3. うまく伝わらない時は？ コンテキスト管理のコツ&lt;/h2&gt;

&lt;p&gt;使っていると、「最近、指示の意図を汲んでくれなくなったな……」と感じることがあります。
これはコンテキストが溜まりすぎて、AI が混乱しているサインかもしれません。&lt;/p&gt;

&lt;h3 id=&quot;基本は-clear-でリセット&quot;&gt;基本は &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/clear&lt;/code&gt; でリセット&lt;/h3&gt;

&lt;p&gt;タスクの区切りや、話が噛み合わなくなったら、以下のコマンドを打ちます。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; /clear
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これにより、これまでのコンテキストが消去され、まっさらな状態で再スタートできます。
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt; の内容は保持されます。&lt;/p&gt;

&lt;h3 id=&quot;コンテキストを残したいなら-compact&quot;&gt;コンテキストを残したいなら &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/compact&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;「今の文脈は維持したいけど、少し記憶を整理したい」という場合は &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/compact&lt;/code&gt; が有効です。&lt;/p&gt;

&lt;p&gt;これは&lt;strong&gt;会話の要約のみを残し、個別のやり取りの詳細な履歴を削除する&lt;/strong&gt;ことで、コンテキストを圧縮します。&lt;/p&gt;

&lt;h2 id=&quot;4-利用状況の確認とモデルの使い分け&quot;&gt;4. 利用状況の確認とモデルの使い分け&lt;/h2&gt;

&lt;p&gt;Claude Code の利用状況や制限は、以下のコマンドで確認できます。
契約形態（サブスクリプションまたは API 課金）によって使い分けます。&lt;/p&gt;

&lt;h3 id=&quot;利用状況の確認&quot;&gt;利用状況の確認&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;サブスクリプションプランの場合&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usage&lt;/code&gt; コマンド
    &lt;ul&gt;
      &lt;li&gt;Claude Pro などのサブスクリプションプランで利用している場合、ここから&lt;strong&gt;レートリミット（残り使用回数）&lt;/strong&gt;やプランの使用状況を確認できます。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;API キーを利用（従量課金）の場合&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/cost&lt;/code&gt; コマンド
    &lt;ul&gt;
      &lt;li&gt;組織で API キーを利用（従量課金）している場合、現在のセッション費用を確認できます。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;モデルの使い分け&quot;&gt;モデルの使い分け&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Sonnet 系モデル&lt;/strong&gt;: 日常的なコーディングや修正。速度とコストのバランス型です。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Opus 系モデル&lt;/strong&gt;: 複雑な設計や難解なバグ調査。高精度で、深い推論を必要とする作業向けです。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;※モデル性能はアップデートにより変更される場合があります。&lt;/p&gt;

&lt;h2 id=&quot;5-急な割り込み対応セッション管理&quot;&gt;5. 急な割り込み対応（セッション管理）&lt;/h2&gt;

&lt;p&gt;開発中に緊急対応が入った場合も、セッション機能を使えば安全に中断・再開できます。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;中断&lt;/strong&gt;: 作業中のセッションに &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/rename [タスク名]&lt;/code&gt; で名前を付けて保存します。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;再開&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/resume&lt;/code&gt; で過去のセッションを選択し、元の状態（コンテキスト含む）から再開できます。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;並行作業&lt;/strong&gt;: Claude Code のセッションはディレクトリに紐付いています。そのため、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git worktree&lt;/code&gt; でディレクトリを分け、セッションを分離して並行作業できます。片方で「バグ調査」をさせつつ、もう片方で「新機能実装」を進めるなど、互いのコンテキストを混ぜずに並行作業が行えます。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;まとめ&quot;&gt;まとめ&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;基本&lt;/strong&gt;: セッションはディレクトリに紐付くため、場所を変えて起動すれば記憶も変わる。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;設定&lt;/strong&gt;: チームルールはルートの &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLAUDE.md&lt;/code&gt;（Git 管理）&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;維持&lt;/strong&gt;: 話が噛み合わなくなったら &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/clear&lt;/code&gt;。コスト節約にもなる。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;運用&lt;/strong&gt;: モデルの使い分けと &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/resume&lt;/code&gt; で柔軟に対応。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ぜひ、皆さんの開発フローにも取り入れてみてください。&lt;/p&gt;

</description>
        <pubDate>Tue, 24 Feb 2026 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>GitHubのマージ（Merge Commit/Squash Merging/Rebase Merging）の違い | QUARTETCOM TECH BLOG</title>
        
        
        <link>https://tech.quartetcom.co.jp/2025/12/05/github-pull-requests-merge/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/12/05/github-pull-requests-merge/</guid>
        <description>
&lt;p&gt;GitHub でプルリクエストをマージする時、マージボタンのプルダウンに「Squash and merge」「Rebase and merge」ってありますよね。これらの違いをよく知らなかったので手元で試してみました。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.github.com/ja/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges&quot;&gt;プルリクエストのマージについて | GitHub ドキュメント&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;動作確認用に使ったプルリクエストはタイトルを &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PR-A&lt;/code&gt; に、コミットメッセージを &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A1 {コミット時刻}&lt;/code&gt; と統一しています。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/pull-request.png&quot; width=&quot;600&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;1-create-a-merge-commit&quot;&gt;1) Create a merge commit&lt;/h1&gt;

&lt;p&gt;プルダウンを展開せずにマージボタンを押したデフォルトの動作です。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/merge-type-default.png&quot; width=&quot;600&quot; /&gt;&lt;/p&gt;

&lt;p&gt;同じブランチから切った複数ブランチをマージすると、時系列でコミットが積み上がります。&lt;/p&gt;

&lt;p&gt;メインブランチに見立てた &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merge&lt;/code&gt; にブランチ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merge-A&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merge-B&lt;/code&gt; をマージすると次の図のようになります。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/merge-tree.png&quot; width=&quot;700&quot; alt=&quot;デフォルトマージの図&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git log merge-A
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 44b8478 A2 21:25
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; fba0ad2 A1 21:23

git log merge-B
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 6bfb8c4 B2 21:26
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 74b8961 B1 21:24

git log merge
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 881e805 Merge pull request &lt;span class=&quot;c&quot;&gt;#18 from ringtail003/merge-B&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; d2bef64 Merge pull request &lt;span class=&quot;c&quot;&gt;#17 from ringtail003/merge-A&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 6bfb8c4 B2 21:26 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; プルリクエスト&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;2&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;のコミット
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 44b8478 A2 21:25 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; プルリクエスト&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;のコミット
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 74b8961 B1 21:24 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; プルリクエスト&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;2&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;のコミット
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; fba0ad2 A1 21:23 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; プルリクエスト&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;のコミット
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/blog-github-pull-requests-merge/commits/merge/&quot;&gt;GitHub でサンプルを見る&lt;/a&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/img/2025-12-05/merge-commit.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;2-squash-and-merge&quot;&gt;2) Squash and merge&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/merge-type-squash.png&quot; width=&quot;600&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Squash はプルリクエストのコミット群をひとつにまとめた新しいコミットを作成します。マージ先のブランチでは、プルリクエストとコミットが 1 対 1 になります。&lt;/p&gt;

&lt;p&gt;メインブランチに見立てた &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;squash&lt;/code&gt; にブランチ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;squash-A&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;squash-B&lt;/code&gt; をマージすると次の図のようになります。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/squash-tree.png&quot; width=&quot;700&quot; alt=&quot;squashの図&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git log squash-A
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 36001a5 A2 21:33 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; マージ元のコミット&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;2個目&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 709eb44 A1 21:30 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; マージ元のコミット&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;1個目&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

git log squash-B
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 2d087cb B2 21:34
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; aea1a38 B1 21:32

git log squash
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 7d65cc7 PR-B &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;c&quot;&gt;#20)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 6d63afc PR-A &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;c&quot;&gt;#19) &amp;lt;== マージ先のコミット（1個にまとまる）&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/blog-github-pull-requests-merge/commits/squash/&quot;&gt;GitHub でサンプルを見る&lt;/a&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/img/2025-12-05/squash-commit.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;squash-and-merge-の-author&quot;&gt;Squash and merge の Author&lt;/h2&gt;

&lt;p&gt;いくつかプルリクエストを作って試したところ、プルリクエストに一番最初にコミットした人がマージコミットの Author として採用されるようです。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/squash-author.png&quot; width=&quot;600&quot; /&gt;&lt;/p&gt;

&lt;p&gt;プルリクエストに 2 番目以降にコミットした人は「共作者」という扱いになります。&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git log &lt;span class=&quot;nt&quot;&gt;--pretty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;full

&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; commit 1234abc
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Author: user1 &amp;lt;user1@example.com&amp;gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Commit: GitHub &amp;lt;noreply@github.com&amp;gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  PR-A &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;c&quot;&gt;#100)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; A1
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; A2
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;span class=&quot;nt&quot;&gt;---------&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  Co-authored-by: user2 &amp;lt;user2@example.com&amp;gt; &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; 共作者
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.github.com/ja/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors&quot;&gt;複数の作者を持つコミットを作成する | GitHub ドキュメント&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;3-rebase-and-merge&quot;&gt;3) Rebase and merge&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/merge-type-rebase.png&quot; width=&quot;600&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Rebase はプルリクエストをマージ先ブランチでリベースしてからコミットを積みます。そのためコミットにそれぞれ新しいハッシュが付与されます。&lt;/p&gt;

&lt;p&gt;メインブランチに見立てた &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rebase&lt;/code&gt; にブランチ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rebase-A&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rebase-B&lt;/code&gt; をマージすると次の図のようになります。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/rebase-tree.png&quot; width=&quot;700&quot; alt=&quot;rebaseの図&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git log rebase-A
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 7258210 A2 21:39
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 7fcedd0 A1 21:37 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; マージ元のコミット

git log rebase-B
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 6ecf78f B2 21:40
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 5bd574d B1 21:38

git log rebase
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 3acd2d8 B2 21:40
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; f4e83f7 B1 21:38
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; e733a59 A2 21:39
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; def1981 A1 21:37 &amp;lt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; マージ先のコミット&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;ハッシュが変わる&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/blog-github-pull-requests-merge/commits/rebase/&quot;&gt;GitHub でサンプルを見る&lt;/a&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/img/2025-12-05/rebase-commit.png&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;マージメッセージ&quot;&gt;マージメッセージ&lt;/h1&gt;

&lt;p&gt;マージコミットのメッセージは Settings ページで変更できます。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-setting.png&quot; width=&quot;700&quot; /&gt;&lt;/p&gt;

&lt;p&gt;選択肢がたくさんあるので表にまとめました。動作確認用に使ったプルリクエストはタイトルを &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PR-A {メッセージの種類}&lt;/code&gt; と統一しています。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;マージの動作&lt;/th&gt;
      &lt;th&gt;メッセージの種類&lt;/th&gt;
      &lt;th&gt;Commits ページの表示&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Merge&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Default message&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-merge-default.png&quot; width=&quot;500&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Merge&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pull request title&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-merge-pr-title.png&quot; width=&quot;500&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Merge&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pull request title and description&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-merge-pr-title-and-desc.png&quot; width=&quot;500&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Squash&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Default message&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-default.png&quot; width=&quot;500&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Squash&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pull request title&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-pr-title.png&quot; width=&quot;500&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Squash&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pull request title and commit details&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-pr-title-and-detail.png&quot; width=&quot;500&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Squash&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pull request title and description&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-pr-title-and-desc.png&quot; width=&quot;500&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/blog-github-pull-requests-merge/commits/message-merge&quot;&gt;GitHub でサンプルを見る | Merge&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://github.com/ringtail003/blog-github-pull-requests-merge/commits/message-squash&quot;&gt;GitHub でサンプルを見る | Squash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;一見すると同じに見えるマージメッセージですが、マージコミットのボディ部分が異なります。&lt;/p&gt;

&lt;h2 id=&quot;default-message&quot;&gt;Default message&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-default-2.png&quot; width=&quot;700&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;pull-request-title&quot;&gt;Pull request title&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-pr-title-2.png&quot; width=&quot;700&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;pull-request-title-and-commit-details&quot;&gt;Pull request title and commit details&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-pr-title-and-detail-2.png&quot; width=&quot;700&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;pull-request-title-and-description&quot;&gt;Pull request title and description&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-12-05/message-squash-pr-title-and-desc-2.png&quot; width=&quot;700&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;考察&quot;&gt;考察&lt;/h1&gt;

&lt;p&gt;マージについて調べようと思ったきっかけは、どのプルリクエストをどの順番でマージしたのかサマリを見たいと思ったことでした。&lt;/p&gt;

&lt;p&gt;この用途だと、プルリクエストごとにマージコミットが作成される「Squash and merge」が良さそうだということになります。ですが 1 コミットに集約されることで、本来のコミットごとの作業履歴が見られなくなる、単一のコミットでリバートできなくなる、などデメリットもあるようです。たとえば release ブランチにマージする時だけ「Squash and merge」を適用できたら嬉しいのですが記事執筆時点（2025/12）ではブランチごとのコントロールはできないようでした。&lt;/p&gt;

&lt;p&gt;せっせとキャプチャをとってまとめましたが結論はデフォルトのまま現状維持、いずれまた検討する時がきたらこのブログを見に来ます。&lt;/p&gt;

</description>
        <pubDate>Fri, 05 Dec 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>暗黙知が支える技術の本質 | QUARTETCOM TECH BLOG</title>
        
        
        <category>チーム</category>
        
        <link>https://tech.quartetcom.co.jp/2025/10/10/the-essence-of-technology/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/10/10/the-essence-of-technology/</guid>
        <description>
&lt;p&gt;ソフトウェア開発の現場では、属人化を避けるために「なんでもドキュメント化しよう」という文化がよく見られます。&lt;br /&gt;
ナレッジを共有し、誰がいなくなっても困らないチームを作るという考え方自体は、合理的で正しいものだと思います。&lt;/p&gt;

&lt;p&gt;しかし、「なんでもドキュメント化しよう」という文化は、捉え方次第では技術の習得という観点で思わぬ弊害を生むことがあります。&lt;/p&gt;

&lt;h2 id=&quot;属人化とドキュメントのジレンマ&quot;&gt;属人化とドキュメントのジレンマ&lt;/h2&gt;
&lt;p&gt;例えば、あるプロジェクトの環境構築の手順をまとめたドキュメントがあるとします。&lt;br /&gt;
そのドキュメントの内容は、何のために、どこまで詳細に書くべきでしょうか。&lt;br /&gt;
その線引きは、チームの方針やメンバーに求めるスキルレベルなどによって大きく異なります。&lt;/p&gt;

&lt;p&gt;手順を細かく書けば、誰でも手順通りに作業でき、効率的に環境構築を進められます。&lt;br /&gt;
もし途中で問題が発生したとしても、そういったケースのトラブルシューティングの手順も記載しておけば問題ないでしょう。&lt;/p&gt;

&lt;p&gt;しかし、そのようなドキュメントに完全に頼って環境構築を終えたメンバーは、「自走して環境構築ができた」と言えるでしょうか。&lt;br /&gt;
多くの場合、それは「再現できた」にすぎず、「理解して環境構築できた」とは異なります。&lt;/p&gt;

&lt;p&gt;ドキュメントが過度に充実してマニュアルのようになると、「なぜそうするのか」を考える機会が失われます。&lt;br /&gt;
チーム全体がそれを当然のように良しとし、盲目的にドキュメント化を推進していると、将来的にメンバーの技術習得が課題になったり、評価と自己認識のズレや、学習意欲の低下といった問題が生じるかもしれません。&lt;/p&gt;

&lt;h2 id=&quot;技術の習得には思考の身体化が必要&quot;&gt;技術の習得には、思考の身体化が必要&lt;/h2&gt;
&lt;p&gt;ドキュメントは形式知を伝えるための手段としてとても有効ですが、それだけでは技術を習得することはできません。&lt;/p&gt;

&lt;p&gt;技術を習得するということは、単に知識を得ることではありません。&lt;br /&gt;
知識や経験をうまく繋げ、状況に応じて適切に判断するための思考を身体化することが必要です。&lt;/p&gt;

&lt;p&gt;開発者としてある程度経験を積むと、「この実装はなぜ気持ち悪いのか」「なぜ今はこの構成のほうが良いのか」といった、言語化しづらい感覚的な知識（暗黙知）を得て、それに基づいた判断ができるようになります。&lt;/p&gt;

&lt;p&gt;この暗黙知は、どれだけ充実したドキュメントを読んでも得ることはできません。&lt;br /&gt;
仮に「なぜそうするのか」まで書かれていても、それを形式的に知るだけでは、思考の再現には至りません。&lt;/p&gt;

&lt;p&gt;暗黙知についての有名な例えである「自転車の乗り方」（自転車の乗り方は実際に自転車に乗ることでしか知ることができず、どのように操作すれば良いかを言語化して説明することが難しい）と同じように、技術もまた、手と頭を動かし、試行錯誤するプロセスを通じてしか身につきません。&lt;br /&gt;
うまくいったり、うまくいかない経験のなかで生まれる感覚が、技術者としての「地力」となっていきます。&lt;/p&gt;

&lt;h2 id=&quot;暗黙知は文化として残す&quot;&gt;暗黙知は、文化として残す&lt;/h2&gt;
&lt;p&gt;「属人化を避けよう」というスローガンの背景には、「個人への依存を減らそう」という意図があると思います。&lt;br /&gt;
しかし、開発をうまく進めるための本質的な知識の多くは、個人の経験からでしか獲得できない暗黙知にあります。&lt;/p&gt;

&lt;p&gt;本当に強いチームとは、単に手順が共有されているチームではなく、暗黙知を文化として共有できるチームです。&lt;br /&gt;
ドキュメントは形式知を必要な分だけ残すことに留め、設計思想、デバッグの勘所、コードの美学といった暗黙知は、ペアプロ・コードレビュー・日常的な対話などを通して受け継いでいくことが大切です。&lt;/p&gt;

&lt;p&gt;一緒に手を動かし、考え方や価値観を自然に共有できる時間を増やすことが、結果的にチームを強くします。&lt;/p&gt;

&lt;h2 id=&quot;終わりに&quot;&gt;終わりに&lt;/h2&gt;
&lt;p&gt;「できる」や「できるようになった」という感覚や手応えがあると、プロセスを楽しめたり、より創造的になれたりします。&lt;/p&gt;

&lt;p&gt;今回の記事では、ドキュメント化の具体的な方法までは踏み込めませんでしたが、今後は「強いチームをつくるためのドキュメントとは何か」を意識して考えていきたいと思います！&lt;/p&gt;

</description>
        <pubDate>Fri, 10 Oct 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>独自のドメインモデルを捨てて、外部のドメインモデルに従う提案 | QUARTETCOM TECH BLOG</title>
        
        
        <category>逆DDD</category>
        
        <link>https://tech.quartetcom.co.jp/2025/10/01/discard-own-domain-model-follow-external-domain-model/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/10/01/discard-own-domain-model-follow-external-domain-model/</guid>
        <description>
&lt;h2 id=&quot;はじめに&quot;&gt;はじめに&lt;/h2&gt;

&lt;p&gt;担当しているプロダクトには &lt;strong&gt;「広告を入稿する」機能&lt;/strong&gt; があり、これは社内のユーザ部門の業務効率化が主な目的です。&lt;/p&gt;

&lt;p&gt;今までのフローとして、お客様に「広告設定確認書」という書類を提出して、&lt;br /&gt;
その「広告設定確認書内の広告設定」を元に「当該の広告媒体へ入稿を行う」業務フローがありました。&lt;/p&gt;

&lt;p&gt;このフローをシステム化することで、業務効率を上げていました。
システムの内部の処理は、 &lt;strong&gt;「独自ドメインモデル(広告設定確認書内の広告設定)」を定義し、それを「外部ドメインモデル（媒体API・SDK）」に変換して入稿 API を叩く、という二段構えのフローを採用&lt;/strong&gt; していました。&lt;/p&gt;

&lt;p&gt;このプロダクトを運用していくうちに、運用においても開発においても課題が見えてきました。&lt;/p&gt;

&lt;h2 id=&quot;プロダクトの課題&quot;&gt;プロダクトの課題&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;「独自ドメインモデル(広告設定確認書内の広告設定)」&lt;/strong&gt; を &lt;strong&gt;「外部ドメインモデル (媒体API・SDK)」&lt;/strong&gt; に変換する際に、スキーマの不一致によってデータの互換性が取れず、API エラーが起きやすい&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;「独自ドメインモデル」、「外部ドメインモデル」と理解するモデルが2つあり、認知負荷が高い&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;データ互換性維持のための差分対応が属人化し、特定の人しか直しづらい状態になっている&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;まとめると&lt;strong&gt;「認知負荷が高い」と「データ互換性維持が困難」、「独自ドメインモデルに属人性がある」という課題&lt;/strong&gt; がありました。&lt;br /&gt;
また、広告媒体 API はアップデートされる機会が多く、このような問題に陥るケースが多くありました。&lt;/p&gt;

&lt;p&gt;そのことから、現状の設計を根本から見直して、課題を解決する方法を考えました。&lt;/p&gt;

&lt;h2 id=&quot;実装した設計&quot;&gt;実装した設計&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-10-01-discard-own-domain-model-follow-external-domain-model/architect.png&quot; width=&quot;800&quot; alt=&quot;外部ドメインモデルをシステムに浸透させる設計&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-10-01-discard-own-domain-model-follow-external-domain-model/driven-pattern.png&quot; width=&quot;800&quot; alt=&quot;「DDD」と「逆DDD」の差&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;コンセプト&quot;&gt;コンセプト&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;「外部ドメインモデル駆動」&lt;/strong&gt; とする設計です。&lt;br /&gt;
&lt;strong&gt;外部ドメインモデルの変化をシステムがしっかりと影響を受けて、システムが変化する&lt;/strong&gt; ことを狙っています。&lt;/p&gt;

&lt;p&gt;つまり外部のドメインモデルに主体性があります。&lt;/p&gt;

&lt;p&gt;API 更新頻度が高いため、ACL 層を維持して独自ドメインモデルを管理するよりも、外部ドメインモデルに直接追従する方が、全体のコストを下げて安定運用できると判断して、
ACL 層を外す判断をしました。&lt;/p&gt;

&lt;p&gt;これは一般的な設計の方針から外れる大胆な判断ですが、&lt;strong&gt;「API に追従することが最優先の領域」&lt;/strong&gt; では合理的だと考えました。&lt;/p&gt;

&lt;p&gt;その他のコンセプトを箇条書きすると以下となります。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;特定のオブジェクトのスキーマ(今回で言うと入稿 API を実行する際に必要なオブジェクト)を外部ドメインモデルに寄せている&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SDK のスキーマをミラー(写像)した Interface&lt;/strong&gt; を定義している
    &lt;ul&gt;
      &lt;li&gt;その Interface を持つオブジェクトを&lt;strong&gt;各層&lt;/strong&gt;に実装する
        &lt;ul&gt;
          &lt;li&gt;&lt;strong&gt;Infrastructure 層&lt;/strong&gt;
            &lt;ul&gt;
              &lt;li&gt;API や SDK とやり取りする層&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;strong&gt;Presentation 層&lt;/strong&gt;
            &lt;ul&gt;
              &lt;li&gt;フロントエンドの関心を持つ層
                &lt;ul&gt;
                  &lt;li&gt;バリデーションの定義を持つ&lt;/li&gt;
                  &lt;li&gt;API スキーマとして表に出す層&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;strong&gt;Entity 層&lt;/strong&gt;
            &lt;ul&gt;
              &lt;li&gt;DB に保存する関心を持つ層&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;いずれの層は同じインターフェース(スキーマ)が実装されているので「オブジェクト to オブジェクト」のような変換が容易。
        &lt;ul&gt;
          &lt;li&gt;フロントエンドで来たものを Entity 層に変換したり、Infrastructure 層に変換して API の実行ができたりと、レイヤーの意味を考えながら実装ができる&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;本来あるはずの Anti-Corruption Layer (ACL) 層 を外して、外部ドメインモデルのスキーマを自システムに影響を反映させる&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;また「SDK のスキーマをミラー(写像)した Interface」は以下のように「getter」を定義して、
スキーマの互換性を表現しています。&lt;/p&gt;

&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CampaignInterface&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;?string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// SDK スキーマと同じフィールド&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;気をつけていること&quot;&gt;気をつけていること&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;SDK のオブジェクトを「我々のコード」に注入せず、&lt;strong&gt;SDK のスキーマをミラー(写像)した Interface&lt;/strong&gt; に依存している
    &lt;ul&gt;
      &lt;li&gt;SDK のオブジェクトは基本的に使いづらかったり、実装が汚れがちであるため、Infrastructure 層だけ SDK のオブジェクトを扱うようにして、実装の汚れを閉じ込めている&lt;/li&gt;
      &lt;li&gt;いわば「依存関係逆転の原則(DIP)」を取り入れて、「SDK -&amp;gt; Interface -&amp;gt; Domain」の関係性を作っています。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;この設計を取り入れるメリット&quot;&gt;この設計を取り入れるメリット&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;API 更新への追従が容易になる&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;API の更新内容を見て、変更があれば「我々のシステムの外部ドメインモデルを変更する」、という一対一の関係ができる&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;属人化を排除できる&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;モデルの説明を媒体ドキュメントに委譲できる。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;データの互換性の維持が容易になる&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;抽象層(独自ドメインモデル)を介さず、媒体スキーマに準拠しているため、適合性が高くできる&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;この設計を取り入れるデメリット&quot;&gt;この設計を取り入れるデメリット&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;「外部ドメインモデル（媒体API・SDK）」の理解が必要&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;ただし、これは広告運用プロダクトを扱う以上、避けられない前提知識でもある&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;「外部ドメインモデル（媒体API・SDK）」が廃止した時、プロダクトの改修範囲が大きくなる&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;外部ドメインモデルをそのままコピーするのでファイル数が膨大になる&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SDK 側の仕様変更に強く依存するため「ドメイン固有の最適化」がやりにくい&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;例：「API のマイクロバジェット値(マイクロ単位の通貨値)」をシステムでは「円」として保存しておきたいなど&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;元々存在した「独自ドメインモデル(広告設定確認書内の広告設定)」を使わなくなったため、ユーザ部門のコントロール性が下がった。（ただし、今回の設計変更は、ユーザ部門の負うこととなるこの「デメリット」を許容してもらうことをまず合意したうえでとりかかった）&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;ユビキタス言語もロストしているため、業務の影響は多少なりとも出ている&lt;/li&gt;
      &lt;li&gt;正規化したと考えても良いが、業務をシステム都合で変えてしまっているのは変わりがない&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;まとめ&quot;&gt;まとめ&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;抽象化は一見便利ですが、常に媒体 API に追従しなければならないシステムにおいては、むしろ負債&lt;/strong&gt; になりがちです。&lt;/p&gt;

&lt;p&gt;一方で、抽象化することで 1 つのモデルで他媒体の関心を共通化できるメリットもあるので、&lt;br /&gt;
どの選択をしてもリスクとリターンがあると、総括して感じました。&lt;/p&gt;

&lt;p&gt;今回の設計は独自のドメインモデルを捨てて外部ドメインモデルに従う、いわば&lt;strong&gt;「逆DDD」&lt;/strong&gt;ですが、&lt;br /&gt;
認知負荷の低減・属人化の排除・最新 API への追従を考えると、やはりメリットが多いと感じます。&lt;/p&gt;

&lt;p&gt;そのことから&lt;strong&gt;「むしろ API にしっかりと追従する必要があるシステムには 逆DDD が良い」&lt;/strong&gt;という提案をしました。&lt;/p&gt;

&lt;p&gt;実際に、この設計を今のプロダクトに適応している最中ですが、
API の追従がしやすかったり、スキーマに互換性があるため、API を叩きやすかったりと効果的だと感じています。&lt;/p&gt;

&lt;p&gt;とはいえ、知れ渡っている理論を逆行する設計なので、心理的にも思い切りが必要です。&lt;br /&gt;
そのため &lt;strong&gt;「逆DDD」を採用する時は、しっかりと「そのシステムで何をしたいのか？」を明確化して判断する&lt;/strong&gt; のをオススメします。&lt;/p&gt;

&lt;h2 id=&quot;所感&quot;&gt;所感&lt;/h2&gt;

&lt;p&gt;自分でモデリングする機会が減りました。&lt;br /&gt;
面白いところだと思いますが、少し残念です。&lt;/p&gt;

&lt;p&gt;ひたすら外部ドメインモデルのリファレンスを読んで、&lt;br /&gt;
インターフェースやクラスを書いているので、作業感がとてもあります。&lt;br /&gt;
(かなり膨大なので疲れます)&lt;/p&gt;

&lt;p&gt;それでもシステムは安定してきているので、作っているシステムにとって良い設計だろうと判断しています。&lt;/p&gt;

</description>
        <pubDate>Wed, 01 Oct 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>Symfonyのretry_failed optionsを使って、APIリクエスト失敗時に再試行するようにする | QUARTETCOM TECH BLOG</title>
        
        
        <category>PHP</category>
        
        <category>Symfony</category>
        
        <category>ExponentialBackoff</category>
        
        <category>API</category>
        
        <link>https://tech.quartetcom.co.jp/2025/09/25/symfony-retry-failed-option/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/09/25/symfony-retry-failed-option/</guid>
        <description>
&lt;p&gt;Symfonyのretry_failed optionsを活用すると、APIリクエストが失敗した際に指数バックオフアルゴリズムによる再試行が簡単に実装できます。&lt;/p&gt;

&lt;p&gt;本記事では、その設定方法と検証結果を紹介します :saluting_face:&lt;/p&gt;

&lt;h3 id=&quot;指数バックオフアルゴリズム-exponential-backoff-algorithmとは&quot;&gt;指数バックオフアルゴリズム (Exponential Backoff Algorithm)とは&lt;/h3&gt;
&lt;p&gt;ネットワークやAPIリトライなどで使われる「待ち時間を指数的に増やして再試行する仕組み」です。&lt;/p&gt;

&lt;p&gt;例えば初回 1秒 → 2秒 → 4秒 → 8秒 … のように、待機時間を指数関数的に増加させてリトライ処理をします。&lt;/p&gt;

&lt;p&gt;過去記事「リトライ処理時の指数バックオフアルゴリズムを AWS Step Functions で実装」も参考になるので読んでみてください。&lt;br /&gt;
&lt;a href=&quot;https://tech.quartetcom.co.jp/2024/10/29/exponential-backoff-step-functions/&quot;&gt;https://tech.quartetcom.co.jp/2024/10/29/exponential-backoff-step-functions/&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;symfonyのretry_failed-optionsの設定方法&quot;&gt;Symfonyのretry_failed optionsの設定方法&lt;/h2&gt;
&lt;p&gt;config/packages/framework.yamlを以下のように設定します。&lt;br /&gt;
※Symfony 5.2以降で利用可能です。&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s&quot;&gt;//  config/packages/framework.yaml&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;framework&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;http_client&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;default_options&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;retry_failed&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;max_retries&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# 最大リトライ回数&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1000&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# 初期遅延 (ミリ秒) → 1s&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;multiplier&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 指数の倍率（2 なら 1s,2s,4s,8s...）&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;max_delay&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;64000&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# 最大待機（ミリ秒）→ Memorystoreの推奨に合わせ64s上限など&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;jitter&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0.1&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# ジッター（0.0〜1.0、ここでは10%の揺らし）。同じタイミングで大量のリトライが発生しないようにランダムなばらつきをもたせる&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;http_codes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;423&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;425&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;429&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;502&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;503&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;504&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;507&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;510&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# リトライ対象のHTTPコード&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;特定API使用時のみリトライする場合は、scoped_clientsを使います。&lt;/p&gt;
&lt;div class=&quot;language-diff highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;framework:
&lt;/span&gt;    http_client:
&lt;span class=&quot;gd&quot;&gt;-        default_options:
&lt;/span&gt;&lt;span class=&quot;gi&quot;&gt;+        scoped_clients:
+            api_time.client:
+               base_uri: &apos;https://127.0.0.1:8000/api/time&apos;
&lt;/span&gt;                    retry_failed:
                        enabled: true
                        max_retries: 5
                        ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//src/Controller/RequestController.php&lt;/span&gt;

&lt;span class=&quot;mf&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Contracts\HttpClient\HttpClientInterface&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;RequestController&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AbstractController&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#[Route(&apos;/request&apos;, name: &apos;app_request&apos;)]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;#[Autowire(service: &apos;api_time.client&apos;)]&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;HttpClientInterface&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$httpClient&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//APIにアクセスする&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;GET&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;https://127.0.0.1:8000/api/time&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getStatusCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;request/error.html.twig&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
                &lt;span class=&quot;s1&quot;&gt;&apos;message&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;API request failed with status code: &apos;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getStatusCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nv&quot;&gt;$content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;toArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;request/index.html.twig&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
            &lt;span class=&quot;s1&quot;&gt;&apos;time&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;time&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;参考: &lt;a href=&quot;https://symfony.com/doc/current/reference/configuration/framework.html#http-client&quot;&gt;https://symfony.com/doc/current/reference/configuration/framework.html#http-client&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;本当に指数関数的にリトライしているか検証&quot;&gt;本当に指数関数的にリトライしているか検証&lt;/h2&gt;
&lt;p&gt;以下の手順で検証を行いました。&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;#1-http-429エラー2リクエスト10秒を意図的に発生させるapiを作成&quot;&gt;HTTP 429エラー(2リクエスト/10秒)を意図的に発生させるAPIを作成&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-1で作成したapiを使用するクライアントにsymfonyのretry_failedオプションを設定&quot;&gt;1で作成したAPIにリクエストをするクライアントにSymfonyのretry_failedオプションを設定&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-リトライ処理が実際に行われているか確認&quot;&gt;リトライ処理が実際に行われているか確認&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;1-http-429エラー2リクエスト10秒を意図的に発生させるapiを作成&quot;&gt;1. HTTP 429エラー(2リクエスト/10秒)を意図的に発生させるAPIを作成&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;composer create-project symfony/skeleton:&lt;span class=&quot;s2&quot;&gt;&quot;7.3.x&quot;&lt;/span&gt; rate-limitter-example
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;rate-limitter-example/
composer require webapp
composer require symfony/rate-limiter
bin/console make:controlle ApiTimeController
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// src/Controller/ShowTimeController.php

&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;App\Controller&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Bundle\FrameworkBundle\Controller\AbstractController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Component\HttpFoundation\Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Component\HttpFoundation\Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Component\RateLimiter\RateLimiterFactoryInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Component\Routing\Attribute\Route&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ApiTimeController&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AbstractController&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#[Route(&apos;/api/time&apos;, name: &apos;app_api_time&apos;)]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Request&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RateLimiterFactoryInterface&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$apiTimeLimiter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$limiter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$apiTimeLimiter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getClientIp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// consume(1)の1は消費するトークン数&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$limiter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;consume&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;isAccepted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TooManyRequestsHttpException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;Too Many Requests&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;
            &lt;span class=&quot;s1&quot;&gt;&apos;time&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;Y-m-d H:i:s&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s&quot;&gt;// config/packages/rate_limiter.yaml&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;framework&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;rate_limiter&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;api_time&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;# use &apos;sliding_window&apos; if you prefer that policy&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fixed_window&apos;&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;limit&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;interval&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;second&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;2-1で作成したapiを使用するクライアントにsymfonyのretry_failedオプションを設定&quot;&gt;2. 1で作成したAPIを使用するクライアントにSymfonyのretry_failedオプションを設定&lt;/h2&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;composer create-project symfony/skeleton:&lt;span class=&quot;s2&quot;&gt;&quot;7.3.x&quot;&lt;/span&gt; clear-late-limiter
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;clear-late-limiter/
composer require webapp
bin/console make:controlle RequestController
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;App\Controller&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Bundle\FrameworkBundle\Controller\AbstractController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Component\HttpFoundation\Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Component\Routing\Attribute\Route&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Symfony\Contracts\HttpClient\HttpClientInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;RequestController&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AbstractController&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#[Route(&apos;/request&apos;, name: &apos;app_request&apos;)]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;HttpClientInterface&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$httpClient&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//APIにアクセスする&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;GET&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;https://127.0.0.1:8000/api/time&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getStatusCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;request/error.html.twig&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
                &lt;span class=&quot;s1&quot;&gt;&apos;message&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;API request failed with status code: &apos;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getStatusCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nv&quot;&gt;$content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;toArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;request/index.html.twig&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
            &lt;span class=&quot;s1&quot;&gt;&apos;time&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;time&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s&quot;&gt;//  config/packages/framework.yaml&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;framework&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;http_client&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;default_options&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;retry_failed&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;max_retries&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# 最大リトライ回数&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1000&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# 初期遅延 (ミリ秒) → 1s&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;multiplier&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 指数の倍率（2 なら 1s,2s,4s,8s...）&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;max_delay&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;64000&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# 最大待機（ミリ秒）→ Memorystoreの推奨に合わせ64s上限など&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;jitter&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0.0&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# ジッター（0.0〜1.0、ここでは10%の揺らし）。同じタイミングで大量のリトライが発生しないようにランダムなばらつきをもたせる&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;http_codes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;423&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;425&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;429&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;502&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;503&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;504&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;507&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;510&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# リトライ対象のHTTPコード&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;上記の設定で指数関数的にリトライするように設定します。 今回は検証結果がわかりやすいように、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jitter: 0.0&lt;/code&gt;とします。&lt;/p&gt;

&lt;h3 id=&quot;3-リトライ処理が実際に行われているか確認&quot;&gt;3. リトライ処理が実際に行われているか確認&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;symfony server:start&lt;/code&gt;で各サーバを立てます。以下&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://127.0.0.1:8000&quot;&gt;https://127.0.0.1:8000&lt;/a&gt; API側&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://127.0.0.1:8001&quot;&gt;https://127.0.0.1:8001&lt;/a&gt; クライアント側&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;とします。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://127.0.0.1:8001/request&quot;&gt;https://127.0.0.1:8001/request&lt;/a&gt; に短時間に連続してアクセスしてみます。&lt;/p&gt;

&lt;p&gt;その後、クライアント側のProfiler &amp;gt; HTTP Client &amp;gt; Responseを確認すると以下のことがわかります。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;retry_count&quot; =&amp;gt; 4&lt;/code&gt;より、4回リトライし、5回目で成功している&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;retries&quot;&lt;/code&gt;より、各リトライが1秒後 → 2秒後 → 4秒後 → 8秒後と指数関数的に試行されている&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;▼
  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;▼
  &lt;span class=&quot;s2&quot;&gt;&quot;info&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;▼
    ...
    &lt;span class=&quot;s2&quot;&gt;&quot;debug&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&quot;
      ...
      * Request completely sent off
      &amp;lt; HTTP/2 200 
      &amp;lt; cache-control: no-cache, private
      &amp;lt; content-type: application/json
      &amp;lt; date: Mon, 22 Sep 2025 01:37:56 GMT
      ...
  ]
  &quot;&lt;/span&gt;retry_count&lt;span class=&quot;s2&quot;&gt;&quot; =&amp;gt; 4
  &quot;&lt;/span&gt;response_headers&lt;span class=&quot;s2&quot;&gt;&quot; =&amp;gt; [▶]
  &quot;&lt;/span&gt;response_json&lt;span class=&quot;s2&quot;&gt;&quot; =&amp;gt; [▶]
  &quot;&lt;/span&gt;retries&lt;span class=&quot;s2&quot;&gt;&quot; =&amp;gt; [▼
    [▼
      ...
      &quot;&lt;/span&gt;debug&lt;span class=&quot;s2&quot;&gt;&quot; =&amp;gt; &quot;&quot;&quot;&lt;/span&gt;
        ...
        &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; Request completely sent off
        &amp;lt; HTTP/2 429 
        &amp;lt; cache-control: no-cache, private
        &amp;lt; content-type: text/html&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;charset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;UTF-8
        &amp;lt; &lt;span class=&quot;nb&quot;&gt;date&lt;/span&gt;: Mon, 22 Sep 2025 01:37:41 GMT
        ...
    &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;▼
      ...
      &lt;span class=&quot;s2&quot;&gt;&quot;debug&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&quot;
        ...
        * Request completely sent off
        &amp;lt; HTTP/2 429 
        &amp;lt; cache-control: no-cache, private
        &amp;lt; content-type: text/html; charset=UTF-8
        &amp;lt; date: Mon, 22 Sep 2025 01:37:42 GMT
        ...
    ]
    [▼
      ...
      &quot;&lt;/span&gt;debug&lt;span class=&quot;s2&quot;&gt;&quot; =&amp;gt; &quot;&quot;&quot;&lt;/span&gt;
        ...        
        &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; Request completely sent off
        &amp;lt; HTTP/2 429 
        &amp;lt; cache-control: no-cache, private
        &amp;lt; content-type: text/html&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;charset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;UTF-8
        &amp;lt; &lt;span class=&quot;nb&quot;&gt;date&lt;/span&gt;: Mon, 22 Sep 2025 01:37:44 GMT
        ...
    &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;▼
      ...
      &lt;span class=&quot;s2&quot;&gt;&quot;debug&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&quot;
        ...
        * Request completely sent off
        &amp;lt; HTTP/2 429 
        &amp;lt; cache-control: no-cache, private
        &amp;lt; content-type: text/html; charset=UTF-8
        &amp;lt; date: Mon, 22 Sep 2025 01:37:48 GMT
        ...
    ]
  ]
]
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;まとめ&quot;&gt;まとめ&lt;/h2&gt;
&lt;p&gt;今回の検証では、2リクエスト/10秒という制限のあるAPIに対して、delay: 1000(=1秒)・multiplier: 2に設定したところ、リトライが頻繁に発生し、設定した最大リトライ回数（max_retries）に達してしまうケースがありました。&lt;/p&gt;

&lt;p&gt;このため、API側のレート制限に合わせて、delayやmultiplier、max_retriesなどのパラメータを適切に調整することが重要です :warning:&lt;/p&gt;

&lt;p&gt;Symfonyのretry_failed optionsを活用すれば、指数バックオフアルゴリズムによるリトライ機能を簡単に設定できます！ぜひ皆さんのプロジェクトでも取り入れてみてください :heart_hands:&lt;/p&gt;

</description>
        <pubDate>Thu, 25 Sep 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>PHPでGraphQLサーバー構築入門：Symfony＋API Platformを活用した実践 | QUARTETCOM TECH BLOG</title>
        
        
        <category>PHP</category>
        
        <category>Symfony</category>
        
        <category>GraphQL</category>
        
        <category>API</category>
        
        <link>https://tech.quartetcom.co.jp/2025/08/15/symfony-api-platform-graphql/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/08/15/symfony-api-platform-graphql/</guid>
        <description>
&lt;p&gt;近年のWebアプリケーションでは、画面構成やUXの多様化にともない&lt;strong&gt;「より柔軟で効率的なデータ取得」&lt;/strong&gt;の重要性が高まっています。&lt;/p&gt;

&lt;p&gt;特にフロントエンドでは、&lt;strong&gt;不要なデータ取得&lt;/strong&gt;や&lt;strong&gt;複数回のAPIリクエスト&lt;/strong&gt;が開発体験やパフォーマンスに影響を与えるケースも増えてきました。&lt;/p&gt;

&lt;p&gt;よく使われている&lt;strong&gt;REST API&lt;/strong&gt;では、エンドポイントごとに決まったレスポンスが返ってくるため、
フロント側の要件に合わせて&lt;strong&gt;「不要なデータを受け取る」&lt;/strong&gt;や&lt;strong&gt;「複数のエンドポイントを呼び分ける」&lt;/strong&gt; といった非効率が発生しがちです。&lt;/p&gt;

&lt;p&gt;これらの課題を解決する手段として注目されているのが&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GraphQL&lt;/code&gt;です。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GraphQL&lt;/strong&gt;を使えば、クライアントが必要なデータだけを明確に指定して取得できるため、 通信の無駄が減り開発効率やパフォーマンスの向上につながります。&lt;/p&gt;

&lt;p&gt;本記事では、&lt;strong&gt;Symfony と API Platform&lt;/strong&gt;を使って、&lt;strong&gt;GraphQL API&lt;/strong&gt;を簡単に作成する方法を紹介します。&lt;/p&gt;

&lt;h2 id=&quot;️-今回作成するもの&quot;&gt;✅️ 今回作成するもの&lt;/h2&gt;

&lt;p&gt;今回は「書籍（Book）」と「レビュー（Review）」のデータを扱う&lt;strong&gt;GraphQL API&lt;/strong&gt;を作成します。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;書籍一覧の取得&lt;/li&gt;
  &lt;li&gt;各書籍に紐づくレビューの平均スコアの取得&lt;/li&gt;
  &lt;li&gt;React + Apollo Clientを使ったフロントエンドでのデータ取得&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;フロント以外のコードはGitHubに公開していますので、ぜひ参考にしてください。&lt;/p&gt;

&lt;p&gt;🔗&lt;a href=&quot;https://github.com/mako5656/symfony-api-platform-graphql&quot;&gt;GitHub：symfony-api-platform-graphql&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;-目次&quot;&gt;📝 目次&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#1-symfonyプロジェクトのセットアップ&quot;&gt;1. Symfonyプロジェクトのセットアップ&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-api-platformの導入&quot;&gt;2. API Platformの導入&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-データベース接続postgresql&quot;&gt;3. データベース接続（PostgreSQL）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4-book--reviewエンティティの作成とマイグレーション&quot;&gt;4. Book / Reviewエンティティの作成とマイグレーション&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5-データ登録-rest-api&quot;&gt;5. データ登録 (REST API)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#6-graphqlの有効化&quot;&gt;6. GraphQLの有効化&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#7-graphqlで書籍一覧を取得&quot;&gt;7. GraphQLで書籍一覧を取得&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#8-カスタムフィールドレビューの平均スコアを追加&quot;&gt;8. カスタムフィールド（レビューの平均スコア）を追加&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#9-フロント側からデータを取得する&quot;&gt;9. フロント側からデータを取得する&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#10-まとめ&quot;&gt;10. まとめ&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-symfonyプロジェクトのセットアップ&quot;&gt;1. Symfonyプロジェクトのセットアップ&lt;/h2&gt;

&lt;p&gt;使用バージョン：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;PHP:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v8.2.28&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Symfony:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v7.3.1&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;まずは新規プロジェクトを作成します。&lt;/p&gt;

&lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;symfony new symfony-api-platform-graphql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;2-api-platformの導入&quot;&gt;2. API Platformの導入&lt;/h2&gt;

&lt;p&gt;API Platformは、PHP製のWeb APIフレームワークです。 
導入するだけで自動的にRESTとGraphQLのAPIエンドポイントが作成されます。&lt;/p&gt;

&lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;composer require api
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これだけで&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/api&lt;/code&gt;にアクセスすると、&lt;strong&gt;Swagger UIでREST APIのドキュメント&lt;/strong&gt;が確認できます。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;💡 API Platform では、REST API と GraphQL API の両方を併用できます。
エンティティを定義するだけで、自動的に REST のエンドポイントが生成され、Swagger UI から確認や操作も可能です。
本記事では GraphQL をメインに扱いますが、動作確認も兼ねてデータ登録には REST API を使って進めていきます。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/01.png&quot; width=&quot;800&quot; alt=&quot;APIドキュメント-データ0&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;3-データベース接続postgresql&quot;&gt;3. データベース接続（PostgreSQL）&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env&lt;/code&gt;ファイルを編集し、PostgreSQLに接続できるように設定します。&lt;/p&gt;

&lt;div class=&quot;language-diff highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gd&quot;&gt;- DATABASE_URL=&quot;postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&amp;amp;charset=utf8&quot;
&lt;/span&gt;&lt;span class=&quot;gi&quot;&gt;+ DATABASE_URL=&quot;postgresql://app:!@127.0.0.1:5432/symfony-api-platform-graphql?serverVersion=16&amp;amp;charset=utf8&quot;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;ユーザー名やパスワードは自分の環境に合わせて変更してください。&lt;/li&gt;
  &lt;li&gt;事前にPostgreSQLをインストールしておく必要があります。&lt;/li&gt;
  &lt;li&gt;PostgreSQL の代わりに SQLite や MySQL を使っても大丈夫です。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;その後、以下のコマンドでデータベースを作成します。&lt;/p&gt;

&lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;php bin/console doctrine:database:create
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;4-book--reviewエンティティの作成とマイグレーション&quot;&gt;4. Book / Reviewエンティティの作成とマイグレーション&lt;/h2&gt;

&lt;p&gt;まずは開発用に&lt;strong&gt;MakerBundle&lt;/strong&gt;を追加します。&lt;/p&gt;

&lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;composer require symfony/maker-bundle &lt;span class=&quot;nt&quot;&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;次に、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;書籍（Book）&lt;/code&gt;と&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;レビュー（Review）&lt;/code&gt;のエンティティを作成し、マイグレーションを実行します。&lt;/p&gt;

&lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;php bin/console make:entity
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;php bin/console make:migration 
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;php bin/console doctrine:migrations:migrate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;👇️️ エンティティ定義のコード&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mako5656/symfony-api-platform-graphql/blob/master/src/Entity/Book.php&quot;&gt;Book.php&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mako5656/symfony-api-platform-graphql/blob/master/src/Entity/Review.php&quot;&gt;Review.php&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;反映後、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/api&lt;/code&gt;にアクセスすると、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Book&lt;/code&gt;と&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Review&lt;/code&gt;のエンドポイントが自動生成されていることが確認できます。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/02.png&quot; width=&quot;800&quot; alt=&quot;REST APIドキュメント-エンティティ反映&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/03.png&quot; width=&quot;800&quot; alt=&quot;REST APIドキュメント-スキーマ&quot; /&gt;&lt;/p&gt;

&lt;p&gt;次に、実際にBookとReviewのデータをAPI経由で登録してみます。&lt;/p&gt;

&lt;h2 id=&quot;5-データ登録-rest-api&quot;&gt;5. データ登録 (REST API)&lt;/h2&gt;

&lt;p&gt;生成された&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/api&lt;/code&gt;エンドポイントに対して、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Postman&lt;/code&gt;などを使ってデータを登録します。&lt;/p&gt;

&lt;p&gt;Bookデータを登録するために、以下のように&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/api/books&lt;/code&gt;に&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POST&lt;/code&gt;リクエストを送信します。&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;isbn&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;978-4-7741-8411-1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ドメイン駆動設計入門&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;DDDの基礎を学べる書籍です。&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;山田太郎&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;publicationDate&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2024-05-01T00:00:00+09:00&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Reviewデータの登録も同様に&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/api/reviews&lt;/code&gt;に&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POST&lt;/code&gt;リクエストを行います。&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;rating&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;body&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;とても分かりやすい内容でDDDが理解できました！&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;読者A&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;publicationDate&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2024-05-10T00:00:00+09:00&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;book&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/api/books/1&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/04.png&quot; width=&quot;800&quot; alt=&quot;Postmanでのデータ登録&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/05.png&quot; width=&quot;800&quot; alt=&quot;PostgreSQLでBookデータ確認&quot; /&gt;&lt;/p&gt;

&lt;p&gt;データベースにデータが入っていることが確認できます。&lt;/p&gt;

&lt;p&gt;サンプルデータとして&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Book&lt;/code&gt;と&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Review&lt;/code&gt;データをいくつか登録しておきます。&lt;/p&gt;

&lt;p&gt;サンプルデータは&lt;a href=&quot;https://github.com/mako5656/symfony-api-platform-graphql/blob/master/README.md&quot;&gt;README.md&lt;/a&gt;に記載しておきます。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/06.png&quot; width=&quot;800&quot; alt=&quot;PostgreSQLでBookとReviewのデータ確認&quot; /&gt;&lt;/p&gt;

&lt;p&gt;REST APIが問題なく動作することを確認できたので、 ここからは本題であるGraphQLの利用方法を見ていきます。&lt;/p&gt;

&lt;h2 id=&quot;6-graphqlの有効化&quot;&gt;6. GraphQLの有効化&lt;/h2&gt;

&lt;p&gt;GraphQLを有効化します。&lt;/p&gt;

&lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;composer require api-platform/graphql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これで&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/graphql&lt;/code&gt;にアクセスすれば、&lt;strong&gt;GraphiQL（GraphQL IDE）&lt;/strong&gt;が利用可能になります。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/07.png&quot; width=&quot;800&quot; alt=&quot;GraphQL IDE&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;7-graphqlで書籍一覧を取得&quot;&gt;7. GraphQLで書籍一覧を取得&lt;/h2&gt;

&lt;p&gt;API Platformでは、GraphQLエンドポイント（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/graphql&lt;/code&gt;）が自動で用意されており、ブラウザから&lt;strong&gt;GraphiQL&lt;/strong&gt;を使ってクエリを試すことができます。&lt;/p&gt;

&lt;p&gt;まずは、シンプルに書籍の一覧を取得してみます。&lt;/p&gt;

&lt;div class=&quot;language-graphql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;books&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;edges&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;author&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isbn&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;publicationDate&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;このように、GraphQLでは&lt;strong&gt;必要なフィールドだけを指定して取得できる&lt;/strong&gt;のが大きなメリットです。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;edges &amp;gt; node&lt;/code&gt;という構造は、&lt;a href=&quot;https://relay.dev/&quot;&gt;Relay仕様&lt;/a&gt;に沿ったページネーション形式です。&lt;/p&gt;

&lt;p&gt;👇️️ 結果画面はこんな感じ&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/08.png&quot; width=&quot;800&quot; alt=&quot;GraphQLのクエリ実行&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;8-カスタムフィールドレビューの平均スコアを追加&quot;&gt;8. カスタムフィールド（レビューの平均スコア）を追加&lt;/h2&gt;

&lt;p&gt;クライアントでレビューを集計するのは手間なので、バックエンドで平均スコアを計算して返すようにします。&lt;/p&gt;

&lt;h3 id=&quot;-bookエンティティに集計ロジックを追加&quot;&gt;📌 Bookエンティティに集計ロジックを追加&lt;/h3&gt;

&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#[Groups([&apos;book:read&apos;])]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getAverageRating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;?float&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;is_iterable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nv&quot;&gt;$sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reviews&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$review&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$review&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;レビューが存在する場合だけ平均を計算し、小数第2位で丸めて返すというシンプルな実装です。&lt;/p&gt;

&lt;h3 id=&quot;-graphqlでフィールドを有効化する&quot;&gt;📌 GraphQLでフィールドを有効化する&lt;/h3&gt;

&lt;p&gt;この&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;averageRating&lt;/code&gt;をGraphQLのレスポンスに含めるためには、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ApiResource&lt;/code&gt;にグループ指定を追加します。&lt;/p&gt;

&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#[ApiResource(normalizationContext: [&apos;groups&apos; =&amp;gt; [&apos;book:read&apos;]])]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これでGraphQL側でも以下のようなクエリで取得可能になります！&lt;/p&gt;

&lt;div class=&quot;language-graphql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;books&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;edges&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;averageRating&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;👇️️ 結果画面はこんな感じ&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-08-15/09.png&quot; width=&quot;800&quot; alt=&quot;平均スコア追加後のGraphQLのクエリ実行&quot; /&gt;&lt;/p&gt;

&lt;p&gt;バックエンドで集計処理を済ませておけば、フロント側は&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;averageRating&lt;/code&gt;をクエリに追加するだけで、すぐに表示できます。&lt;/p&gt;

&lt;p&gt;REST APIでも集約済みのデータを1リクエストで取得することは可能ですが、 事前に専用のエンドポイントを用意する必要があり画面ごとのデータ要件に応じて設計が増えていきがちです。&lt;/p&gt;

&lt;p&gt;その点GraphQLでは、クライアントが欲しい形で柔軟にクエリを定義できるため、バックエンド側は汎用的なスキーマを用意するだけで済みます。&lt;/p&gt;

&lt;p&gt;その結果、&lt;strong&gt;クライアントは欲しいデータを、欲しい形で取得&lt;/strong&gt;できるようになり、
バックエンド側も汎用的なスキーマ設計だけで済むため、&lt;strong&gt;API設計の手間を大きく減らす&lt;/strong&gt;ことができます。&lt;/p&gt;

&lt;p&gt;GraphQL のこうした柔軟さは、複雑な画面構成や多様なデータ要件を持つアプリ開発において、特に効果を発揮します。&lt;/p&gt;

&lt;h2 id=&quot;9-フロント側からデータを取得する&quot;&gt;9. フロント側からデータを取得する&lt;/h2&gt;

&lt;p&gt;GraphQLの大きな利点のひとつが、「&lt;strong&gt;フロントエンドから必要なデータだけを効率的に取得できる&lt;/strong&gt;」点です。&lt;/p&gt;

&lt;p&gt;ここでは&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;React + Apollo Client&lt;/code&gt;を使って、書籍のタイトルと平均スコアを表示するシンプルなUIを作ってみます。&lt;/p&gt;

&lt;h3 id=&quot;graphqlクエリの定義&quot;&gt;GraphQLクエリの定義&lt;/h3&gt;

&lt;div class=&quot;language-tsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;GET_BOOKS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gql&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`
  query {
    books {
      edges {
        node {
          id
          title
          averageRating
        }
      }
    }
  }
`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;コンポーネント側の実装&quot;&gt;コンポーネント側の実装&lt;/h3&gt;

&lt;div class=&quot;language-tsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useQuery&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;@apollo/client&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;BookList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;useQuery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;GET_BOOKS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;loading&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;読み込み中...&lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;エラー: &lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;;&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;books&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;edges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(({&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}:&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt; - 平均スコア: &lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;averageRating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;評価なし&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;BookList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;このように、GraphQLクエリを使ってフロント側で必要なフィールドだけを柔軟に取得できます。&lt;/p&gt;

&lt;p&gt;バックエンド側で&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Groups&lt;/code&gt;属性によってフィールド公開範囲を調整できるのも、API Platform の便利な点です。&lt;/p&gt;

&lt;h2 id=&quot;10-まとめ&quot;&gt;10. まとめ&lt;/h2&gt;

&lt;p&gt;今回の構成（Symfony + API Platform + GraphQL）を振り返ってみると、こんな強みがありました。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;✅ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;自動生成&lt;/code&gt;：エンティティ定義だけでREST/GraphQL APIを即構築可能&lt;/li&gt;
  &lt;li&gt;✅ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;柔軟性&lt;/code&gt;：Groups属性で公開フィールドを制御したり、フロントエンドから必要なデータを自由に取得できる&lt;/li&gt;
  &lt;li&gt;✅ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;効率性&lt;/code&gt;：GraphQL により、必要な情報だけを最小限で取得できるため、通信や処理の無駄がない&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;GraphQLが初めての方でも、API Platformを使えば簡単に構築できます。&lt;/p&gt;

&lt;p&gt;特に、&lt;strong&gt;データの粒度を調整したい場面&lt;/strong&gt;や&lt;strong&gt;複雑な画面構成を持つSPA開発&lt;/strong&gt;においては、GraphQLのメリットを最大限に活かせます。&lt;/p&gt;

&lt;p&gt;今回は実装中心の紹介でしたが、GraphQLはUIの多様化に柔軟に対応できる強力な選択肢です。&lt;/p&gt;

&lt;p&gt;ぜひ一度、試してみてください！&lt;/p&gt;

&lt;h2 id=&quot;️-参考リンク&quot;&gt;📚️ 参考リンク&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://api-platform.com/docs/&quot;&gt;API Platform 公式ドキュメント&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zenn.dev/ttskch/articles/89a4a6420313bb&quot;&gt;Zenn 記事：Symfony + API Platform で GraphQL API を実装&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Fri, 15 Aug 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>Angularリアクティブフォームの型安全な使い方 ─ 罠を避ける実践ポイント | QUARTETCOM TECH BLOG</title>
        
        
        <category>Angular</category>
        
        <category>TypeScript</category>
        
        <category>Form</category>
        
        <link>https://tech.quartetcom.co.jp/2025/08/01/angular-form/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/08/01/angular-form/</guid>
        <description>
&lt;h1 id=&quot;はじめに&quot;&gt;はじめに&lt;/h1&gt;
&lt;p&gt;今年に入りチーム編成が変わり、バックエンドエンジニアからフロントエンドやインフラも触ることになりました。
詳しくは&lt;a href=&quot;https://tech.quartetcom.co.jp/2025/06/27/rebuild-team/&quot;&gt;こちら&lt;/a&gt;をご覧ください。&lt;/p&gt;

&lt;p&gt;その中でAngular v18環境でのフォーム実装に関わる機会があり、特にリアクティブフォームの「型の付け方」や「構成パターン」で混乱があったので、
本記事ではTyped Forms(型付きフォーム)におけるフォームオブジェクトの生成、型推論、および &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nonNullable&lt;/code&gt; の扱いなどを体系的に整理し、より型が安全なフォーム実装に必要な観点をまとめます。&lt;/p&gt;

&lt;h1 id=&quot;angularのフォーム構成の方法&quot;&gt;Angularのフォーム構成の方法&lt;/h1&gt;
&lt;p&gt;Angularにはフォームを作成するための2つの主要な構成方法があります。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://angular.jp/guide/forms#choosing-an-approach&quot;&gt;公式ドキュメント&lt;/a&gt;を見ていただければわかりますがデータフローや入力フィールド数の規模感の違いなどがあり、 フォームの構造やロジックの定義箇所、型推論の取り扱いが選定時に特に重要になると感じました。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;リアクティブフォーム：フォーム構造・ロジックをTypeScript側で定義する。&lt;/li&gt;
  &lt;li&gt;テンプレート駆動フォーム：フォーム構造・ロジックをHTMLテンプレート側に記述する。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;本記事では、Typed Forms(型付きフォーム)を活かせるリアクティブフォームに焦点を当てて解説します。&lt;/p&gt;

&lt;h1 id=&quot;リアクティブフォームの構成要素&quot;&gt;リアクティブフォームの構成要素&lt;/h1&gt;
&lt;p&gt;フォームの実装をする上で良いとされる構成パターンはよく見かけますがなぜいいのかがわからない状態だったので、
以下の3つの観点に分けて順に理解していくとわかりやすいと感じたので構成方法や型指定方法の違いによって起きうる危険性も含めて解説していきます。&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;#フォームオブジェクトの生成方法&quot;&gt;フォームオブジェクトの作成方法&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#フォームの型指定方法&quot;&gt;フォームの型の指定方法&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#オプション設定&quot;&gt;オプション設定&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;フォームオブジェクトの生成方法&quot;&gt;フォームオブジェクトの生成方法&lt;/h2&gt;
&lt;p&gt;オブジェクトの作成には、主に以下の方法があります。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;フォームの基盤となるクラスを&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;(インスタンス化)して作成する方法(以下、「ローレベルAPI」)&lt;/li&gt;
  &lt;li&gt;Angularが提供するユーティリティサービスのFormBuilderを使用して作成する方法&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;以下にそれぞれのサンプルコードを示し違いを説明します。&lt;/p&gt;

&lt;p&gt;他にも深いところで違いがあるんだとは思いますが、個人的にはDIでのテストのしやすさや可読性の点からFormBuilderの方が好みでした。&lt;/p&gt;

&lt;h3 id=&quot;ローレベルapiのサンプルコード&quot;&gt;ローレベルAPIのサンプルコード&lt;/h3&gt;
&lt;p&gt;フォームの基盤クラスである&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormGroup&lt;/code&gt;や&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&lt;/code&gt;を明示的にインスタンス化してフォームを作成します。&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;UserFormComponent&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;userForm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;formbuilderのサンプルコード&quot;&gt;FormBuilderのサンプルコード&lt;/h3&gt;
&lt;p&gt;FormBuilderを使用してフォームを作成します。&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;UserFormComponent&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;userForm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;フォームの型指定方法&quot;&gt;フォームの型指定方法&lt;/h2&gt;
&lt;p&gt;上記で作成したフォームに型を指定する方法として、v14以降に導入されたTyped Forms(型付きフォーム)を使用することでより型安全なフォームの実装が可能になります。&lt;/p&gt;

&lt;p&gt;Typed Forms(型付きフォーム)を使っていて最も混乱したのが、&lt;strong&gt;開発者が指定した型と型推論の違い&lt;/strong&gt;でした。
型パラメータやNonNullableFormBuilderを使うことでより開発者が明示的に扱う型を宣言することができ、より型安全なフォームの実装が可能になります。ですが、フォームのFormControlが&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;を許容するかどうかによって意図しない型推論が行われることがあるので注意が必要です。&lt;/p&gt;

&lt;p&gt;以下に分けて解説します。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;nullを許容しない場合&lt;/li&gt;
  &lt;li&gt;nullを意図して許容する場合&lt;/li&gt;
  &lt;li&gt;nullを意図せず許容してしまっている場合&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nullを許容しない場合&quot;&gt;nullを許容しない場合&lt;/h3&gt;
&lt;p&gt;nullを許容しない場合は、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NonNullableFormBuilder&lt;/code&gt;と型パラメータ&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;T&amp;gt;&lt;/code&gt;使うことでシンプルにより型安全なフォームを作成できます。&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;userForm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;NonNullableFormBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;FormGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;   
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;明示した通り&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;string&amp;gt;&lt;/code&gt;の型パラメータを指定することで、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;を許容しない型(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&amp;lt;string&amp;gt;&lt;/code&gt;)として推論されます。&lt;/p&gt;

&lt;h3 id=&quot;nullを許容する場合&quot;&gt;nullを許容する場合&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;を許容する場合は、以下のようにFormBuilderと型パラメータ&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;T&amp;gt;&lt;/code&gt;を使ってフォームを作成できます。&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;userForm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;FormGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これは記述通りの型推論になっており、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&amp;lt;string | null&amp;gt;&lt;/code&gt;のように&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;を許容する型として推論されます。&lt;/p&gt;

&lt;h3 id=&quot;nullを意図せず許容してしまっている場合&quot;&gt;nullを意図せず許容してしまっている場合&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;を意図せず許容してしまっている場合は、以下のようにFormBuilderで明示的に&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;string&amp;gt;&lt;/code&gt;の型パラメータを与えているように見えて、内部的なFormControlの仕様によって&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;が許容されてしまいます。&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;userForm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;FormGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fb.control&amp;lt;string&amp;gt;&lt;/code&gt;で型パラメータを&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;string&amp;gt;&lt;/code&gt;で与えているので&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;は許容されていないように見えますが、Angulerの&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&lt;/code&gt;の仕様によって、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;が許容されてしまいます。&lt;/p&gt;

&lt;p&gt;以下はFormControlの該当する&lt;a href=&quot;https://github.com/angular/angular/blob/5b25d93f27b259098ed968a8a355e9c16867b37b/goldens/public-api/forms/index.api.md?plain=1#L310&quot;&gt;ソースコード&lt;/a&gt;です。&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;formState&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControlState&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;validatorOrOpts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ValidatorFn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ValidatorFn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControlOptions&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;asyncValidator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;AsyncValidatorFn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;AsyncValidatorFn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;control&amp;lt;T&amp;gt;&lt;/code&gt;で&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;T&amp;gt;&lt;/code&gt;を型パラメータとして与えても返り値は&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;T | null&amp;gt;&lt;/code&gt;になっていることがわかります。
上記のように型パラメータだけでは&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;が許容されている状態となりコンパイルエラーやバグの原因になります。&lt;/p&gt;

&lt;p&gt;これを回避するためにオプション設定を理解しておくことが重要です。&lt;/p&gt;

&lt;h2 id=&quot;オプション設定&quot;&gt;オプション設定&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl()&lt;/code&gt; や &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fb.control()&lt;/code&gt; では、第2引数として構成オプションを渡すことができます。
nullを許容しないようにするためには、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nonNullable: true&lt;/code&gt;オプションを指定します。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#nullを意図せず許容してしまっている場合&quot;&gt;nullを意図せず許容してしまっている場合&lt;/a&gt;にオプションを追記すると以下のようになります。&lt;/p&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;userForm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;nonNullable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;userForm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;nonNullable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;FormGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;   
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nonNullable: true&lt;/code&gt;を指定することで、返り値の&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&amp;lt;T|null&amp;gt;&lt;/code&gt;の型が&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&amp;lt;T&amp;gt;&lt;/code&gt;に変わり、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;を許容しないことで型安全性を高めることができます。&lt;/p&gt;

&lt;p&gt;以下は&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nunNullable: true&lt;/code&gt;を設定した場合の&lt;a href=&quot;https://github.com/angular/angular/blob/5b25d93f27b259098ed968a8a355e9c16867b37b/goldens/public-api/forms/index.api.md?plain=1#L304&quot;&gt;ソースコード&lt;/a&gt;です。
先ほどのnonNullableのオプション設定のないソースコードと比べると、返り値が&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&amp;lt;T|null&amp;gt;&lt;/code&gt;ではなく&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&amp;lt;T&amp;gt;&lt;/code&gt;になっていることがわかります。&lt;/p&gt;
&lt;div class=&quot;language-typescript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;formState&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControlState&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;opts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControlOptions&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;nonNullable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FormControl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;オプションを使うことで&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt;を許容しないようにすることはできますが、より型安全なフォームを実装したい場合は&lt;a href=&quot;#nullを許容しない場合&quot;&gt;nullを許容しない場合&lt;/a&gt;でフォーム作成をすることで型安全性を高めることができます。&lt;/p&gt;

&lt;h1 id=&quot;まとめ&quot;&gt;まとめ&lt;/h1&gt;
&lt;p&gt;リアクティブフォームは柔軟性が高いため設計を曖昧にしたまま進めると、型の不一致や型推論のnullによるバグが発生しやすくなる印象を受けました。
そのため最初にフォームオブジェクト+型パラメータ+オプション設定を実装の意図に合わせて組むことが、型安全性とテスト容易性を高めるために重要だと感じました。&lt;/p&gt;

&lt;p&gt;本記事では触れませんでしたが、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interface&lt;/code&gt; で値の型を明示したり、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormBuilder.nonNullable.group()&lt;/code&gt; を使ったりすることでも型の安全性を担保できます。
またリアクティブフォームに触れる中で、RxJSによる非同期処理やストリームの考え方(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Observable&lt;/code&gt;の&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pipe()&lt;/code&gt;を使ったオペレーター連結など)も非常に新鮮に感じたのでまた紹介できればと思います。&lt;/p&gt;

&lt;h1 id=&quot;おまけ&quot;&gt;おまけ&lt;/h1&gt;
&lt;h2 id=&quot;v13以前での型の戻り値&quot;&gt;v13以前での型の戻り値&lt;/h2&gt;
&lt;p&gt;ブログを書く中でわかったことですがv13以前では&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormGroup&lt;/code&gt;や&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&lt;/code&gt;に対して型パラメータ&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;T&amp;gt;&lt;/code&gt;を与えることができず、戻り値は&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormGroup&amp;lt;any&amp;gt;&lt;/code&gt;と返ってきていたようで完全に型安全にしたい場合は、&lt;a href=&quot;https://github.com/Quramy/ngx-typed-forms&quot;&gt;ngx-typed-forms&lt;/a&gt;などのライブラリを使う必要があったようです。
この問題はv14でTypedFormsが公式に導入されたことで解消され、今は&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormGroup&amp;lt;T&amp;gt;&lt;/code&gt;や&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormControl&amp;lt;T&amp;gt;&lt;/code&gt;による型安全なフォームが標準機能として扱えるようになっています。
詳しくは&lt;a href=&quot;https://github.com/angular/angular/discussions/44513&quot;&gt;こちら&lt;/a&gt;を参照してください。&lt;/p&gt;

</description>
        <pubDate>Fri, 01 Aug 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>プロダクトチーム制への移行とユーザー部門との連携強化に取り組みました！ | QUARTETCOM TECH BLOG</title>
        
        
        <category>チーム</category>
        
        <category>組織</category>
        
        <link>https://tech.quartetcom.co.jp/2025/06/27/rebuild-team/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/06/27/rebuild-team/</guid>
        <description>
&lt;p&gt;今回は、システム開発部が現在取り組んだ「チーム体制の見直し」と「他部署との連携強化」についてご紹介します。&lt;/p&gt;

&lt;h1 id=&quot;前提&quot;&gt;前提&lt;/h1&gt;

&lt;p&gt;私たちは大きさの異なるプロダクトや担当業務を合計で約20ほどを開発・運用しています。そのほとんどがいわゆる Web+RDBMS で構成されるアプリケーションですが一部は Node.JS on AWS Lambda だったり Google Apps Script だったりします。&lt;/p&gt;

&lt;h1 id=&quot;旧体制における課題職能別チームの状況&quot;&gt;旧体制における課題：職能別チームの状況&lt;/h1&gt;

&lt;p&gt;これまでのシステム開発部は、PHP、UI、インフラといった&lt;strong&gt;職能別の専門チーム&lt;/strong&gt;で構成されていました。各チームは、それぞれの専門分野を担当する数名のメンバーで構成されていました。この体制には、いくつかの課題がありました。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-06-27/skill-teams.png&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;課題例1-チーム間での業務量のばらつき&quot;&gt;課題例1: チーム間での業務量のばらつき&lt;/h2&gt;

&lt;p&gt;チームによって担当するタスクの質と量にばらつきが見られました。これにより、メンバー個々の&lt;strong&gt;価値提供の機会に偏り&lt;/strong&gt;が生じ、必ずしも健全とは言えない状況でした。&lt;/p&gt;

&lt;h2 id=&quot;課題例2-プロダクトオーナーシップの不明確さ&quot;&gt;課題例2: プロダクトオーナーシップの不明確さ&lt;/h2&gt;

&lt;p&gt;特定のプロダクトに対し、複数の職能チームのメンバーがその都度対応する形となっていました。そのため、各プロダクトを主体的に担当するメンバーやチームが明確ではなく、結果として&lt;strong&gt;責任の所在が曖昧になる傾向&lt;/strong&gt;が見られました。&lt;/p&gt;

&lt;h1 id=&quot;新体制プロダクトチーム制への移行&quot;&gt;新体制：プロダクトチーム制への移行&lt;/h1&gt;

&lt;p&gt;これらの課題に対応するため、私たちは組織体制を「&lt;strong&gt;プロダクトチーム制&lt;/strong&gt;」へと変更しました。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-06-27/product-teams.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;プロダクトチーム&lt;/strong&gt;にはリーダーが置かれ、会社の役職上のマネージャがその職責を担います。（ちなみに各チーム名はシステム開発部の業務で欠かせない Linux のイメージキャラクタであるペンギンの種別から着想を得たものです）&lt;br /&gt;
各プロダクトチームには、担当するプロダクトや業務範囲が設定されています。&lt;br /&gt;
さらに、各プロダクトや業務範囲に対し、&lt;strong&gt;一人の PdM（プロダクトマネージャ） と一人以上のメンバー&lt;/strong&gt;を明確に割り当てます。&lt;/p&gt;

&lt;p&gt;新体制への移行により、各メンバーの&lt;strong&gt;権限と責任がより明確に&lt;/strong&gt;なりました。これにより、各プロダクトにおけるメンバーの&lt;strong&gt;オーナーシップ意識の醸成&lt;/strong&gt;にも寄与すると考えています。一方で、従来の職能チーム体制では求められなかった、より幅広いスキルセットが各メンバーに求められるようになっています。これは、メンバー一人ひとりが専門分野を超えて成長していくことを前提としており、個人のスキル向上とキャリア形成の一助となると考えています。&lt;/p&gt;

&lt;h2 id=&quot;新体制への過程部門内での検討&quot;&gt;新体制への過程：部門内での検討&lt;/h2&gt;

&lt;p&gt;今回のプロダクトチーム制への移行は、慎重かつ綿密な検討を重ねて行われました。私たちは、どのようなチーム構成が適切か、また各プロダクトをどのチームが担当すべきかについて、適宜さまざまな座組で複数回にわたり検討を行いました。&lt;br /&gt;
最終段階ではメンバー全員による複数回の協議を実施し、結論を出すための最終協議はリモートワークメンバーも含め、全員が出社して対面で意見を交換しました。忌憚のない、お互いを尊重するコミュニケーションを通じて、結論を導き出しました。
検討過程でのコミュニケーションは、「変更されたチーム体制」という成果物以上に、メンバーの相互理解を深め、関係を醸成するという価値を提供してくれるものでした。
この変革は、部長である私から部のメンバーに提起したものですが、各メンバーの建設的で主体的な姿勢があったことで実現できたものと認識しています。大変感謝しています！&lt;/p&gt;

&lt;h1 id=&quot;ユーザー部門との連携強化システム開発における共創&quot;&gt;ユーザー部門との連携強化：システム開発における共創&lt;/h1&gt;

&lt;p&gt;私たちが開発するプロダクトやタスクの大部分は、他部署の業務効率化やサポートを目的としています。そこで、ユーザー部門の従業員にもより明確なオーナーシップを持ってもらえるよう、新たな連携の枠組みを構築し始めています。&lt;br /&gt;
その端緒として、私からシステム開発におけるユーザー部門の従業員の関与の重要性を共有し、&lt;strong&gt;各プロダクトに一人の PO（プロダクトオーナー） の設定&lt;/strong&gt;を依頼しました。&lt;br /&gt;
システム開発部の PdM とユーザー部門の PO が一般的に呼称される役割に限定せず、それぞれの役割を適切に協議し設定することで、プロダクトがユーザーの課題を的確に解決し、さらに効果的に利用されることを目指します。&lt;/p&gt;

&lt;h1 id=&quot;今後の展望&quot;&gt;今後の展望&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;プロダクトチーム制への移行&lt;/strong&gt;と&lt;strong&gt;ユーザー部門との連携強化&lt;/strong&gt;は、システム開発部がより柔軟で、かつ責任を持った組織へと発展するための重要な一歩となります。この変革を通じて、私たちは今後も事業が高品質なサービスを提供するためのシステムを支えていきます！&lt;/p&gt;

&lt;hr /&gt;

</description>
        <pubDate>Fri, 27 Jun 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>JavaScript 非同期処理を Event Loop で理解する | QUARTETCOM TECH BLOG</title>
        
        
        <category>JavaScript</category>
        
        <link>https://tech.quartetcom.co.jp/2025/05/30/javascript-asynchronous-processing/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/05/30/javascript-asynchronous-processing/</guid>
        <description>
&lt;h1 id=&quot;はじめに&quot;&gt;はじめに&lt;/h1&gt;

&lt;p&gt;久しぶりに JavaScript / TypeScript に触れる機会がありました。&lt;br /&gt;
JavaScript の非同期処理は思い出すのにいつも時間がかかります。今後のために非同期処理について少し詳しくまとめます。&lt;/p&gt;

&lt;p&gt;本記事では、サンプルコードとともに Event Loop の仕組み、Microtasks / Macrotasks の実行タイミングを整理しながら非同期処理についての理解を深めることを目的にしています。&lt;/p&gt;

&lt;p&gt;本記事はおもに &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide/In_depth&quot;&gt;In depth: Microtasks and the JavaScript runtime environment&lt;/a&gt; を参考にしています。&lt;/p&gt;

&lt;h2 id=&quot;event-loop-とは&quot;&gt;Event Loop とは&lt;/h2&gt;

&lt;p&gt;JavaScript の Event Loop は、非同期処理の「実行タイミング」を制御する仕組みです。&lt;br /&gt;
JavaScript は（同じ Event Loop のサイクルにおいて）同期処理をすべて実行した後に非同期処理を実行します。言い換えると、非同期処理の準備が整っていても（解決済みでも）同期処理に割り込むことはありません。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;同期処理 -&amp;gt; 即時実行される&lt;/li&gt;
  &lt;li&gt;非同期処理 -&amp;gt; キューに登録され、順番に実行される&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;非同期処理の種類タスクの分類&quot;&gt;非同期処理の種類（タスクの分類）&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide/In_depth&quot;&gt;In depth: Microtasks and the JavaScript runtime environment&lt;/a&gt; では非同期処理を 2 種類の「キュー（待ち行列）」に分類して説明しています。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;種類&lt;/th&gt;
      &lt;th&gt;名前&lt;/th&gt;
      &lt;th&gt;実行タイミング&lt;/th&gt;
      &lt;th&gt;例&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Microtasks&lt;/td&gt;
      &lt;td&gt;マイクロタスク&lt;/td&gt;
      &lt;td&gt;現在のタスクの後すぐ実行&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Promise.then&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;queueMicrotask&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Macrotasks&lt;/td&gt;
      &lt;td&gt;タスク&lt;/td&gt;
      &lt;td&gt;次の Event Loop のタイミングで実行&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setTimeout&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setInterval&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;注意点&quot;&gt;注意点&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;「現在のタスク（current task）」という表現が MDN にもありますが、これは setTimeout のような「Macrotasks の 1 件」だけを指すわけではありません。文脈によっては、「今 JavaScript が同期的に実行している 1 サイクル全体（＝現在の Event Loop のサイクル）」を指している場合もあります。文脈に注意して解釈する必要があります。&lt;/li&gt;
  &lt;li&gt;Macrotasks は Microtasks との対比を強調する意味で使用されることが多いようです。[In depth: Microtasks and the JavaScript runtime environment] は単に &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Macrotasks&lt;/code&gt; を&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tasks&lt;/code&gt; と表記しています。本記事は分かりやすさのために Microtasks / Macrotasks で統一します。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;サンプル&quot;&gt;サンプル&lt;/h2&gt;

&lt;p&gt;今までの説明をサンプルコードを使って見ていきます。&lt;/p&gt;

&lt;h3 id=&quot;サンプル1基本的な実行タイミングを確認&quot;&gt;サンプル1：基本的な実行タイミングを確認&lt;/h3&gt;

&lt;h4 id=&quot;コード&quot;&gt;コード&lt;/h4&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// (1)..(5) は実行順序を表します&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sampleAsynchronous&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Promise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 1.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// (1)&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 4.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;promiseObj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sampleAsynchronous&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 5.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;// (5)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 2.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;// (2)&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;promiseObj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;           &lt;span class=&quot;c1&quot;&gt;// (4)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 3.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;// (3)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 出力結果

task 1.
task 2.
task 3.
task 4.
task 5.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;解説&quot;&gt;解説&lt;/h4&gt;

&lt;p&gt;以下の (1)…(5) はコードのコメントに記載 (1)…(5) に対応します&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;同期処理 (1)〜(3)：すぐに実行される&lt;/li&gt;
  &lt;li&gt;Microtasks (4)：Promise.then は Microtasks として登録され、同期処理が終わった後に即実行される&lt;/li&gt;
  &lt;li&gt;Macrotasks (5)：setTimeout は次の Event Loop サイクルで実行される&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;event-loop-のサイクル構造簡略図&quot;&gt;Event Loop のサイクル構造（簡略図）&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; ┌────────────┐
 │ Macrotasks │ &amp;lt;- (1回目: 同期処理)
 └────┬───────┘
      ↓
 ┌────────────┐
 │ Microtasks │ &amp;lt;- (Promise.thenなど)
 └────┬───────┘
      ↓
   次の Macrotasks（setTimeout など）
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;サンプル2複数サイクル実行タイミングを確認&quot;&gt;サンプル2：複数サイクル実行タイミングを確認&lt;/h3&gt;

&lt;div class=&quot;language-ts highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// (1)..(10) は実行順序を表します&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;createPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Promise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 2.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// (2)&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 4.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;createOtherPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Promise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 6.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// (6)&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 8.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 1.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;// (1)&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;promiseObj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;createPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;promiseObj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// (4)&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 5.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// (5)&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;other&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;createOtherPromise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;// (8)&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 9.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// (9)&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 10.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (10)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 7.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// (7)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;task 3.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;// (3)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 出力結果（順序）

task 1.
task 2.
task 3.
task 4.
task 5.
task 6.
task 7.
task 8.
task 9.
task 10.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;解説-1&quot;&gt;解説&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;1回目の Event Loop
    &lt;ul&gt;
      &lt;li&gt;Macrotasks：task 1. -&amp;gt; task 2. -&amp;gt; task 3.&lt;/li&gt;
      &lt;li&gt;Microtasks：task 4.（Promise.then）&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2回目の Event Loop（ 1000ms 後の setTimeout ）
    &lt;ul&gt;
      &lt;li&gt;Macrotasks：task 5. -&amp;gt; task 6. -&amp;gt; task 7.&lt;/li&gt;
      &lt;li&gt;Microtasks：task 8.（ Promise.then ）&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3回目の Event Loop（ さらに 2000ms 後の setTimeout ）
    &lt;ul&gt;
      &lt;li&gt;Macrotasks：task 9. -&amp;gt; task 10.&lt;/li&gt;
      &lt;li&gt;Microtasks：なし&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;まとめ&quot;&gt;まとめ&lt;/h1&gt;

&lt;p&gt;まとめとしてに本記事の要点を記載します。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Promise.then は同期処理が終わった直後に実行される（ Microtasks ）&lt;/li&gt;
  &lt;li&gt;setTimeout は 次の Event Loop サイクルで実行される（ Macrotasks ）&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Event Loop は Macrotasks（ current task ） -&amp;gt; すべての Microtasks → 次の Macrotasks（ Tasks ） という流れで進行します。&lt;/p&gt;

&lt;p&gt;非同期処理は JavaScript の基本的な機能ですが、文脈による言葉の使い分け（特に「task」）も含め、分かりづらい面もあります。
本記事が非同期処理の理解の一助になれば幸いです。&lt;/p&gt;

</description>
        <pubDate>Fri, 30 May 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>GitHubでYahoo!広告スクリプトのための開発環境をつくる | QUARTETCOM TECH BLOG</title>
        
        
        <category>Node.js</category>
        
        <link>https://tech.quartetcom.co.jp/2025/03/05/yas-scaffold/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/03/05/yas-scaffold/</guid>
        <description>
&lt;h1 id=&quot;はじめに&quot;&gt;はじめに&lt;/h1&gt;

&lt;p&gt;みなさん「Yahoo!広告スクリプト」をご存知でしょうか。&lt;br /&gt;
Yahoo!広告スクリプトとは、Yahoo! JAPANにおけるWeb広告プラットフォームにアクセスするためのスクリプトです。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.lycbiz.com/jp/column/yahoo-ads/service-information/2023021530408670/&quot;&gt;Yahoo!広告 スクリプトとは？特徴や利用手順を解説 | LINEヤフー for business&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;弊社にはWeb広告の運用代行事業があり、とある集計作業でのスクリプト制作を試みました。&lt;/p&gt;

&lt;p&gt;Yahoo!広告スクリプトは専用の編集画面でJavaScriptのコードを登録します。&lt;br /&gt;
リアルタイム実行またはタイマー実行で、ログを見てトライ＆エラーを繰り返すのが基本の使い方です。CI、テスト、リビジョン管理といったなじみの道具はなく、使用できるAPIや構文はECMAScriptのバージョンとは一致しません。&lt;/p&gt;

&lt;p&gt;そんなランタイムのための開発環境をどう作るか…🤔&lt;br /&gt;
試行錯誤の結果できあがった開発環境について紹介します。&lt;/p&gt;

&lt;p&gt;※ Yahoo!広告ランタイムは定期的にアップデートされます。当記事はランタイム「202501」を前提としています。&lt;/p&gt;

&lt;h1 id=&quot;目指したもの&quot;&gt;目指したもの&lt;/h1&gt;

&lt;p&gt;できるだけ普段に近づけたいと思い、以下を開発環境の要件としました。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;GitHubでリビジョン管理する事&lt;/li&gt;
  &lt;li&gt;TypeScriptで開発する事&lt;/li&gt;
  &lt;li&gt;ユニットテストを実行する事&lt;/li&gt;
  &lt;li&gt;ランタイムのビルトインサービスを表現できる事&lt;/li&gt;
  &lt;li&gt;ランタイムのシンタックスエラーをローカルで再現する事&lt;/li&gt;
  &lt;li&gt;1回限りでなく既存プロジェクトへの展開ができる事&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;完成したもの&quot;&gt;完成したもの&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/yas-scaffold&quot;&gt;https://github.com/ringtail003/yas-scaffold&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;完成した開発環境をGitHubリポジトリにアップしました。&lt;br /&gt;
このリポジトリは以下のように使用します。&lt;/p&gt;

&lt;p&gt;空のディレクトリを作成し、npxでセットアップ用スクリプトを叩くと各種設定ファイルがコピーされます。&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;node &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; v22.9.0

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;my-project
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;my-project

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npx ringtail003/yas-scaffold yas &lt;span class=&quot;nt&quot;&gt;--init&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 設定ファイルをコピーしました（package.json）
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 設定ファイルをコピーしました（eslint.config.json）
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;プロジェクト名を書き換えてパッケージをインストールします。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// package.json&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;my-project&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npm &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これでセットアップは完了です。&lt;br /&gt;
サンプルコードに対してユニットテストとLintが実行できます。&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npm &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ✔ src/greet.ts &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;72.979375ms&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;   ✔ プリミティブ &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0.4155ms&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;   ✔ 配列 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0.474125ms&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ...
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ℹ tests 13
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ℹ pass 13
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npm run lint
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; eslint &lt;span class=&quot;nt&quot;&gt;--fix&lt;/span&gt; ./src
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ビルドコマンドを叩くと、JavaScriptにトランスパイルしたビルドファイルが生成されます。&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npm run publish
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; created dist/bundle.js &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;343ms
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; created dist/publish.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ビルドファイルの中身をスクリプト編集画面に貼り付けます。&lt;br /&gt;
保存してリアルタイム実行し、ログやリファレンスを見ながら実装を詰めていきます。&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;リポジトリはYahoo!広告スクリプトのプロジェクトを構成する目的として、yas-scaffold（Yahoo Ads Script Scaffold）と名付けました。以降はこのリポジトリを「YAS開発環境」と表記します。&lt;/p&gt;

&lt;h1 id=&quot;githubでリビジョン管理する&quot;&gt;GitHubでリビジョン管理する&lt;/h1&gt;

&lt;p&gt;ビルドファイルの冒頭にはgitのコミットが記載されます。&lt;br /&gt;
Yahoo!広告スクリプトの編集画面から辿ってビルド時点のコミットが特定できる、という仕組みです。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// publish.js&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
 * @file ...
 * @see https://github.com/{SAMPLE_ORGANIZATION}/my-project/commit/123abcd
 */&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;コメントはビルド後に &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/shells/publish.sh&quot;&gt;publish.sh&lt;/a&gt; で埋め込んでいます。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{SAMPLE_ORGANIZATION}&lt;/code&gt; は実際には自社のOrganizationをベタ書きしていて、 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;my-project&lt;/code&gt; はビルド時にpackage.jsonから読み込みます。&lt;/p&gt;

&lt;p&gt;Yahoo!広告スクリプトをたくさん登録しても（上限100個）、どのリポジトリで開発しているのか判別ができます。&lt;/p&gt;

&lt;h1 id=&quot;typescriptで開発する&quot;&gt;TypeScriptで開発する&lt;/h1&gt;

&lt;p&gt;TypeScriptからJavaScriptへのトランスパイルは &lt;a href=&quot;https://Rollupjs.org/&quot;&gt;Rollup&lt;/a&gt; を採用しました。&lt;/p&gt;

&lt;p&gt;最初は &lt;a href=&quot;https://babeljs.io/&quot;&gt;Babel&lt;/a&gt; を使っていたのですが、設定が圧倒的にシンプルであること、複数ファイルを結合するバンドル機能を標準で備えていること、などの優位性からRollupに乗り換えることにしました。&lt;/p&gt;

&lt;p&gt;セットアップ用スクリプトで作成されるサンプルコードは &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/src/index.ts&quot;&gt;index.ts&lt;/a&gt; で、開発言語はTypeScriptです。&lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/package.json#L21&quot;&gt;ビルドコマンド&lt;/a&gt; を叩くとJavaScriptのファイルが出力されます。&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npm run build

├── dist
│   ├── bundle.js &lt;span class=&quot;c&quot;&gt;# ビルドファイル&lt;/span&gt;
├── src
│   ├── index.ts &lt;span class=&quot;c&quot;&gt;# ソースコード&lt;/span&gt;
│   └── greet.ts &lt;span class=&quot;c&quot;&gt;# ソースコード&lt;/span&gt;
├── rollup.config.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;設定ファイル &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/rollup.config.js&quot;&gt;rollup.config.js&lt;/a&gt; はたったの14行です。巷ではゼロコンフィグのトランスパイラも登場しているようですが、今のところRollupに満足しています。&lt;/p&gt;

&lt;h1 id=&quot;ユニットテストを実行する&quot;&gt;ユニットテストを実行する&lt;/h1&gt;

&lt;p&gt;テストはNode.jsの &lt;a href=&quot;https://nodejs.org/docs/latest-v22.x/api/test.html&quot;&gt;ビルトインテストランナー&lt;/a&gt; を採用しました。YAS開発環境では関数のIN/OUTを検証するテストが主体で、必要最低限のものが揃えば十分だと思ったからです。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/package.json#L23-L25&quot;&gt;テストコマンド&lt;/a&gt; は基本的に &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;node --test&lt;/code&gt; を実行しているだけです。ビルトインテストランナーは &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*.test.ts&lt;/code&gt; を探してテストスイートを実行します。&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;node &lt;span class=&quot;nt&quot;&gt;--test&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--experimental-strip-types&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;# 型宣言を削除する&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--experimental-transform-types&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;# enumなどTypeScript独自のシンタックスを変換する&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--no-warnings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ExperimentalWarning &lt;span class=&quot;c&quot;&gt;# experimentalの警告表示をオフにする&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;テストのサンプルコード &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/src/index.test.ts#L12&quot;&gt;index.test.ts&lt;/a&gt; では、インポート文に &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ts&lt;/code&gt; が付いています。Node.jsの &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--experimental-strip-types&lt;/code&gt; フラグは型宣言を削除するだけでTypeScriptのように拡張子を補完しないため、拡張子付きで宣言する必要があります。また型のインポートが削除対象となるように &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;type&lt;/code&gt; キーワードも必要になります。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Greeting&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;./greet.ts&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;インポートだけ気をつければ後は普通にテストを書くことができます。一般的なアサーションも揃っています。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;TestContext&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;node:test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;TestContext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Hello World&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Hello &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;World&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;deepEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;strictEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;テスト環境のためのパッケージのインストールやアップデートメンテも不要ですし、ユニットテストならこれで十分かなと思っています。&lt;/p&gt;

&lt;p&gt;※ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--experimental-strip-types&lt;/code&gt; フラグの挙動は &lt;a href=&quot;https://nodejs.org/ja/blog/release/v23.6.0&quot;&gt;Node.js v23.6&lt;/a&gt; でデフォルトになるため、Node.jsのアップデートとともに必要がなくなります。&lt;/p&gt;

&lt;h1 id=&quot;ランタイムのビルトインサービス&quot;&gt;ランタイムのビルトインサービス&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;https://ads-developers.yahoo.co.jp/ja/ads-script/product-guide/reference/&quot;&gt;リファレンス | Yahoo! JAPAN広告&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yahoo!広告スクリプトにはビルトインサービスが存在し、Googleスプレッドシートの書き込みやログ出力ができます。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ss&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;openById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;テスト&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;Logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;完了&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SpreadsheetApp&lt;/code&gt; や &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Logger&lt;/code&gt; はYahoo!広告のランタイムで実体が得られるオブジェクトで、そのまま書くとTypeScriptの世界ではコンパイルエラーが発生します。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ss&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;openById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;テスト&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//         ~~~~~~~~~~~~~~&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//         ERROR: Cannot find name &apos;SpreadsheetApp&apos;.ts(2304)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;YAS開発環境では、ビルトインサービスをグローバルオブジェクトとして &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/types/builtin.d.ts&quot;&gt;builtin.d.ts&lt;/a&gt; で型宣言しています。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;declare&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;openById&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Spreadsheet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// グローバルオブジェクトの存在を宣言する&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/tsconfig.json#L7&quot;&gt;tsconfig.json&lt;/a&gt; でデフォルトで読み込むようにしておけば、どのファイルからもインポート文なしで使用できます。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;compilerOptions&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;typeRoots&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;./types&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;openById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;spreadsheetId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 👍&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;テスト環境では実体が得られないため、モックをセットしておきましょう。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;beforeEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;globalThis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;openById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;dummy file&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;SpreadsheetApp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;openById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;spreadsheetId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 👍&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;シンタックスエラーをローカルで再現する&quot;&gt;シンタックスエラーをローカルで再現する&lt;/h1&gt;

&lt;p&gt;Yahoo!広告のランタイムとECMAScriptのバージョンは一致しません。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array.flatMap（ES2019）&lt;/code&gt; は使用できて、それよりも古い &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class（ES6）&lt;/code&gt; は使用できない、といった具合です。&lt;/p&gt;

&lt;p&gt;このような環境の場合、以下のような選択肢が考えられます。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;新しいバージョンをベースにしてシンタックスを個別に禁止する&lt;/li&gt;
  &lt;li&gt;古いバージョンをベースにしてシンタックスを個別に許容する&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;YAS開発環境では「古いバージョン」をベースにしました。新しいシンタックスをひとつずつ試して禁止していくよりも、ランタイムで大半のシンタックスが使える古いバージョンをベースにするほうが楽だからです。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/tsconfig.json#L6&quot;&gt;tsconfig.json&lt;/a&gt; には、やや古めの &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ES6&lt;/code&gt; を指定しています。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;compilerOptions&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;lib&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ES6&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ES6 === ES2015&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;シンタックスを禁止するeslint&quot;&gt;シンタックスを禁止する（ESLint）&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class（ES6）&lt;/code&gt; はTypeScriptではコンパイルエラーになりませんが、Yahoo!広告スクリプトのランタイムでシンタックスエラーが発生します。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Foo&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// コンパイルエラーにならない&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;このようなケースでは、うっかりコードを書かないように &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/eslint.config.js&quot;&gt;eslint.config.js&lt;/a&gt; のルールで使用を禁止します。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;esPlugin&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;eslint-plugin-es&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;**/*.ts&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;es&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;esPlugin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// `es/` プレフィクスを有効にする&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;es/no-classes&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// classの使用を禁止する&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Foo&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ~~~~~~~~~&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ERROR: ES2015 class declarations are forbidden.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;シンタックスを許容するdeclare宣言&quot;&gt;シンタックスを許容する（declare宣言）&lt;/h2&gt;

&lt;p&gt;開発中に &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object.groupBy（ES2024）&lt;/code&gt; が使いたくなることがありました。YAS開発環境はES6のため、ES2024のAPIの型は存在しません。そのまま書くと型の解決ができずコンパイルエラーが発生します。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;groupBy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([],&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{});&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//     ~~~~~~~~&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//     ERROR: Property &apos;groupBy&apos; does not exist on type &apos;ObjectConstructor&apos;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object.groupBy&lt;/code&gt; はYahoo!広告スクリプトのランタイムではシンタックスエラーにならず、期待通りの結果が返ることが分かりました。このようなケースでは、declare宣言で型を解決します。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;declare&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kr&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ObjectConstructor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;groupBy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;K&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...):&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Partial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Record&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;K&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;groupBy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([],&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{});&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 👍&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;シンタックスを許容するrollup&quot;&gt;シンタックスを許容する（Rollup）&lt;/h2&gt;

&lt;p&gt;YAS開発環境はES6のため &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional chaining（ES2020）&lt;/code&gt; を使うとコンパイルエラーが発生します。この構文はYahoo!広告ランタイムでもシンタックスエラーが発生し、使うことができません。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ~~  ~~&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ERROR: ES2020 optional chaining is forbidden.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;このようなケースでは、Rollupでポリフィルできないか探しましょう。&lt;/p&gt;

&lt;p&gt;Rollupでは &lt;a href=&quot;https://rollupjs.org/configuration-options/#output-generatedcode&quot;&gt;generatedCode&lt;/a&gt; で指定したECMAScriptのバージョンにより、一部のコードがポリフィルの対象になります。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;generatedCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;es5&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ES5で出力する&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Before: index.ts&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// After: publish.js&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ポリフィルできることが分かれば &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/eslint.config.js&quot;&gt;eslint.config.js&lt;/a&gt; で許容しておきましょう。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;es/no-optional-chaining&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;off&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ルールをオフにする&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// 👍&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;シンタックスを禁止するeslintカスタムルール&quot;&gt;シンタックスを禁止する（ESLintカスタムルール）&lt;/h2&gt;

&lt;p&gt;Yahoo!広告ランタイムでは &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;〜&lt;/code&gt; という文字が使用できませんでした。コメントアウトの中に存在していても「使用できない文字が含まれている」と保存時にエラーになる事がありました。&lt;/p&gt;

&lt;p&gt;Yahoo!広告ランタイムの独自エラーのため、TypeScriptのコンパイルエラーでは検出できません。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;Logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1〜100件のデータ取得完了&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// コンパイルエラーにならない&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;このようなケースでは &lt;a href=&quot;https://eslint.org/docs/latest/extend/custom-rule-tutorial&quot;&gt;Custom Rule Tutorial&lt;/a&gt; を参考にしてESLintのカスタムルールを追加します。YAS開発環境では &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/lint/plugin.js&quot;&gt;plugin.js&lt;/a&gt; にカスタムルール置き場を用意しています。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;plugin&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;meta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;eslint-plugin-no-wave-dash&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ルール名&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1.0.0&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;no-wave-dash&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ルールの実装&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;nx&quot;&gt;Literal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;〜&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
                  &lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                  &lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Yahoo!広告スクリプトで&apos;〜&apos;は使えません。&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
              &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
              &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;追加したカスタムルールは &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/eslint.config.js#L48&quot;&gt;eslint.config.js&lt;/a&gt; で有効にします。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;plugin&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;./lint/plugin.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;custom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;plugin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// `custom/` プレフィクスを有効にする&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;custom/no-wave-dash&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 禁止する&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;このようにすると、Yahoo!広告スクリプトの独自エラーを検出できるようになります。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;Logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1〜100件のデータ取得完了&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//          ~~~~~~~~~~~~~~~~~~~~~&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// ERROR: Yahoo!広告スクリプトで&apos;〜&apos;は使えません。eslint(custom/no-wave-dash)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;既存プロジェクトへの展開&quot;&gt;既存プロジェクトへの展開&lt;/h1&gt;

&lt;p&gt;セットアップ用スクリプトを使うことで、同じYAS開発環境のプロジェクトをいくつも作ることができます。&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npx ringtail003/yas-scaffold yas &lt;span class=&quot;nt&quot;&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Yahoo!広告ランタイムのアップデートでそれまで使えなかったシンタックスが使えるようになったり、Node.jsのアップデートで便利な機能が使えるようになるかもしれません。YAS開発環境もそれに合わせて進化していくでしょう。&lt;/p&gt;

&lt;p&gt;そんな時のために更新用のスクリプトも用意しています。設定ファイルを再びリポジトリからコピーして、パッケージ更新を促すだけのスクリプトです。&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;npx quartetcom/yas-scaffold yas &lt;span class=&quot;nt&quot;&gt;--update&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 設定ファイルをコピーしました（eslint.config.js）
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ...
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; package.json &lt;span class=&quot;s1&quot;&gt;&apos;devDependencies&apos;&lt;/span&gt; をインストールしてください
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ┌─────────┬─────────────┬─────────┬──────────┐
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; │ &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;index&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; │ name        │ current │ required │
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ├─────────┼─────────────┼─────────┼──────────┤
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; │ 0       │ &lt;span class=&quot;s1&quot;&gt;&apos;package-A&apos;&lt;/span&gt; │ &lt;span class=&quot;s1&quot;&gt;&apos;1.0.0&apos;&lt;/span&gt; │ &lt;span class=&quot;s1&quot;&gt;&apos;3.0.0&apos;&lt;/span&gt;  │
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; └─────────┴─────────────┴─────────┴──────────┘
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; npm &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;   package-A@3.0.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;実装は &lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/bin/yas-cli.js&quot;&gt;yas-cli.js&lt;/a&gt; に存在します。&lt;a href=&quot;https://github.com/ringtail003/yas-scaffold/blob/0348f7d276ca51fef996c4558ac17fa103a12947/package.json#L29&quot;&gt;package.json&lt;/a&gt; に登録することでnpxでの実行が可能になります。&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;yas&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;./bin/yas-cli.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;セットアップ用スクリプトで作成したプロジェクトでは、テストランナーの変更など個別のカスタマイズを想定していません。ベースとなるYAS開発環境のリポジトリに変更を加え更新用スクリプトで配布します。&lt;/p&gt;

&lt;p&gt;このような仕組みにすることで、プロジェクトの数が増えてもYahoo!広告ランタイムやNode.jsのアップデートにかんたんに追随できると考えました。&lt;/p&gt;

&lt;h1 id=&quot;おわりに&quot;&gt;おわりに&lt;/h1&gt;

&lt;p&gt;Yahoo!広告スクリプトに限らず、他のランタイムでも同じ仕組みで開発環境が構築できるのではないかと思います。&lt;/p&gt;

&lt;p&gt;今回紹介した内容がどなたかのお役に立てば幸いです。&lt;/p&gt;

</description>
        <pubDate>Wed, 05 Mar 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>PHPカンファレンス名古屋2025 プラチナスポンサー参加レポート | QUARTETCOM TECH BLOG</title>
        
        
        <category>PHP</category>
        
        <category>PHPカンファレンス</category>
        
        <category>イベント</category>
        
        <link>https://tech.quartetcom.co.jp/2025/03/03/phpcon-nagoya-2025-report/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/03/03/phpcon-nagoya-2025-report/</guid>
        <description>
&lt;p&gt;&lt;a href=&quot;https://phpcon.nagoya/2025/&quot; target=&quot;_blank&quot;&gt;PHPカンファレンス名古屋2025&lt;/a&gt;にプラチナスポンサーとして協賛しブース出展、スタッフとして参加しました！&lt;br /&gt;
初ブース出展で当日は運営スタッフとしての参加だったのでセッションは見ることができませんでしたが、PHPを扱う会社としてPHP業界に貢献できよかったです！&lt;br /&gt;
当日はイベント来場者がアンケートや企画参加のためにブースに来ていただきとても盛り上がったかなと思っています、ありがとうございました！&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-02-27/width840.jpg&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;ブースアンケート集計結果&quot;&gt;ブースアンケート集計結果&lt;/h2&gt;

&lt;h3 id=&quot;ソフトウェア開発においてai技術の活用は全体の何を占めていますか&quot;&gt;ソフトウェア開発においてAI技術の活用は全体の何%を占めていますか？&lt;/h3&gt;

&lt;p&gt;アンケート内容の定義は以下の通りです。&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;縦軸：自分が所属しているチーム単位の人数&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;横軸：その業務でAI技術を活用しているパーセンテージ&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-02-27/width840_2.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;開発規模は1~10人、AI利用率は0%~50%に多く分布していたものの、その中では大きな偏りがない結果となりました。&lt;br /&gt;
回答者の中には、AIの利用率が低いことで謙遜する方や、逆に利用率が高いことで謙遜する方が見受けられました。また、全体としてAIの活用が思ったより進んでいるという声が多くありました。&lt;/p&gt;

&lt;h3 id=&quot;あなたの勤務スタイルは&quot;&gt;あなたの勤務スタイルは？&lt;/h3&gt;

&lt;p&gt;最近ではフルリモート勤務からハイブリット勤務や出社勤務に戻す企業も増えている印象がありましたが、&lt;br /&gt;
結果を見ると、フルリモート勤務が多いという結果でした。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/2025-02-27/width840_3.jpg&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;初ブース出展の感想&quot;&gt;初ブース出展の感想&lt;/h2&gt;

&lt;p&gt;初ブース出展でしたが、PHP業界の方々と交流できてとても楽しかったです。&lt;br /&gt;
WebサイトをPHPを使って構築・運用されている方などには、弊社で開発しているWeb広告レポートツール(&lt;a href=&quot;https://lisket.jp/&quot;&gt;Lisket&lt;/a&gt;)やGoogleアナリティクスレポートツール(&lt;a href=&quot;https://mugenreport.com/&quot;&gt;無限GAレポートメーカー&lt;/a&gt;) に関心を寄せてくださる参加者もいらっしゃいました。
そのような方々と直接話すことで、ブース出展を行う企業向けのスポンサープランならではの価値を実感する場面もありました。&lt;br /&gt;
個人的には勉強会への企業からのスポンサーは、企業PRとPHPコミュニティーへの恩返しの意味が強いのかなと思っています。&lt;br /&gt;
PHPは古いと言われることも多々ありますが、多くのエンジニアに愛されている言語なんだなと実感しました。&lt;br /&gt;
恩返しという意味では、他にもOSSへの貢献(バグ報告やドキュメント改善など)やPHP Foundationへの寄付などがあると思いますが、PHPを使う企業に属する者としてコミュニティーへの貢献は継続的にしていけたらいいなと思います。&lt;/p&gt;

&lt;h2 id=&quot;カルテット開発部について&quot;&gt;カルテット開発部について&lt;/h2&gt;

&lt;p&gt;カルテット開発部は、インターネット広告専門の広告代理店内の開発部門です。&lt;br /&gt;
少人数の部署ですが、広告運用を効率化する &lt;a href=&quot;https://lisket.jp&quot; target=&quot;_blank&quot;&gt;Lisket&lt;/a&gt; とウェブサイト運営に欠かせないGoogleAnalyticsのレポートをエクセル形式で出力できる &lt;a href=&quot;https://mugenreport.com&quot; target=&quot;_blank&quot;&gt;無限GAレポートメーカー&lt;/a&gt; という2つのWebサービスを開発〜運営まで行っています。既存システムの保守だけでなく社内システムや新規事業などの新規プロダクトの開発も進行中で、直近プロダクトではスクラム開発も実施しておりました。&lt;br /&gt;
フルリモート勤務も可能でライフワークバランスも大切にしているので、PHPを使うエンジニアの方々にも働きやすい環境を提供できると思います。&lt;br /&gt;
オンラインカジュアル面談も随時受け付けているので、少しでも興味を持っていただいた方はぜひ&lt;a href=&quot;https://quartetcom.co.jp/recruit/engineer/&quot;&gt;お気軽にお問い合わせください&lt;/a&gt;。&lt;/p&gt;

</description>
        <pubDate>Mon, 03 Mar 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>PHPカンファレンス名古屋2025にプラチナスポンサーとして協賛します | QUARTETCOM TECH BLOG</title>
        
        
        <category>PHP</category>
        
        <category>PHPカンファレンス</category>
        
        <category>イベント</category>
        
        <link>https://tech.quartetcom.co.jp/2025/02/20/phpcon-nagoya-2025/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/02/20/phpcon-nagoya-2025/</guid>
        <description>
&lt;p&gt;&lt;a href=&quot;https://phpcon.nagoya/2025/&quot; target=&quot;_blank&quot;&gt;PHPカンファレンス名古屋2025&lt;/a&gt;にプラチナスポンサーとして協賛いたします。&lt;br /&gt;
当日はブースも構えて会場に参加しているので、ぜひ立ち寄っていただければと思います。&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;名古屋でのPHPカンファレンス開催は今回が初めてでカルテットコミュニケーション開発部からは運営スタッフとしても参加します！&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;phpカンファレンス名古屋について&quot;&gt;PHPカンファレンス名古屋について&lt;/h2&gt;

&lt;p&gt;都市規模に比して不活発と言われているエンジニアコミュニティ活動を活発にしたい！&lt;br /&gt;
地理的な理由でこれまで各地のカンファレンスに参加できなかった地方在住のエンジニアの方の参加を通して、名古屋のエンジニアと全国のエンジニアの交流が促進され名古屋のエンジニアコミュニティにも新たな風を吹き込みたい！&lt;br /&gt;
そんな思いから開催されるカンファレンスです。&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;【概要】&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;日時：2025年2月22日(土)&lt;br /&gt;
（開場 9:30、本編 10:00〜18:00、懇親会 19:00〜21:00）&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;会場：ウインクあいち 11F&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;公式サイト：&lt;a href=&quot;https://phpcon.nagoya/2025/&quot;&gt;https://phpcon.nagoya/2025/&lt;/a&gt; &lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;公式Twitter：&lt;a href=&quot;https://x.com/phpcon_nagoya&quot;&gt;https://x.com/phpcon_nagoya&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;カルテット開発部について&quot;&gt;カルテット開発部について&lt;/h2&gt;

&lt;p&gt;カルテット開発部は、インターネット広告専門の広告代理店内の開発部門です。&lt;br /&gt;
少人数の部署ですが、広告運用を効率化する &lt;a href=&quot;https://lisket.jp&quot; target=&quot;_blank&quot;&gt;Lisket&lt;/a&gt; とウェブサイト運営に欠かせないGoogleAnalyticsのレポートをエクセル形式で出力できる &lt;a href=&quot;https://mugenreport.com&quot; target=&quot;_blank&quot;&gt;無限GAレポートメーカー&lt;/a&gt; という2つのWebサービスを開発〜運営まで行っています。既存システムの保守だけでなく社内システムや新規事業などの新規プロダクトの開発も進行中で、直近プロダクトではスクラム開発も実施しておりました。&lt;br /&gt;
PHPer絶賛募集中です！少しでも興味を持っていただいた方はぜひオフライン・オンライン両会場で弊社エンジニアにお声掛けください。&lt;/p&gt;

</description>
        <pubDate>Thu, 20 Feb 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>同一 MySQL サーバ上の複数データベースに対する権限設定 - Ansible mysql_user モジュールで実装する際の注意点 | QUARTETCOM TECH BLOG</title>
        
        
        <category>Ansible</category>
        
        <category>MySQL</category>
        
        <category>構成管理</category>
        
        <category>Docker</category>
        
        <link>https://tech.quartetcom.co.jp/2025/02/14/ansible-mysql_user-test-tool/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/02/14/ansible-mysql_user-test-tool/</guid>
        <description>
&lt;h2 id=&quot;結論&quot;&gt;結論&lt;/h2&gt;

&lt;p&gt;同一 MySQL サーバに共存させた複数データベースに存在するユーザーに対して任意の権限を付与するには、&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt; を使う必要があります。&lt;/strong&gt; &lt;br /&gt;
Ansible の &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mysql_user&lt;/code&gt; モジュールでは、同じユーザーに対して複数回 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;priv&lt;/code&gt; を指定すると、後から指定した値が優先されるからです。&lt;/p&gt;

&lt;p&gt;この挙動を整理した時の経緯を紹介します。&lt;/p&gt;

&lt;h2 id=&quot;何で困っていたか&quot;&gt;何で困っていたか&lt;/h2&gt;

&lt;p&gt;同一サーバに複数のデータベースを作成し、 Ansible を使ったユーザー作成と権限管理を行なっていましたが、この際の挙動を捉えるのに苦労しました。&lt;/p&gt;

&lt;p&gt;例えば、user1 に対する以下のような設定を想定しているとします。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;database_a&lt;/code&gt; の全てのテーブルに対する &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SELECT&lt;/code&gt; 権限&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;database_b&lt;/code&gt; の全てのテーブルに対する &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ALL&lt;/code&gt; 権限&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;この想定で playbook.yml を次のように記述した場合&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;user1&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;localhost&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;priv&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;database_a.*:SELECT&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password1&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;user1&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;localhost&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;priv&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;database_b.*:ALL&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password1&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ansible による実行結果は以下のようになり、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user1&lt;/code&gt; に関する &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;database_a&lt;/code&gt; への権限を付与できませんでした。&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Select_priv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Update_priv&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Host&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;User&lt;/span&gt;          &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Db&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Select_priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Update_priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;performance_schema&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;                &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user1&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database_b&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;実行順序を入れ替えても&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;user1&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;localhost&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;priv&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;database_b.*:ALL&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password1&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;user1&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;localhost&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;priv&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;database_a.*:SELECT&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password1&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;以下のような結果となり、やはり &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user1&lt;/code&gt; に関してデータベースごとに異なる権限を付与できませんでした。&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Select_priv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Update_priv&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Host&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;User&lt;/span&gt;          &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Db&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Select_priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Update_priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;performance_schema&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;                &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user1&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database_a&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;上記以外にも、カンマやリストを使った記述方法も試しましたが、いずれも望んだ結果を得られませんでした。&lt;/p&gt;

&lt;h2 id=&quot;どうやって解決したか&quot;&gt;どうやって解決したか&lt;/h2&gt;

&lt;p&gt;公式情報をちゃんと読み、簡単な検証ツールを作って検証しました。 
最終的に以下のような記述により、期待した結果を得ました。&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;user1&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;localhost&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;priv&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;database_a.*:SELECT/database_b.*:ALL&apos;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;password1&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Select_priv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Update_priv&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Host&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;User&lt;/span&gt;          &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Db&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Select_priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Update_priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;performance_schema&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mysql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;                &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user1&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database_a&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user1&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database_b&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-----------+---------------+--------------------+-------------+-------------+&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;公式ドキュメント&quot;&gt;公式ドキュメント&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;Multiple privileges can be specified by separating each one using a forward slash: db.table1:priv/db.table2:priv.&lt;/p&gt;

  &lt;p&gt;&lt;a href=&quot;https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_user_module.html#parameter-priv&quot;&gt;https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_user_module.html#parameter-priv&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;検証ツール&quot;&gt;検証ツール&lt;/h3&gt;

&lt;p&gt;こちらは GitHub に公開しましたので、興味のある方はご活用ください。 
このツールは MySQL に対する Ansible の挙動を Docker を使って確認するのに役立ちます。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/Tatsumi-I/ansible-mysql_user-test-tool&quot;&gt;https://github.com/Tatsumi-I/ansible-mysql_user-test-tool&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;まとめ&quot;&gt;まとめ&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;同一ユーザーへ複数回 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;priv&lt;/code&gt; を指定した際の挙動を理解していないと、想定した権限を付与できないことがあります。&lt;/li&gt;
  &lt;li&gt;同一サーバに共存する複数データベースにおけるユーザーへ任意の権限を付与するには、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt; を使う必要があります。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;また、Ansible における変数の扱いやその優先度も併せて把握することが重要です。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;In general, Ansible gives precedence to variables that were defined more recently, more actively, and with more explicit scope. Variables in the defaults folder inside a role are easily overridden. Anything in the vars directory of the role overrides previous versions of that variable in the namespace.&lt;/p&gt;

  &lt;p&gt;&lt;a href=&quot;https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#understanding-variable-precedence&quot;&gt;https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#understanding-variable-precedence&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;どんなツールでもとっかかりは難しいですが、使えると開発者体験が大きく向上しますね。
これがその一助となりましたら幸いです。&lt;/p&gt;

&lt;h2 id=&quot;参考検証環境&quot;&gt;（参考）検証環境&lt;/h2&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt;
Docker version 27.4.0, build bde2b89
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# mysql --version&lt;/span&gt;
mysql  Ver 8.0.37
&lt;span class=&quot;c&quot;&gt;# ansible --version&lt;/span&gt;
ansible &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;core 2.13.13]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Fri, 14 Feb 2025 00:00:00 +0900</pubDate>
      </item>
    
      



      <item>
        <title>意思決定を未来へ届ける | QUARTETCOM TECH BLOG</title>
        
        
        <category>意思決定</category>
        
        <link>https://tech.quartetcom.co.jp/2025/01/07/delivering-system-design-documents-to-the-future/</link>
        <guid isPermaLink="true">https://tech.quartetcom.co.jp/2025/01/07/delivering-system-design-documents-to-the-future/</guid>
        <description>
&lt;h2 id=&quot;はじめに&quot;&gt;はじめに&lt;/h2&gt;

&lt;p&gt;開発部の 有澤 です。&lt;/p&gt;

&lt;p&gt;数ヶ月ほど前に、社内アプリケーションの開発責任者(いわゆるプロダクトマネージャー)になりました。
役割を通じて、ステークホルダーと関わることが増え、既存システムに機能を加える機会が増えてきました。&lt;/p&gt;

&lt;p&gt;私は新たな要望に応えるため、既存システムと新規機能を比較し、「どのような設計で実現できるか」を検討する機会が増えましたが、
その過程で一つの懸念が浮かびました。&lt;/p&gt;

&lt;h2 id=&quot;システム設計書は時間と共に風化する&quot;&gt;システム設計書は時間と共に風化する&lt;/h2&gt;

&lt;p&gt;私がこれまでに触れてきたシステム設計書には、さまざまな形式がありました。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Excel&lt;/li&gt;
  &lt;li&gt;PowerPoint&lt;/li&gt;
  &lt;li&gt;ナレッジベース&lt;/li&gt;
  &lt;li&gt;コードベース&lt;/li&gt;
  &lt;li&gt;人の頭の中&lt;/li&gt;
  &lt;li&gt;GitHub Issue&lt;/li&gt;
  &lt;li&gt;Pull Request&lt;/li&gt;
  &lt;li&gt;Commit メッセージ&lt;/li&gt;
  &lt;li&gt;Slack メッセージ&lt;/li&gt;
  &lt;li&gt;紙&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;これらはチームや組織の状況に応じて形が変わるもので、どれが優れているかは一概に言えません。&lt;/p&gt;

&lt;p&gt;しかし、共通する課題があります。それは、時間とともに「リンク切れ」「検索不可」「消失」などの問題が発生し、情報が風化する点です。
また、これらの情報が分散しているため、仕様を再確認する作業がまるで「地層から化石を掘り起こし、全体像を再構築する」ような作業が必要だったりします。&lt;/p&gt;

&lt;p&gt;私はこういった情報の復元に慣れていますが、面倒であるのは確かです。&lt;br /&gt;
このような状況を自分も生み出してしまうのかと思うと、どうにか解決したいと考えるようになりました。&lt;/p&gt;

&lt;h2 id=&quot;未来人はシステム設計書で何を知りたいのか&quot;&gt;未来人はシステム設計書で何を知りたいのか&lt;/h2&gt;

&lt;p&gt;未来の開発者が何を知りたいかを完全に予測することは難しいです。&lt;/p&gt;

&lt;p&gt;ですが、自分やチームが「何が必要か？」を考えたり、話し合ったりはできます。&lt;br /&gt;
自分やチームが必要なものが書かれていれば、少なからず未来人は意思決定の参考になるはずです。&lt;/p&gt;

&lt;p&gt;考えるに、以下のようなことだと定義しました。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;なぜこの設計を採用したか？&lt;/li&gt;
  &lt;li&gt;他に代替案はなかったか？&lt;/li&gt;
  &lt;li&gt;この設計はシステムへ適応済みか？&lt;/li&gt;
  &lt;li&gt;適応したかった設計はあるか？&lt;/li&gt;
  &lt;li&gt;大小限らず、発見した技術的負債はあるか？&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;これらをまとめると、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;「意思決定の判断材料」として機能する情報&lt;/code&gt; が必要だと考えました。&lt;/p&gt;

&lt;p&gt;この情報があれば、未来の開発者がシステム変更時にスムーズな判断を下せるようになるはずです。&lt;/p&gt;

&lt;h2 id=&quot;adr-を採用しました&quot;&gt;ADR を採用しました&lt;/h2&gt;

&lt;p&gt;ADR は比較的軽量なフレームワークだったのもあり、こちらを採用することにしました。&lt;/p&gt;

&lt;p&gt;とはいえ ADR のテンプレートにしっかり準拠するのではなくて、 必要な情報を箇条書きで書ける独自テンプレートを使用することにしました。&lt;/p&gt;

&lt;p&gt;ドキュメントを書くためのフレームワークを調べたところ、以下がありました。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Design Doc
    &lt;ul&gt;
      &lt;li&gt;システムや機能の詳細な設計を記録したドキュメントで、特定の技術的なソリューションや実装について深く掘り下げているのが特徴。&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.industrialempathy.com/posts/design-docs-at-google/&quot;&gt;https://www.industrialempathy.com/posts/design-docs-at-google/&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Architecture Decision Records (ADR)
    &lt;ul&gt;
      &lt;li&gt;システム設計における重要な意思決定を記録するための簡潔なドキュメント。&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://adr.github.io/&quot;&gt;https://adr.github.io/&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Lightweight Architecture Decision Records (LADR)
    &lt;ul&gt;
      &lt;li&gt;ADRの簡易版で、より軽量な記録形式。小規模なプロジェクトや頻繁な意思決定の記録に適してそう。&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/peter-evans/lightweight-architecture-decision-records?tab=readme-ov-file&quot;&gt;https://github.com/peter-evans/lightweight-architecture-decision-records?tab=readme-ov-file&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;adr-の配置&quot;&gt;ADR の配置&lt;/h2&gt;

&lt;p&gt;PHP アプリケーションのルート直下に doc/adr/ を作成して、その中にマークダウンファイルを格納しています。&lt;/p&gt;

&lt;p&gt;エディタ上で閲覧・編集が簡潔するので開発者的には嬉しいですし、
バージョン管理されるため、ドキュメントがロストしにくくなります。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PHP Application (root)
└── doc
    └── adr
        ├── 2024-08-23-依存ライブラリの見直し.md
        ├── 2024-11-29-◯◯機能の縮小.md
        ├── 2024-12-17-ADRの導入.md
        ├── 2024-12-18-◯◯機能の再設計.md
        └── README.md
└── public
└── config
└── .dockerignore
└── etc...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;アプリケーションデプロイ時にドキュメントが増えることを避けたい場合は、.dockerignore で doc/ を無視することを推奨します。&lt;/p&gt;

&lt;h2 id=&quot;adr-のテンプレート&quot;&gt;ADR のテンプレート&lt;/h2&gt;

&lt;p&gt;必要な情報を最小限に集めたいので、以下のテンプレートを定義しました。&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## 背景（Background）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 問題の概要と目的。
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; システムが解決しようとする課題。 

&lt;span class=&quot;gu&quot;&gt;## 目標と非目標（Goals and Non-Goals）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 目標: このプロジェクトで達成すべきことを具体的に記述。
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 非目標: このプロジェクトでは対応しないことを明確にしてスコープを限定。

&lt;span class=&quot;gu&quot;&gt;## 提案内容（Proposal）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 問題を解決するアプローチ。
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 技術的な選択肢や、それぞれのメリット・デメリット。

&lt;span class=&quot;gu&quot;&gt;## 技術設計（Technical Design）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; システムのアーキテクチャ。
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; データベース設計やAPI仕様の詳細。
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; PHPフレームワークや主要ライブラリの選定理由。

&lt;span class=&quot;gu&quot;&gt;## 代替案（Alternatives Considered）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 他に検討したアプローチと採用しなかった理由。
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; リスクとトレードオフ（Risks and Tradeoffs）
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 現状では想定しづらいリスクや、トレードオフについて明記。

&lt;span class=&quot;gh&quot;&gt;# マイルストーンとスケジュール（Milestones and Timeline）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; プロジェクトのスケジュールと各フェーズのゴール。
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 未解決の問題（Unresolved Questions）
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 現段階では結論に至っていない内容。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;そもそも、ドキュメントを書くことは開発者のオーバーヘッドです。
見出しに対して文字を埋めることを強要せず、必要な情報だけを書ける柔軟な形式を理想としています。&lt;/p&gt;

&lt;h2 id=&quot;adr-の内容&quot;&gt;ADR の内容&lt;/h2&gt;

&lt;p&gt;まずは「ADRを導入した際の意思決定」を書くのがスタートに丁度よいです。
実際の物よりもボカシていますが、以下のように書きました。&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gh&quot;&gt;# 2024-12-17 ADRの導入&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;## 背景（Background）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; ◯◯ の設計や機能を変更する上で、変更箇所や理由、意思決定が継承されづらい状況であることが懸念だった。

&lt;span class=&quot;gu&quot;&gt;## 目標と非目標（Goals and Non-Goals）&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;### 目標&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; ADRを導入することで、意思決定を継承する。
&lt;span class=&quot;p&quot;&gt;  -&lt;/span&gt; 初期段階で完璧なADRは目指さないで、まずは簡単な形で導入を目指す。

&lt;span class=&quot;gu&quot;&gt;### 非目標&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; なし

&lt;span class=&quot;gu&quot;&gt;## 提案内容（Proposal）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; ADRを導入
&lt;span class=&quot;p&quot;&gt;  -&lt;/span&gt; コードと一緒に保管される形容なら、プロダクトが生き続く限り残るのでベストと判断した。
&lt;span class=&quot;p&quot;&gt;  -&lt;/span&gt; エディタ内で完結することもDX的に良い。

&lt;span class=&quot;gu&quot;&gt;## 代替案（Alternatives Considered）&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Notionやその他のナレッジベースで管理すること
&lt;span class=&quot;p&quot;&gt;  -&lt;/span&gt; リンク切れを起こしたり、そもそも形容として形骸化しやすいので避けた。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;adr-のメンテナンス&quot;&gt;ADR のメンテナンス&lt;/h2&gt;

&lt;p&gt;「必要だと思ったり、便利だと感じる人が増えたら必然的に良いADRが残るはず」と期待しているので、
メンテナンスに関するルールは定義していません。&lt;/p&gt;

&lt;p&gt;また、ドキュメントをバージョン管理することのデメリットの一つとして「Pull Requestをレビューする必要」がありますが、
doc/ ディレクトリ配下はレビュー不要とすることで、ドキュメントのメンテナンスのハードルを下げても良いと感じています。&lt;/p&gt;

&lt;h2 id=&quot;所感&quot;&gt;所感&lt;/h2&gt;

&lt;p&gt;書いた自分でも後々思うのは、代替案が書いてあるのは凄く便利です。&lt;/p&gt;

&lt;p&gt;新たに機能を開発した後「なぜこうしなかったのか？」と話が上がることは、プロダクト開発においてよくあります。
その際に自分の記憶が曖昧になっていたり、そもそも自分が退職してしまった時に説明できないのは問題だと感じていたので、
ADR を通してプロダクトの持続可能性を高められたら嬉しいです。&lt;/p&gt;

</description>
        <pubDate>Tue, 07 Jan 2025 00:00:00 +0900</pubDate>
      </item>
    
  </channel>
</rss>
