Skip to content

gh api proposal: enable GraphQL operations without having to know GraphQL IDs #3549

Open

Description

@mislav

An example GraphQL mutation to add a label to the repository with the current version of GitHub CLI:

repoId="..."
labelId="..."

gh api graphql -f repoId="$repoId" -f labelId="labelId" -f query='
mutation($repoId:ID!,$labelId:ID!) {
  addLabelsToLabelable(input:{
    labelableId:$repoId
    labelIds:[$labelId]
  }) { clientMutationId }
}'

The problem is that the user typically needs to know GraphQL IDs of the objects they want to operate on. That means that every GraphQL mutation is usually preceded by a GraphQL query (or few) that gather these IDs. To have to do this via gh api every time is tedious.

This proposes a new syntax to be able to pass human-readable values to gh api and have it resolve them to GraphQL IDs internally:

gh api graphql -F repoId="id:cli/cli" -F labelId="id:help wanted" -f query='...'

I have actually no idea what the syntax for labels could be, but repositories would be identified by the typical owner/repo pair, users by @handle, teams like @org/team-slug, issues like owner/repo#123, etc.

Activity

  1. added
    core
    enhancement
    on Apr 30, 2021
  2. self-assigned this
    on Apr 30, 2021
  3. removed their assignment
    on Jun 9, 2023
  4. added
    gh-api
    on Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreenhancementgh-api

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions