An action that acts a client for GitHub's GraphQL API and can be chained. It means you can use a first instance to execute a GraphQL query and use its output to execute a GraphQL mutation.
Check a sample workflow and sample GraphqQL queries
Argument | Description |
---|---|
query | Query file path within the repo. Required |
output | The name of the file, relative to GITHUB_WORKSPACE , where the output will be stored. Defaults to github-graphql-action.json |
url | GraphQL endpoint URL. Defaults to https://api.github.com/graphql |
accept | Accept header to set in the query. Optional |
log | Set this argument to any value to enable logging to the console. Optional |
The query file contains the GraphQL query or mutation to execute. Format is YAML based.
query: '
query($owner:String!, $name:String!) {
repository(owner:$owner, name:$name) {
name
}
}'
variables:
owner: helaili
name: github-graphql-action
action "GraphQL query" {
uses = "./"
secrets = ["GITHUB_TOKEN"]
args = "--query .github/graphql_action/repository-static.query.yaml"
}
Variables values can also come from a command line argument.
query: '
query($owner:String!, $name:String!) {
repository(owner:$owner, name:$name) {
name
}
}'
variables:
owner:
type: arg
name: owner
name:
type: arg
name: name
action "GraphQL query" {
uses = "./"
secrets = ["GITHUB_TOKEN"]
args = "--query .github/graphql_action/repository-args.query.yaml --owner helaili --name hello-vue"
}
Variable values can also come from a file, typically event.json
which contains the event which triggered the action workflow (in ../workflow
) or an arbitrary file (relative to /github/workspace
) containing the result from a previous action (declared using the output
command line parameter). This file is then processed by a jq query in order to extract the scalar value needed for the GraphQL query.
You can optionally add a cast
parameter in order to convert the jq output to an Int
, Float
or Boolean
query:'
query($owner:String!, $name:String!) {
repository(owner:$owner, name:$name) {
name
}
}'
variables:
owner:
type: jq
file: ../workflow/event.json
query: '.repository.owner.login'
name:
type: jq
file: ../workflow/event.json
query: '.repository.name'
action "GraphQL query" {
uses = "./"
secrets = ["GITHUB_TOKEN"]
needs = "Repo Query Args"
args = "--query .github/graphql_action/repository-jq.query.yaml --log true"
}
query: '
mutation pinIssue($issueId: ID!){
pinIssue(input: { issueId: $issueId }) {
issue {
repository {
id
}
}
}
}'
variables:
issueId:
type: jq
file: ../workflow/event.json
query: '.issue.node_id'