<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ayumi Tamai</title>
    <description>The latest articles on DEV Community by Ayumi Tamai (@ayumitamai97).</description>
    <link>https://dev.to/ayumitamai97</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F457339%2F0a6003b5-a342-49e6-a31d-acea031d0db1.png</url>
      <title>DEV Community: Ayumi Tamai</title>
      <link>https://dev.to/ayumitamai97</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayumitamai97"/>
    <language>en</language>
    <item>
      <title>Continuously generate TypeScript typings from GraphQL schema across multiple repositories 🚀</title>
      <dc:creator>Ayumi Tamai</dc:creator>
      <pubDate>Thu, 28 Jan 2021 17:47:50 +0000</pubDate>
      <link>https://dev.to/ayumitamai97/continuously-generate-typescript-typings-from-graphql-schema-across-multiple-repositories-37ab</link>
      <guid>https://dev.to/ayumitamai97/continuously-generate-typescript-typings-from-graphql-schema-across-multiple-repositories-37ab</guid>
      <description>&lt;p&gt;&lt;a href="https://graphql-code-generator.com/" rel="noopener noreferrer"&gt;GraphQL Code Generator&lt;/a&gt; (&lt;code&gt;graphql-codegen&lt;/code&gt;) is very useful when you use GraphQL on the server-side and TypeScript on the client-side. If you use GraphQL and TypeScript, you will declare TypeScript typings based on your GraphQL schema for sure. Instead of writing TypeScript types one by one, &lt;code&gt;graphql-codegen&lt;/code&gt; generates type declarations out of the GraphQL schema which is 1:1 to the schema.&lt;br&gt;&lt;br&gt;
However, you may have problem generating type declarations from the latest GraphQL schema using &lt;code&gt;graphql-codegen&lt;/code&gt; when you develop API and client app in the different GitHub repositories. How should it be solved?&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic usage of &lt;code&gt;graphql-codegen&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;A minimal example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;schema.graphql&lt;/span&gt;
&lt;span class="na"&gt;generates&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;./src/graphql-schema.ts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;schema&lt;/code&gt; field accepts 1) URL of GraphQL endpoint, 2) local schema file in &lt;code&gt;*.graphql&lt;/code&gt; or JSON format, 3) remote &lt;code&gt;*.graphql&lt;/code&gt; file in GitHub repository, and so on.&lt;/p&gt;

&lt;p&gt;Refer to &lt;a href="https://graphql-code-generator.com/docs/getting-started/codegen-config" rel="noopener noreferrer"&gt;GraphQL Code Generator's documentation&lt;/a&gt; for more details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;Before proceeding to the next section, ensure that you have the following:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. GraphQL project and its corresponding GitHub repository
&lt;/h4&gt;

&lt;p&gt;Mine is a Rails application along with &lt;code&gt;graphql-ruby&lt;/code&gt; gem, and the app is named &lt;code&gt;cont-codegen-sandbox-api&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Application made with TypeScript and its corresponding GitHub repository
&lt;/h4&gt;

&lt;p&gt;Mine is &lt;code&gt;cont-codegen-sandbox-client&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. GraphQL schema generator
&lt;/h4&gt;

&lt;p&gt;A script to generate GraphQL schema file such as &lt;code&gt;schema.graphql&lt;/code&gt; on the server-side. I'm using &lt;a href="https://github.com/rmosolgo/graphql-ruby/blob/792f276444e1dd6004fcafe3820d65fdbbe285f0/lib/graphql/rake_task.rb" rel="noopener noreferrer"&gt;lib/graphql/rake_task.rb&lt;/a&gt; (&lt;code&gt;rake graphql:schema:idl&lt;/code&gt;) for this.&lt;/p&gt;

&lt;p&gt;I recommend that you automate this file generation by using git pre-commit hook or GitHub application.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. GitHub personal access token
&lt;/h4&gt;

&lt;p&gt;Set your GitHub personal access token to your repository's secret. In my case, the secret's name is &lt;code&gt;PERSONAL_ACCESS_TOKEN&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The token should have access to scope &lt;code&gt;repo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx0fjewhe5txs0v85r30r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx0fjewhe5txs0v85r30r.png" alt="new_personal_access_token"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;graphql-codegen&lt;/code&gt; and GitHub Action use the token whether the repo is private or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate typings across repos
&lt;/h2&gt;

&lt;p&gt;If your GraphQL project and client app are in the same directory or in the same GitHub repository, the basic example above should be enough. On the other hand, when your applications are managed in different repositories, how should you do?&lt;/p&gt;

