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

1
  • Did you found the answer to your query?? I am looking for the answer as well. If yes, can you please help me out? Commented Jun 2, 2021 at 5:23

1 Answer 1

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
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.