Skip to content

[Step1|BE] Add field blobs to GraphQL

Now that we're going to have multiple files, when we access the GraphQL endpoint, instead of one, it will return several blobs. It will be a matter of adding to https://gitlab.com/gitlab-org/gitlab/blob/master/app/graphql/types/snippet_type.rb the following:

field :blobs, type: [Types::Snippets::BlobType],
             description: 'Snippet blobs',
             calls_gitaly: true,
             null: false

Then in the snippet presenter https://gitlab.com/gitlab-org/gitlab/blob/master/app/presenters/snippet_presenter.rb we have to add a blobs method:

def blob
  blobs.first
end

def blobs
  if snippet.empty_repo?
    [snippet.blob]
  else
    snippet.blobs
  end
end

This way we don't break the existing logic in the GraphQL endpoint and allow it returns just one blob in the blob attribute.