GraphQL API returns invalid JSON for rawBlob response

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

When requesting a raw binary file via the GraphQL API RepositoryBlob.rawBlob endpoint, invalid JSON is returned.

Steps to reproduce

  1. Add a raw binary file to a repository
  2. Request the rawBlob for the path to that file via the GraphQL API (see example query below)

Example Project

https://gitlab.com/irowebbn/sandbox

You can try the following queries in GraphQL explorer

Query:

query ($project_path: ID!, $branch: String, $file_paths: [String!]!) {
  project(fullPath: $project_path) {
    repository {
      blobs(ref: $branch, paths: $file_paths) {
        nodes {
          rawBlob
        }
      }
    }
  }
}

Query variables

{
  "project_path": "irowebbn/sandbox",
  "branch": "main",
  "file_paths": [
    "small_test_file"
  ]
}

Note that requesting README.md has no issues, but both small_test_file and large_test_file do.

What is the current bug behavior?

Using curl, I see a 500 Internal Server error or a 502 bad Gateway error. Using GraphQL explorer, I get

{
  "message": "Unexpected token < in JSON at position 0",
  "stack": "SyntaxError: Unexpected token < in JSON at position 0"
}

What is the expected correct behavior?

Expect to see a base64-encoded string with the file contents, or if such an encoding is not supported by the GitLab API, a more specific response code.

{
  "data": {
    "project": {
      "repository": {
        "blobs": {
          "nodes": [
            {
              "rawBlob": "[file content]"
            }
          ]
        }
      }
    }
  }
}

Relevant logs and/or screenshots

Output of checks

This bug happens on GitLab.com

Possible fixes

Edited by 🤖 GitLab Bot 🤖