2

I am attempting to read the raw contents of a specific file in my GitLab repository using the GraphQL API. Doing this with the REST Api is detailed here: https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository

Yet I can’t quite figure out how to do this with GraphQL. This is as far as I’ve gotten.

{
  project(fullPath: "BenSa/first-project") {
    repository {
      tree(ref: "master", recursive: true){
        blobs{
          nodes {
            name
            type
            flatPath
            sha
          }
        }
      }
    }
  }
}

The result of this query is:

{
"data": {
    "project": {
      "repository": {
        "tree": {
          "blobs": {
            "nodes": [
              {
                "name": "data.json",
                "type": "blob",
                "flatPath": "",
                "sha": "aa6f396f7a0e2c3163bc05c857539db89ade1a37"
              },
              {
                "name": "index.html",
                "type": "blob",
                "flatPath": "",
                "sha": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
              }
            ]
          }
        }
      }
    }
  }
}

Yet I want to access the raw contents of “data.json”. I have searched through the GraphQL schema for the word “raw” and only found references to snippets. The Blob type has a webUrl but not a rawUrl and besides I need the data coming from the GraphQL response if possible, not a separate fetch request. Any ideas?

Here is the GitLab GraphiQL link: https://gitlab.com/-/graphql-explorer

And the GraphQL Reference: https://docs.gitlab.com/ee/api/graphql/reference/

Thanks

Stib
  • 86
  • 1
  • 7
  • Did you found the answer to your query?? I am looking for the answer as well. If yes, can you please help me out? – Smile Kisan Jun 02 '21 at 05:23

1 Answers1

1

Your query should be like this instead:

query {
  project(fullPath: "BenSa/first-project") {
    repository {
      blobs(ref:"master", paths: ["data.json", "index.html"]) {
        nodes {
          rawBlob
        }
      }
    }
  }
}
Franck Rasolo
  • 539
  • 4
  • 9