graphqlgithub-api-v4

Github Graphql API create repo


I am using below query to create repo:

   gh api -i graphql -f query='
   mutation {
   createRepository(input: {name: "gh-create-test", visibility: PRIVATE, ownerId: "ID"}) {
    repository {
      url
    }
  }
}
'

THe repo gets created successfully but without admin rights whereas when I create repo from GITHUB UI the repo has admin rights. Can anyone please help what's the issue in this query?


Solution

  • I just created one, Make sure you are getting the id first and pass it to the createRepository

    query{
      repositoryOwner(login:"yourLoginId"){
        id
        login
        repositories(first:1) {
          edges {
            node {
              id
            }
          }
        }
      }
    }
    

    and create a repository by passing the ownerid

    mutation {
       createRepository(input: {name: "gh-create-test", visibility: PRIVATE, ownerId: "idobtainedabove"}) {
        repository {
          url
        }
      }
    }