&lt;p&gt;In that case, you can specify the remote &lt;code&gt;schema.graphql&lt;/code&gt; in a GitHub repository (including private repository ✨). &lt;code&gt;codegen.yml&lt;/code&gt; should be following syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;user/repo#branchName:path/to/schema.graphql:&lt;/span&gt;
      &lt;span class="s"&gt;token&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${PERSONAL_ACCESS_TOKEN}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;token&lt;/code&gt; field is always required because &lt;code&gt;graphql-codegen&lt;/code&gt; can access to your repository, which is not described in the official documentation. Even your repo is public, it requires &lt;code&gt;token&lt;/code&gt; as of today, Jan 2021. I don't know if this is a bug.&lt;/p&gt;

&lt;p&gt;If you're using dotenv, codegen command is &lt;code&gt;graphql-codegen -r dotenv/config&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is my &lt;code&gt;codegen.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;github:ayumitamai97/cont-codegen-sandbox-api#main:schema.graphql:&lt;/span&gt;
      &lt;span class="s"&gt;token&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${PERSONAL_ACCESS_TOKEN}&lt;/span&gt;

&lt;span class="na"&gt;generates&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;./types/graphql-schema.ts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript&lt;/span&gt;
    &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;apolloClientVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can generate type declation for TypeScript by hitting &lt;code&gt;yarn graphql-codegen -r dotenv/config&lt;/code&gt; 🔥&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuously generate typings across repos
&lt;/h2&gt;

&lt;p&gt;The previous section describes how to setup &lt;code&gt;graphql-codegen&lt;/code&gt; when having GraphQL and TypeScript projects in different repositories. Then, how can this process be automated?&lt;/p&gt;

&lt;p&gt;GitHub Action may be the best way to do that. We need to create three GitHub workflows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Notify client-side repo when GraphQL schema is updated (server-side repo)&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;graphql-codegen&lt;/code&gt; and create Pull Request (client-side repo)&lt;/li&gt;
&lt;li&gt;Automerge Pull Request (client-side repo) (optional)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Notify client-side repo when GraphQL schema is updated
&lt;/h3&gt;

&lt;p&gt;To generate TypeScript typings out of GraphQL schema almost synchronously, server-side repo has to notify client-side repo when GraphQL schema is updated.&lt;/p&gt;

&lt;p&gt;The configuration below allows the repo to trigger &lt;code&gt;repository_dispatch&lt;/code&gt; event in the other repo when a commit is pushed to &lt;code&gt;main&lt;/code&gt; branch and &lt;code&gt;schema.graphql&lt;/code&gt; has file diff.&lt;/p&gt;

&lt;p&gt;Caveat! The third step (&lt;code&gt;Dispatch update-graphql-schema&lt;/code&gt;) requires your personal access token since &lt;a href="https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token" rel="noopener noreferrer"&gt;&lt;code&gt;GITHUB_TOKEN&lt;/code&gt; cannot trigger &lt;code&gt;repository_dispatch&lt;/code&gt; event&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;.github/workflows/dispatch_graphql_schema_update.yml&lt;/code&gt; in server-side repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Dispatch GraphQL Schema Update&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;main&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v2&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;technote-space/get-diff-action@v4.0.1&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;PATTERNS&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;schema.graphql&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Dispatch update-graphql-schema&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;peter-evans/repository-dispatch@v1&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;repository&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ayumitamai97/cont-codegen-sandbox-client&lt;/span&gt;
          &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.PERSONAL_ACCESS_TOKEN }}&lt;/span&gt;
          &lt;span class="na"&gt;event-type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;update-graphql-schema&lt;/span&gt;
        &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;env.GIT_DIFF&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Execute &lt;code&gt;graphql-codegen&lt;/code&gt; and create Pull Request
&lt;/h3&gt;

&lt;p&gt;When &lt;code&gt;repository_dispatch&lt;/code&gt; event is triggered in the client-side repo, we want &lt;code&gt;graphql-codegen&lt;/code&gt; to generate TypeScript types based on the latest GraphQL schema.&lt;/p&gt;

&lt;p&gt;When the Pull Request is created, one wants to check &amp;amp; approve the PR, while another wants PR to be merged automatically. I like the latter idea, so I added some configurations to prepare for &lt;code&gt;pascalgn/automerge-action&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Caveat! The 4th step (&lt;code&gt;Create Pull Request&lt;/code&gt;) requires &lt;code&gt;PERSONAL_ACCESS_TOKEN&lt;/code&gt; if you want to automerge the Pull Request. Otherwise, &lt;code&gt;GITHUB_TOKEN&lt;/code&gt; is enough.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;.github/workflows/graphql_schema_updated.yml&lt;/code&gt; on client-side repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update GraphQL Schema&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;repository_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;update-graphql-schema&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;update-graphql-schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;checkout&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v2&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install dependencies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yarn install&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update GraphQL Schema&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;PERSONAL_ACCESS_TOKEN=${{ secrets.PERSONAL_ACCESS_TOKEN }} yarn codegen&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Create Pull Request&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;peter-evans/create-pull-request@v3&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.PERSONAL_ACCESS_TOKEN }}&lt;/span&gt; &lt;span class="c1"&gt;# `GITHUB_TOKEN` unless using automerge-action&lt;/span&gt;
          &lt;span class="na"&gt;commit-message&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;[bot]&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Update&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;GraphQL&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Schema'&lt;/span&gt;
          &lt;span class="na"&gt;committer&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;GitHub &amp;lt;noreply@github.com&amp;gt;&lt;/span&gt;
          &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.actor }} &amp;lt;${{ github.actor }}@users.noreply.github.com&amp;gt;&lt;/span&gt;
          &lt;span class="na"&gt;signoff&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
          &lt;span class="na"&gt;branch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;feature/update-graphql-schema&lt;/span&gt;
          &lt;span class="na"&gt;branch-suffix&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;timestamp&lt;/span&gt;
          &lt;span class="na"&gt;delete-branch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
          &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;[bot]&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Update&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;GraphQL&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Schema'&lt;/span&gt;
          &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;GraphQL schema has been updated&lt;/span&gt;
          &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;automerge&lt;/span&gt; &lt;span class="c1"&gt;# required if using automerge-action&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Automerge Pull Request (optional)
&lt;/h3&gt;

&lt;p&gt;If you'd like a Pull Request to be automerged which is created in GitHub workflows, &lt;a href="https://github.com/pascalgn/automerge-action" rel="noopener noreferrer"&gt;&lt;code&gt;pascalgn/automerge-action&lt;/code&gt;&lt;/a&gt; is helpful. This GitHub Action merges a PR automatically when it has &lt;code&gt;automerge&lt;/code&gt; label.&lt;/p&gt;

&lt;p&gt;As the second workflow creates a new Pull Request and adds &lt;code&gt;automerge&lt;/code&gt; label to it, the third (this) workflow should be triggered when a PR is labeled.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;.github/workflows/automerge.yml&lt;/code&gt; on client-side repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Automerge&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;labeled&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;automerge&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;automerge&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pascalgn/automerge-action@v0.13.0&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;GITHUB_TOKEN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GITHUB_TOKEN }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Working example
&lt;/h2&gt;

&lt;p&gt;Finally, your GraphQL project can &lt;strong&gt;continuously generate TypeScript typings out of GraphQL schema across repositories&lt;/strong&gt;! 🚀&lt;/p&gt;

&lt;p&gt;If you successfully configured all of the above, workflows should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5hyvjtgj10x7oesgce3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5hyvjtgj10x7oesgce3y.png" alt="server-side"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmqkexmj1gy3gzan20cum.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmqkexmj1gy3gzan20cum.png" alt="client-side"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Links to my codegen &amp;amp; workflow configurations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/ayumitamai97/cont-codegen-sandbox-client/blob/05b52ee7f63e3ed6d8e9230db04bb7b57eb75cd3/codegen.yml" rel="noopener noreferrer"&gt;&lt;code&gt;graphql-codegen&lt;/code&gt; config&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/ayumitamai97/cont-codegen-sandbox-api/blob/d2b8be0879e81a20309dd10094b2af1444e6f6c6/.github/workflows/dispatch_graphql_schema_update.yml" rel="noopener noreferrer"&gt;Notify client-side repo when GraphQL schema is updated&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/ayumitamai97/cont-codegen-sandbox-client/blob/c6590aaeafbfb003f93e5d5d431efafef5556674/.github/workflows/graphql_schema_updated.yml" rel="noopener noreferrer"&gt;Execute &lt;code&gt;graphql-codegen&lt;/code&gt; and create Pull Request&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/ayumitamai97/cont-codegen-sandbox-client/blob/95d7606dca926c2e78ddca15c2f40d5a512fc039/.github/workflows/automerge.yml" rel="noopener noreferrer"&gt;Automerge Pull Request&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Link to the example Pull Request
&lt;/h3&gt;

&lt;p&gt;You can see the actual Pull Request created in the workflow here &lt;a href="https://github.com/ayumitamai97/cont-codegen-sandbox-client/pull/36" rel="noopener noreferrer"&gt;ayumitamai97/cont-codegen-sandbox-client#36&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note that if you use &lt;code&gt;GITHUB_TOKEN&lt;/code&gt; for &lt;code&gt;Create Pull Request&lt;/code&gt; step, the committer will be "github-actions (bot)" instead of your account.&lt;/p&gt;

&lt;p&gt;If this post is helpful, or you know better ways to do these things, please don't hesitate to leave a comment. Thank you for reading! 👾&lt;/p&gt;

&lt;p&gt;Japanese version: &lt;a href="https://ayumitamai97.medium.com/continuously-generate-typescript-typings-from-graphql-schema-across-multiple-repositories-ja-fdb2c99c7f1c" rel="noopener noreferrer"&gt;GraphQL スキーマの変更を検知し、TypeScript の型定義を自動的に生成する仕組み | Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>typescript</category>
      <category>github</category>
    </item>
  </channel>
</rss>
