{"id":5215,"date":"2024-03-25T11:11:10","date_gmt":"2024-03-25T11:11:10","guid":{"rendered":"https:\/\/gitprotect.io\/blog\/?p=5215"},"modified":"2024-03-25T11:11:11","modified_gmt":"2024-03-25T11:11:11","slug":"optimizing-github-actions-with-github-graphql-api","status":"publish","type":"post","link":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/","title":{"rendered":"Optimizing GitHub Actions with GitHub GraphQL API"},"content":{"rendered":"\n<p>GitHub Actions and the GitHub GraphQL API are powerful tools for automating and optimizing workflows. GitHub Actions, released in 2018 brings CI\/CD directly into the GitHub ecosystem and automates general project management using YAML files. Whereas, a 2-year earlier-released GraphQL API provides a more efficient way to fetch and manipulate data.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>In this article we will examine how combining these technologies may simplify development processes, making them more efficient as well as customized to specific requirements. While we explore how to optimize GitHub Actions with GraphQL, we will also focus on the importance of automation efficiency to guarantee every workflow is as effective as possible.<\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Let&#8217;s analyze GraphQL API<\/h2>\n\n\n\n<p>GraphQL, which was developed by Facebook and adopted by GitHub in 2016, represents a major change in how developers query and manipulate data. Moreover, GitHub was among the first major platforms to offer a public GraphQL API, which just shows its early support for the technology.<\/p>\n\n\n\n<p>Unlike traditional REST APIs, which frequently return a comprehensive set of data, GraphQL allows developers to request only what they need. This targeted approach to data retrieval significantly reduces response payload, which improves web application and service performance.<\/p>\n\n\n\n<p>To understand the efficiency of GraphQL better, consider a database containing customer records. A typical customer entry, in a RESTful service, might look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"Customer\": {\n\n  \"id\": \"101010\",\n\n  \"first_name\": \"Jack\",\n\n  \"last_name\": \"Kowalski\",\n\n  \"email\": \"fake_jackkowalski@gmail.com\",\n\n  \"City\": \"Chicago\",\n\n  \"State\": \"Illinois\"\n\n  ...\n\n}<\/code><\/pre>\n\n\n\n<p>If the objective is to personalize a greeting with the customer&#8217;s first name, a REST get request would return the entire customer record, including unneeded data. This is where GraphQL shines. With GraphQL, you can construct a query to fetch only the desired information:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>query FindCustomerFirstName {\n  customer(id: \"101010\") {\n    first_name\n  }\n}<\/code><\/pre>\n\n\n\n<p>Applying this to the GitHub GraphQL API, you should also consider a scenario where you need the ID of a specific repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>query FindRepoID {\n  repository(owner:\"YOUR_ORGANIZATION_NAME\", name:\"REPOSITORY_NAME\") {\n    id\n  }\n}<\/code><\/pre>\n\n\n\n<p>This query efficiently retrieves just the repository&#8217;s ID, despite the repository object containing numerous other fields, potentially over a hundred. The response to such a query would be succinct and focused:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"data\": {\n    \"repository\": {\n      \"id\": \"R_ktHp3iGA\"\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p>In the context of GitHub Actions, this means that workflows can interact with GitHub data, requesting only what is necessary for each stage of the process. For example, an action may utilize a GraphQL query to determine the status of a pull request or issue, and then make decisions based on that information, such as launching a deployment or sending a message. This exact data fetching with GraphQL not only improves the efficiency of GitHub Actions, but also matches with the goal of developing efficient, responsive, and resource-conscious CI\/CD pipelines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Setting up GitHub GraphQL API with GitHub Actions<\/strong><\/h2>\n\n\n\n<p>Integrating the GitHub GraphQL API with GitHub Actions enables developers to automate and optimize workflows with unmatched precision and efficiency. This configuration entails authenticating requests, constructing GraphQL queries, and managing replies using GitHub Actions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Authenticating with a personal access token<\/h3>\n\n\n\n<p>Generate a Personal Access Token (PAT):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigate to your GitHub settings.<\/li>\n\n\n\n<li>Go to the Developer settings \u2192 Personal access tokens \u2192 Generate new token.<\/li>\n\n\n\n<li>Select the scopes or permissions you need for your GraphQL queries. For most applications involving repository data, <strong><em>repo <\/em><\/strong>scope suffices.<\/li>\n\n\n\n<li>Generate the token and make sure to copy it; GitHub will not show it again.<\/li>\n<\/ul>\n\n\n\n<p>Store your PAT in GitHub Actions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In your repository, go to Settings \u2192 Secrets.<\/li>\n\n\n\n<li>Click on &#8220;New repository secret.&#8221;<\/li>\n\n\n\n<li>Name your secret (e.g., <strong><em>GH_GRAPHQL_TOKEN<\/em><\/strong>) and paste your Personal Access Token.<\/li>\n\n\n\n<li>Your token is now securely stored and can be referenced in your GitHub Actions workflows.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Sample GraphQL Query<\/h3>\n\n\n\n<p>To use the GitHub GraphQL API within a GitHub Action, you&#8217;ll need to craft a GraphQL query. For example, to fetch the ID of a repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>query {\n  repository(owner:\"OWNER_NAME\", name:\"REPO_NAME\") {\n    id\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Incorporate the Query in GitHub Actions<\/h3>\n\n\n\n<p>Here\u2019s how to use the above query within a GitHub Action workflow:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create a workflow file:<\/strong>\n<ul class=\"wp-block-list\">\n<li>In your repository, navigate to the <strong><em>.github\/workflows<\/em><\/strong> directory.<\/li>\n\n\n\n<li>Create a new YAML file for your workflow (e.g., <strong><em>graphql_query.yml<\/em><\/strong>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Define your workflow:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Start with the basic structure of a workflow, specifying the name and the trigger event.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>name: Fetch Repository ID\non: &#091;push]\n\njobs:\n  fetch-repo-id:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Query GitHub GraphQL API\n        id: fetch_data\n        uses: actions\/github-script@v5\n        with:\n          github-token: ${{ secrets.GH_GRAPHQL_TOKEN }}\n          script: |\n            const query = `\n              query {\n                repository(owner:\"OWNER_NAME\", name:\"REPO_NAME\") {\n                  id\n                }\n              }`;\n            const response = await github.graphql(query);\n            return response.repository.id;\n        env:\n          GH_GRAPHQL_TOKEN: ${{ secrets.GH_GRAPHQL_TOKEN }}<\/code><\/pre>\n\n\n\n<p>Use the output of the GraphQL query in subsequent steps of your workflow. For example, you can echo the repository ID or use it in further automation logic.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      - name: Output Repository ID\n        run: echo \"The Repository ID is ${{ steps.fetch_data.outputs.result }}\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Advanced GraphQL Queries for GitHub Actions<\/strong><\/h2>\n\n\n\n<p>Optimizing GitHub Actions workflows involves more than automating tasks. One of the key strengths of the GitHub GraphQL API is its ability to fetch exactly what&#8217;s needed in a single request, as opposed to making multiple calls to a REST API. This capability can significantly reduce the computational load and speed up the execution of GitHub Actions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reduce API calls<\/h3>\n\n\n\n<p>Every API call&nbsp;in a GitHub Action can add&nbsp;delay&nbsp;and increase the likelihood of exceeding rate limits. By using advanced GraphQL queries, you may combine numerous REST API calls into a single GraphQL call. For example, rather than making multiple REST API calls to collect the data, comments, and status of a pull request, a single GraphQL query can do so all at once.<\/p>\n\n\n\n<p><strong>Example: Fetching Pull Request details<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>query {\n  repository(owner: \"OWNER_NAME\", name: \"REPO_NAME\") {\n    pullRequest(number: 123) {\n      title\n      body\n      comments(first: 5) {\n        nodes {\n          body\n        }\n      }\n      merged\n      mergeable\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Precisely fetch data<\/h3>\n\n\n\n<p>The specificity of GraphQL is not just about efficiency; it&#8217;s also about getting precisely what your workflow needs to make decisions or perform actions. This precision prevents your GitHub Actions from downloading and processing unnecessary data, thus optimizing performance.<\/p>\n\n\n\n<p><strong>Example: Conditional workflow execution<\/strong><\/p>\n\n\n\n<p>Imagine a workflow that should only proceed if certain conditions are met, such as a pull request being labeled with &#8220;review needed&#8221;. A GraphQL query can check for this condition by fetching only the labels of a pull request:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>query {\n  repository(owner: \"OWNER_NAME\", name: \"REPO_NAME\") {\n    pullRequest(number: 123) {\n      labels(first: 10) {\n        nodes {\n          name\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Best practices<\/h3>\n\n\n\n<p>When working with lists (e.g., comments, issues), use GraphQL&#8217;s <strong>pagination<\/strong> features to limit the amount of data returned in a single query.<\/p>\n\n\n\n<p>Be mindful of GitHub&#8217;s rate limits. Advanced queries, while efficient, can quickly consume your rate limit if not optimized. Use the <strong><em>rateLimit <\/em><\/strong>field to monitor your usage.<\/p>\n\n\n\n<p>It&#8217;s important to regularly <strong>review and optimize your queries<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Authenticating with the GitHub App<\/h2>\n\n\n\n<p>When automating and optimizing workflows with GitHub Actions and the GraphQL API, using a GitHub App for authentication offers several distinct advantages over personal access tokens (PATs). GitHub Apps provide a more secure and flexible way to interact with GitHub&#8217;s ecosystem, making them ideal for complex automation tasks.<\/p>\n\n\n\n<p><strong>Benefits of GitHub App authentication:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Granular permissions<\/strong>: GitHub Apps allow for more precise control over permissions than PATs. You can specify exactly what actions your app can perform, reducing security risks by sticking to the principle of least privilege.<\/li>\n\n\n\n<li><strong>Better security<\/strong>: Authentication via a GitHub App uses a dynamic installation access token, which changes periodically, offering better security compared to a static PAT. This token reduces the risk if a token were ever to be compromised.<\/li>\n\n\n\n<li><strong>Per-repository installation<\/strong>: GitHub Apps can be installed on individual repositories or across an entire organization, providing flexibility in scope and application. This means actions can be tailored and restricted to specific repositories, further enhancing security and efficiency.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How to set up GitHub App<\/h3>\n\n\n\n<p>Go to your GitHub account or organization settings, find the GitHub Apps section under Developer settings, and click on &#8220;New GitHub App&#8221;. Then, configure your app&#8217;s name, description, and permissions based on the needs of your GitHub Actions. For GraphQL queries, set the necessary read and possibly write permissions.<\/p>\n\n\n\n<p>Specify a Webhook URL if required (not necessary for GitHub Actions), and complete the app creation process. Once the app is created, install it on the repositories where your GitHub Actions will run. This step applies the permissions you&#8217;ve configured to the repositories selected<\/p>\n\n\n\n<p>Use the App&#8217;s installation access token for authentication in your GitHub Actions workflows. GitHub provides an API endpoint to generate these tokens, which can be requested within a workflow run.<\/p>\n\n\n\n<p><strong>Example: Authenticating a GraphQL Query<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name: Use GraphQL with GitHub App Auth\non: &#091;push]\n\njobs:\n  example-job:\n    runs-on: ubuntu-latest\n    steps:\n    - name: Generate token\n      id: generate_token\n      run: |\n        TOKEN=$(curl -X POST \\\n        -H \"Authorization: Bearer YOUR_APP_JWT\" \\\n        -H \"Accept: application\/vnd.github.v3+json\" \\\n        https:\/\/api.github.com\/app\/installations\/YOUR_INSTALLATION_ID\/access_tokens | jq -r '.token')\n        echo \"::set-output name=token::$TOKEN\"\n    - name: Run GraphQL Query\n      run: |\n        curl -H \"Authorization: Bearer ${{ steps.generate_token.outputs.token }}\" \\\n        -X POST -d '{\"query\":\"query { viewer { login }}\"}' \\\n        https:&#47;&#47;api.github.com\/graphql<\/code><\/pre>\n\n\n\n<p>This example demonstrates generating an installation access token for the GitHub App and using it to authenticate a GraphQL query within a GitHub Action. Adjust the <strong><em>YOUR_APP_JWT <\/em><\/strong>and <strong><em>YOUR_INSTALLATION_ID <\/em><\/strong>placeholders to match your GitHub App&#8217;s credentials and installation ID.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using GraphQL.js<\/h2>\n\n\n\n<p>Integrating GraphQL.js with GitHub Actions expands the possibilities for querying and manipulating data directly within automation scripts. GraphQL.js, the official JavaScript reference implementation for GraphQL, makes it easy to create complicated queries and mutations, allowing for dynamic and powerful interactions with the GitHub GraphQL API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Set up GraphQL.js<\/h3>\n\n\n\n<p>To use GraphQL.js in a GitHub Action, you typically need a Node.js environment. While GitHub Actions run in a variety of environments, most custom scripts that leverage GraphQL.js will be executed in a Node.js setup. Here&#8217;s a streamlined approach to getting started:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Make sure your GitHub Action workflow initiates a Node.js environment. This can be achieved by using a setup-node action at the beginning of your workflow.<\/li>\n\n\n\n<li>Use npm or yarn to install GraphQL.js. This can be done within your workflow file or as part of a project dependency if you&#8217;re running a custom script.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: Install Dependencies\n  run: npm install graphql<\/code><\/pre>\n\n\n\n<p><strong>Example of a use case: Fetching repository information<\/strong><\/p>\n\n\n\n<p>Here\u2019s how you might use GraphQL.js to fetch detailed information about issues within a repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const { graphql, buildSchema } = require('graphql');\n\n\/\/ Define your schema and resolver\nconst schema = buildSchema(`\n  type Query {\n    repository(owner: String!, name: String!): Repository\n  }\n  type Repository {\n    issues(labels: &#091;String], first: Int): IssueConnection\n  }\n  type IssueConnection {\n    edges: &#091;IssueEdge]\n  }\n  type IssueEdge {\n    node: Issue\n  }\n  type Issue {\n    title: String\n    body: String\n    createdAt: String\n  }\n`);\n\n\/\/ The root provides the top-level API endpoints\nconst root = {\n  repository: () =&gt; {\n    \/\/ Mocked data, replace with actual GraphQL query execution\n    return { \/* repository data *\/ };\n  },\n};\n\n\/\/ Sample query\nconst query = `\n  {\n    repository(owner: \"OWNER_NAME\", name: \"REPO_NAME\") {\n      issues(labels: &#091;\"bug\"], first: 5) {\n        edges {\n          node {\n            title\n            body\n            createdAt\n          }\n        }\n      }\n    }\n  }\n`;\n\n\/\/ Execute the query\ngraphql(schema, query, root).then((response) =&gt; {\n  console.log(response);\n});<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Mutations in GraphQL<\/strong><\/h2>\n\n\n\n<p>Mutations in GraphQL allow for the creation, modification, and deletion of data. In terms of GitHub Actions, mutations enable you to automate actions such as merging pull requests, creating issues, or updating repository content.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>The GraphQL Endpoint<\/strong><\/h3>\n\n\n\n<p>All interactions with the GitHub GraphQL API occur through a single HTTP endpoint. Understanding how to make requests to this endpoint is crucial for both queries and mutations.<\/p>\n\n\n\n<p><strong>Endpoint details:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>URL<\/strong>: <strong>https:\/\/api.github.com\/graphql<\/strong><\/li>\n\n\n\n<li><strong>Authentication<\/strong>: Requires an OAuth token or GitHub App installation token for access.<\/li>\n\n\n\n<li><strong>Request structure<\/strong>: All GraphQL operations are sent as POST requests with the query included in the body.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example Query: Fetching issue labels<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>query {\n  repository(owner: \"OWNER_NAME\", name: \"REPO_NAME\") {\n    issue(number: 1) {\n      labels(first: 5) {\n        nodes {\n          name\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p>This query can be used within a GitHub Action to determine how to proceed based on the labels attached to an issue.<\/p>\n\n\n\n<p><strong>Example mutation: Closing an issue<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mutation {\n  closeIssue(input: {issueId: \"ISSUE_ID\"}) {\n    issue {\n      state\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p>Integrate this mutation into a GitHub Action to automatically close issues that meet certain criteria, such as all associated tasks being completed.<\/p>\n\n\n\n<p><strong>Implementing in GitHub Actions:<\/strong><\/p>\n\n\n\n<p>Make sure your GitHub Action has access to a token with the necessary permissions.<\/p>\n\n\n\n<p>Then, process the data returned from queries and mutations to control the flow of your GitHub Actions, such as conditional logic based on query results or confirmation of mutation success.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The integration of GitHub Actions and the GraphQL API provides significant improvements to development workflows, including precise automation and optimization capabilities. As we use these tools to streamline processes, it&#8217;s critical to remember the value of protecting our workflows. Implementing <a href=\"https:\/\/gitprotect.io\/blog\/github-backup-best-practices\/\">GitHub backup best practices<\/a> and using such backup and Disaster Recovery tools like GitProtect.io guarantees the resilience of our CI\/CD pipelines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Before you go:&nbsp;<\/h2>\n\n\n\n<p class=\"has-background\" style=\"background-color:#f4fafe\">\ud83d\udcda Learn more about <a href=\"https:\/\/gitprotect.io\/blog\/github-ci-cd-the-beginners-guide\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub CI\/CD<\/a> to automate and deliver your software faster<br><br>\ud83d\udd0e Find out top reasons <a href=\"https:\/\/gitprotect.io\/blog\/why-back-up-devops-tools-what-is-worth-remembering\/\" target=\"_blank\" rel=\"noreferrer noopener\">why it&#8217;s critical to back up your GitHub environment<\/a><br><br>\u270d\ufe0f Subscribe to <a href=\"https:\/\/gitprotect.io\/gitprotect-newsletter.html?utm_source=blog&amp;utm_medium=blog\" target=\"_blank\" rel=\"noreferrer noopener\"><u>GitProtect DevSecOps X-Ray Newsletter<\/u><\/a> and always stay up-to-date with the latest DevSecOps insights<br><br>\ud83d\udccc Try <a href=\"https:\/\/gitprotect.io\/sign-up.html?utm_source=blog&amp;utm_medium=blog\" target=\"_blank\" rel=\"noreferrer noopener\"><u>GitProtect backups for your GitHub environment<\/u><\/a> and start protecting your source code immediately<br><br>\ud83d\udcc5 Schedule <a href=\"https:\/\/calendly.com\/d\/3s9-n9z-pgc\/gitprotect-live-demo?month=2024-03\" target=\"_blank\" rel=\"noreferrer noopener\"><u>a live custom demo<\/u><\/a> and learn more about GitProtect backups for your GitHub repositories and metadata<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GitHub Actions and the GitHub GraphQL API are powerful tools for automating and optimizing workflows. GitHub Actions, released in 2018 brings CI\/CD directly into the GitHub ecosystem and automates general project management using YAML files. Whereas, a 2-year earlier-released GraphQL API provides a more efficient way to fetch and manipulate data.<\/p>\n","protected":false},"author":12,"featured_media":5216,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-5215","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git-backup-101","post--single"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Optimizing GitHub Actions with GitHub GraphQL API - Blog | GitProtect.io<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Optimizing GitHub Actions with GitHub GraphQL API - Blog | GitProtect.io\" \/>\n<meta property=\"og:description\" content=\"GitHub Actions and the GitHub GraphQL API are powerful tools for automating and optimizing workflows. GitHub Actions, released in 2018 brings CI\/CD directly into the GitHub ecosystem and automates general project management using YAML files. Whereas, a 2-year earlier-released GraphQL API provides a more efficient way to fetch and manipulate data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog | GitProtect.io\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/XoperoSoftware\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-25T11:11:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-25T11:11:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GitProtectio\" \/>\n<meta name=\"twitter:site\" content=\"@GitProtectio\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/\"},\"author\":{\"name\":\"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io\",\"@id\":\"https:\/\/gitprotect.io\/blog\/#\/schema\/person\/3404d5bf8d1a1c26abb51a4c2cacbc05\"},\"headline\":\"Optimizing GitHub Actions with GitHub GraphQL API\",\"datePublished\":\"2024-03-25T11:11:10+00:00\",\"dateModified\":\"2024-03-25T11:11:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/\"},\"wordCount\":1839,\"publisher\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png\",\"articleSection\":[\"Git Backup 101\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/\",\"url\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/\",\"name\":\"Optimizing GitHub Actions with GitHub GraphQL API - Blog | GitProtect.io\",\"isPartOf\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png\",\"datePublished\":\"2024-03-25T11:11:10+00:00\",\"dateModified\":\"2024-03-25T11:11:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage\",\"url\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png\",\"contentUrl\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png\",\"width\":1200,\"height\":600},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Strona g\u0142\u00f3wna\",\"item\":\"https:\/\/gitprotect.io\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Optimizing GitHub Actions with GitHub GraphQL API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/gitprotect.io\/blog\/#website\",\"url\":\"https:\/\/gitprotect.io\/blog\/\",\"name\":\"GitProtect.io Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/gitprotect.io\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/gitprotect.io\/blog\/#organization\",\"name\":\"GitProtect.io\",\"url\":\"https:\/\/gitprotect.io\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gitprotect.io\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/05\/favicon-528x528-1.png\",\"contentUrl\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/05\/favicon-528x528-1.png\",\"width\":528,\"height\":528,\"caption\":\"GitProtect.io\"},\"image\":{\"@id\":\"https:\/\/gitprotect.io\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/XoperoSoftware\/\",\"https:\/\/x.com\/GitProtectio\",\"https:\/\/www.linkedin.com\/company\/xopero-software\/\",\"https:\/\/www.youtube.com\/channel\/UCiEnl6n0mIO6w7twccz-l2w\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/gitprotect.io\/blog\/#\/schema\/person\/3404d5bf8d1a1c26abb51a4c2cacbc05\",\"name\":\"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gitprotect.io\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/08\/milosz-jesis-technical-content-writer-at-gitprotect.io_avatar-96x96.png\",\"contentUrl\":\"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/08\/milosz-jesis-technical-content-writer-at-gitprotect.io_avatar-96x96.png\",\"caption\":\"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io\"},\"description\":\"Milosz is Technical Content Writer at GitProtect, demonstrating fluency in both Polish and English, and a passion for language and technology. Currently pursuing a degree in Philosophy at UWE Bristol, he excels in creating engaging technical content that bridges the gap between users and the emerging technologies. Milosz leverages his writing skills and technical knowledge to author articles and blog posts, with a focus on DevOps, cyber-security, and potential cyber-threats, among other crucial IT topics. Additionally, valuable translations provided by Milosz further enhance GitProtect's communication and global outreach.\",\"url\":\"https:\/\/gitprotect.io\/blog\/author\/milosz-jesis\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Optimizing GitHub Actions with GitHub GraphQL API - Blog | GitProtect.io","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/","og_locale":"en_US","og_type":"article","og_title":"Optimizing GitHub Actions with GitHub GraphQL API - Blog | GitProtect.io","og_description":"GitHub Actions and the GitHub GraphQL API are powerful tools for automating and optimizing workflows. GitHub Actions, released in 2018 brings CI\/CD directly into the GitHub ecosystem and automates general project management using YAML files. Whereas, a 2-year earlier-released GraphQL API provides a more efficient way to fetch and manipulate data.","og_url":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/","og_site_name":"Blog | GitProtect.io","article_publisher":"https:\/\/www.facebook.com\/XoperoSoftware\/","article_published_time":"2024-03-25T11:11:10+00:00","article_modified_time":"2024-03-25T11:11:11+00:00","og_image":[{"width":1200,"height":600,"url":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png","type":"image\/png"}],"author":"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io","twitter_card":"summary_large_image","twitter_creator":"@GitProtectio","twitter_site":"@GitProtectio","twitter_misc":{"Written by":"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#article","isPartOf":{"@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/"},"author":{"name":"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io","@id":"https:\/\/gitprotect.io\/blog\/#\/schema\/person\/3404d5bf8d1a1c26abb51a4c2cacbc05"},"headline":"Optimizing GitHub Actions with GitHub GraphQL API","datePublished":"2024-03-25T11:11:10+00:00","dateModified":"2024-03-25T11:11:11+00:00","mainEntityOfPage":{"@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/"},"wordCount":1839,"publisher":{"@id":"https:\/\/gitprotect.io\/blog\/#organization"},"image":{"@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage"},"thumbnailUrl":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png","articleSection":["Git Backup 101"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/","url":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/","name":"Optimizing GitHub Actions with GitHub GraphQL API - Blog | GitProtect.io","isPartOf":{"@id":"https:\/\/gitprotect.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage"},"image":{"@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage"},"thumbnailUrl":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png","datePublished":"2024-03-25T11:11:10+00:00","dateModified":"2024-03-25T11:11:11+00:00","breadcrumb":{"@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#primaryimage","url":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png","contentUrl":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2024\/03\/GitHub-and-GraphQL-1.png","width":1200,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/gitprotect.io\/blog\/optimizing-github-actions-with-github-graphql-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Strona g\u0142\u00f3wna","item":"https:\/\/gitprotect.io\/blog\/"},{"@type":"ListItem","position":2,"name":"Optimizing GitHub Actions with GitHub GraphQL API"}]},{"@type":"WebSite","@id":"https:\/\/gitprotect.io\/blog\/#website","url":"https:\/\/gitprotect.io\/blog\/","name":"GitProtect.io Blog","description":"","publisher":{"@id":"https:\/\/gitprotect.io\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gitprotect.io\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/gitprotect.io\/blog\/#organization","name":"GitProtect.io","url":"https:\/\/gitprotect.io\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gitprotect.io\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/05\/favicon-528x528-1.png","contentUrl":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/05\/favicon-528x528-1.png","width":528,"height":528,"caption":"GitProtect.io"},"image":{"@id":"https:\/\/gitprotect.io\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/XoperoSoftware\/","https:\/\/x.com\/GitProtectio","https:\/\/www.linkedin.com\/company\/xopero-software\/","https:\/\/www.youtube.com\/channel\/UCiEnl6n0mIO6w7twccz-l2w"]},{"@type":"Person","@id":"https:\/\/gitprotect.io\/blog\/#\/schema\/person\/3404d5bf8d1a1c26abb51a4c2cacbc05","name":"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gitprotect.io\/blog\/#\/schema\/person\/image\/","url":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/08\/milosz-jesis-technical-content-writer-at-gitprotect.io_avatar-96x96.png","contentUrl":"https:\/\/gitprotect.io\/blog\/wp-content\/uploads\/2023\/08\/milosz-jesis-technical-content-writer-at-gitprotect.io_avatar-96x96.png","caption":"Mi\u0142osz Jesis, Technical Content Writer at GitProtect.io"},"description":"Milosz is Technical Content Writer at GitProtect, demonstrating fluency in both Polish and English, and a passion for language and technology. Currently pursuing a degree in Philosophy at UWE Bristol, he excels in creating engaging technical content that bridges the gap between users and the emerging technologies. Milosz leverages his writing skills and technical knowledge to author articles and blog posts, with a focus on DevOps, cyber-security, and potential cyber-threats, among other crucial IT topics. Additionally, valuable translations provided by Milosz further enhance GitProtect's communication and global outreach.","url":"https:\/\/gitprotect.io\/blog\/author\/milosz-jesis\/"}]}},"_links":{"self":[{"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/posts\/5215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/comments?post=5215"}],"version-history":[{"count":1,"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/posts\/5215\/revisions"}],"predecessor-version":[{"id":5217,"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/posts\/5215\/revisions\/5217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/media\/5216"}],"wp:attachment":[{"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/media?parent=5215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/categories?post=5215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gitprotect.io\/blog\/wp-json\/wp\/v2\/tags?post=5215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}