• Stars
    star
    114
  • Rank 297,138 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A GitHub Action to send queries to GitHub's GraphQL API

Octokit Request Action

A GitHub Action to send queries to GitHub's GraphQL API

Build Status

Usage

Minimal example

name: Log latest release
on:
  push:
    branches:
      - main

jobs:
  logLatestRelease:
    runs-on: ubuntu-latest
    steps:
      - uses: octokit/[email protected]
        id: get_latest_release
        with:
          query: |
            query release($owner:String!,$repo:String!) {
              repository(owner:$owner,name:$repo) {
                releases(first:1) {
                  nodes {
                    name
                    createdAt
                    tagName
                    description
                  }
                }
              }
            }
          owner: ${{ github.event.repository.owner.name }}
          repo: ${{ github.event.repository.name }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - run: "echo 'latest release: ${{ steps.get_latest_release.outputs.data }}'"

You can also use the variables parameter to pass variables.

- uses: octokit/[email protected]
  with:
    query: |
      query release($owner:String!,$repo:String!) {
        repository(owner:$owner,name:$repo) {
          releases(first:1) {
            nodes {
              name
              createdAt
              tagName
              description
            }
          }
        }
      }
    variables: |
      owner: ${{ github.event.repository.owner.name }}
      repo: ${{ github.event.repository.name }}
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

To access deep values of outputs.data, use fromJSON().

Debugging

To see additional debug logs, create a secret with the name: ACTIONS_STEP_DEBUG and value true.

How it works

octokit/graphql-action is using @octokit/graphql internally with the addition that requests are automatically authenticated using the GITHUB_TOKEN environment variable. It is required to prevent rate limiting, as all anonymous requests from the same origin count against the same low rate.

The actions sets data output to the response data. Note that it is a string, you should use fromJSON() to access any value of the response. The action also sets headers (again, to a JSON string) and status.

Preview Media Types

New features of graphql require the use of an Accept header with a preview media-type. This is supported with a mediaType property, e.g.

steps:
  - uses: octokit/[email protected]
    with:
      query: |
        query  pullRequest(
          $repo:String!
          $owner:String!) {
          repository(name:$repo, owner:$owner) { 
            pullRequests(last:1) {
              nodes {
                number
                mergeStateStatus
              }
            }
          }
        }
      owner: ${{ github.event.repository.owner.name }}
      repo: ${{ github.event.repository.name }}
      mediaType: |
        previews:
        - merge-info

Troubleshooting

Input variables

It's important to remark input variables are converted to lowercase at runtime. This happens with GitHub Actions by design1.

Example

In the following example, the variable itemId is casted to itemid so, when trying to use it in the query, the execution will fail because of a missing variable: itemId

query release($itemId: String!) {
  ...

# Fails with "Error: Variable $itemId of type String! was provided invalid value"
itemId: "randomId"

The recommendation1 is to use variables in lowercase to avoid this kind of problems:

# The variable name must be lower-case:
query release($itemid: String!) {
  ...

# Both: in the query and action var declaration:
itemid: "randomId"

License

MIT

Footnotes

  1. https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs ↩ ↩2

More Repositories

1

octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
TypeScript
6,695
star
2

octokit.rb

Ruby toolkit for the GitHub API
Ruby
3,818
star
3

octokit.net

A GitHub API client library for .NET
C#
2,591
star
4

octokit.objc

GitHub API client for Objective-C
Objective-C
1,841
star
5

core.js

Extendable client for GitHub's REST & GraphQL APIs
TypeScript
1,145
star
6

rest.js

GitHub REST API client for JavaScript
JavaScript
503
star
7

graphql.js

GitHub GraphQL API client for browsers and Node
TypeScript
446
star
8

request-action

A GitHub Action to send arbitrary requests to GitHub's REST API
JavaScript
350
star
9

authentication-strategies.js

GitHub API authentication strategies for Browsers, Node.js, and Deno
320
star
10

webhooks.js

GitHub webhook events toolset for Node.js
TypeScript
296
star
11

go-octokit

Simple Go wrapper for the GitHub API
Go
257
star
12

request.js

Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node
TypeScript
223
star
13

webhooks

machine-readable, always up-to-date GitHub Webhooks specifications
TypeScript
202
star
14

action.js

GitHub API client for GitHub Actions
TypeScript
173
star
15

graphql-schema

GitHub’s GraphQL Schema with validation. Automatically updated.
JavaScript
170
star
16

app.js

GitHub Apps toolset for Node.js
TypeScript
149
star
17

auth-app.js

GitHub App authentication for JavaScript
TypeScript
142
star
18

octokit.graphql.net

A GitHub GraphQL client library for .NET
C#
140
star
19

types.ts

Shared TypeScript definitions for Octokit projects
TypeScript
113
star
20

plugin-throttling.js

Octokit plugin for GitHub’s recommended request throttling
TypeScript
100
star
21

plugin-rest-endpoint-methods.js

Octokit plugin adding one method for all of api.github.com REST API endpoints
TypeScript
100
star
22

fixtures

Fixtures for all the octokittens
JavaScript
98
star
23

auth-token.js

GitHub API token authentication for browsers and Node.js
TypeScript
94
star
24

routes

machine-readable, always up-to-date GitHub REST API route specifications
JavaScript
84
star
25

oauth-app.js

GitHub OAuth toolset for Node.js
TypeScript
74
star
26

auth-oauth-app.js

GitHub OAuth App authentication for JavaScript
TypeScript
64
star
27

endpoint.js

Turns REST API endpoints into generic request options
TypeScript
54
star
28

go-sdk

A generated Go SDK from GitHub's OpenAPI specification.
Go
51
star
29

webhooks.net

GitHub webhook events toolset for .NET
C#
46
star
30

plugin-paginate-rest.js

Octokit plugin to paginate REST API endpoint responses
TypeScript
45
star
31

dotnet-sdk

C#
43
star
32

octopoller.rb

A micro gem for polling and retrying. Perfect for making repeating requests.
Ruby
43
star
33

auth-action.js

GitHub API token authentication for GitHub Actions
TypeScript
38
star
34

openapi

GitHub's official OpenAPI spec with Octokit extensions
JavaScript
38
star
35

openapi-types.ts

Generated TypeScript definitions based on GitHub's OpenAPI spec
JavaScript
37
star
36

plugin-paginate-graphql.js

Octokit plugin to paginate GraphQL Query responses
TypeScript
31
star
37

plugin-retry.js

Octokit plugin for GitHub’s recommended request retries
TypeScript
29
star
38

fixtures-server

Fixtures server for browser & language agnositic octokit testing
JavaScript
26
star
39

webhooks-methods.js

Methods to handle GitHub Webhook requests
TypeScript
20
star
40

plugin-enterprise-server.js

Octokit plugin for GitHub Enterprise REST APIs
TypeScript
19
star
41

octokit-next.js

JavaScript
18
star
42

oauth-authorization-url.js

Universal library to retrieve GitHub’s identity URL for the OAuth web flow
TypeScript
16
star
43

auth-oauth-user-client.js

OAuth user authentication without exposing client secret
15
star
44

create-octokit-project.js

"npm init" script to create a new Octokit JS module
JavaScript
15
star
45

auth-oauth-user.js

Octokit authentication strategy for OAuth clients
TypeScript
15
star
46

plugin-create-or-update-text-file.js

Convenience method to create/edit/delete a text file based on its current content
TypeScript
13
star
47

app-permissions

machine-readable, always up-to-date GitHub App permissions
JavaScript
10
star
48

auth-oauth-device.js

GitHub OAuth Device authentication strategy for JavaScript
TypeScript
10
star
49

request-error.js

Error class for Octokit request errors
TypeScript
9
star
50

handbook

Handbook for Octokit maintainers and GitHub integrators
9
star
51

auth-basic.js

GitHub API Basic authentication for browsers and Node.js
TypeScript
8
star
52

.github

7
star
53

discussions

discussions and planning for Octokit clients
7
star
54

plugin-request-log.js

Log all requests and request errors
TypeScript
7
star
55

source-generator

Go
6
star
56

plugin-enterprise-cloud.js

Octokit plugin for GitHub Enterprise Cloud REST APIs
TypeScript
6
star
57

tsconfig

TypeScript configuration for Octokit packages
JavaScript
5
star
58

oauth-methods.js

Request methods to create and refresh user access tokens for OAuth and GitHub Apps
TypeScript
4
star
59

auth-callback.js

GitHub API authentication using a callback method
TypeScript
4
star
60

auth-unauthenticated.js

strategy for explicitly unauthenticated Octokit instances
TypeScript
4
star
61

tf-acc-test-empty-f89p1

Terraform acceptance test f89p1
2
star
62

plugin-enterprise-compatibility.js

Octokit plugin for improving GHE compatibility
TypeScript
1
star
63

openapi-webhooks

JavaScript
1
star