Skip to content

Implement workhorse acceleration for graphql file uploads

We support file uploads in GraphQL but unfortunately, they don't get the benefits of workhorse disk acceleration (see https://gitlab.com/gitlab-org/gitlab-ce/issues/63097)

According to graphql multipart request specification this is a multipart/form-data upload that is aleady implemented in workhorse.

The plan

In order to take advantage of the acceleration,

  1. workhorse should provide is handler on /api/graphql - PoC gitlab-workhorse!403 (diffs)
  2. Gitlab::Middleware::Multipart must be executed before ApolloUploadServer::Middleware in order to handle workhorse upload acceleration. - gitlab-org/gitlab-ee!16461

Graphql file upload example

Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryHgU2DZfs5IjCF4TD

------WebKitFormBoundaryHgU2DZfs5IjCF4TD
Content-Disposition: form-data; name="operations"

{"operationName":"uploadDesign","variables":{"files":[null],"projectPath":"work/uploads","iid":"1"},"query":"mutation uploadDesign($files: [Upload!]!, $projectPath: ID!, $iid: ID!) {\n  designManagementUpload(input: {projectPath: $projectPath, iid: $iid, files: $files}) {\n    designs {\n      ...DesignListItem\n      versions {\n        edges {\n          node {\n            id\n            sha\n            __typename\n          }\n          __typename\n        }\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n}\n\nfragment DesignListItem on Design {\n  id\n  image\n  filename\n  __typename\n}\n"}
------WebKitFormBoundaryHgU2DZfs5IjCF4TD
Content-Disposition: form-data; name="map"

{"1":["variables.files.0"]}
------WebKitFormBoundaryHgU2DZfs5IjCF4TD
Content-Disposition: form-data; name="1"; filename="a_file.jpg"
Content-Type: image/jpeg


------WebKitFormBoundaryHgU2DZfs5IjCF4TD--
Edited by Alessio Caiazza