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
- Part of section D of #628901 (console errors in feature specs)
- Console check and baseline allowlist MR that surfaced it: !255207 (closed)
- Reveal pipeline job showing the error: https://gitlab.com/gitlab-org/gitlab/-/jobs/16462296271
Screenshots or screen recordings
Not applicable. No visible change.
How to set up and validate locally
- Run
yarn jest spec/frontend/repository/graphql_spec.js spec/frontend/repository/components/preview - In GDK create a project whose only README is
README.txt - Open the project page with the browser console open
- 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.