Always resolve the README preview html field

What does this MR do and why?

The repository tree page previews the README through an Apollo local resolver in app/assets/javascripts/repository/graphql.js. When the README has no rich viewer (for example, README.txt), the resolver omits the html field from its response. Apollo then writes a ReadmeFile without the selected html field and logs "Missing field 'html' while writing result" in the browser console.

This MR fixes the resolver to return html: null when the server does not provide an html key. The preview component already renders nothing for a null value, so the page looks the same. The request and the fallback move into an exported fetchReadme helper so they can be unit tested. New Jest spec spec/frontend/repository/graphql_spec.js covers both response shapes. Two suites, nine examples pass (also the preview component spec).

A README without a rich viewer still shows an empty preview, as before. Falling back to the simple viewer would be a product change and is out of scope.

References

Screenshots or screen recordings

Not applicable. No visible change.

How to set up and validate locally

  1. Run yarn jest spec/frontend/repository/graphql_spec.js spec/frontend/repository/components/preview
  2. In GDK create a project whose only README is README.txt
  3. Open the project page with the browser console open
  4. On master the console shows "Missing field 'html' while writing result"; on this branch it shows nothing

MR acceptance checklist

This MR has been evaluated against the GitLab acceptance checklist.

Edited by Miguel Rincon

Merge request reports

Loading
Loading