DRY up direct_asset_url method between GraphQL and REST API
The following discussion from !41170 (merged) should be addressed:
-
@nfriend started a discussion: (+5 comments) Question: This is an exact copy of the logic in our Grape entity: https://gitlab.com/gitlab-org/gitlab/-/blob/9e7619fafaee88b5d2c2840d11fe19e110ff078e/lib/api/entities/releases/link.rb#L20
Is there a way to share this logic between these two endpoints instead of duplicating it in both places?
Proposal
- Introduce a presenter class for
Releases::Link
model. - Move the
direct_asset_url
method to theReleases::LinkPresenter
class. (If necessary, movedownload_url
as well) - Make sure the
Releases::Link
objects are presented (e.g.release.link.present
orpresent_using
) in both Rest API (API::Entities::Releases::Link
) and GraphQL API (e.g.Types::ReleaseAssetLinkType
). - Make sure this refactoring only affects
direct_asset_url
method, not the other methods are changed/overridden.
Edited by Shinya Maeda