Return the errors payload from environment local mutations

What does this MR do and why?

The Environments page uses Apollo Client local resolvers for some actions. Three local mutation resolvers in app/assets/javascripts/environments/graphql/resolvers/base.js did not return their result to the caller:

  • stopEnvironmentREST
  • deleteEnvironment
  • rollbackEnvironment

Each mutation document selects an errors field, so Apollo expects an object with errors. Each resolver chained two .then calls after the HTTP request. The first .then built the payload with buildErrors(). The second .then evicted the folder field from the cache and did not return the payload. As a result:

  • stopEnvironmentREST and rollbackEnvironment resolved to undefined.
  • deleteEnvironment resolved to true, the return value of cache.evict.
  • Apollo logged Missing field 'errors' while writing result true in the browser console.
  • The delete and rollback modals read errors from the result, so they never received the payload.

This affects anyone who stops, deletes, or rolls back an environment from an environment folder page. The visible symptom is a console error. The list still refreshes.

What changes

  • Each of the three resolvers now evicts the cache inside the first .then and returns buildErrors() from it.
  • The second .then is removed.
  • The .catch branches are unchanged. They already return buildErrors([...]) with a message.
  • spec/frontend/environments/graphql/resolvers/base_spec.js now asserts the resolved value of each resolver equals { errors: [], __typename: 'LocalEnvironmentErrors' }.

Approach

  • Ruled out: remove the errors selection from the mutation documents. The delete and rollback modals depend on the payload for the failure path, and the .catch branches already return it.
  • The success path keeps the same behavior. The cache eviction still runs before the promise resolves. Only the resolved value changes.

Screenshots or screen recordings

The page looks the same before and after. The difference is in the browser console. A temporary feature spec deleted a stopped environment from the folder page and collected the SEVERE browser logs.

Before After
before after
Run Missing field 'errors' while writing result true in the console
Before, master without this change 1
After, with this change 0

Other SEVERE entries in both runs are unrelated GDK noise. Examples are Snowplow connection errors and a toJSON Vue warning.

How to set up and validate locally

  1. Run yarn jest spec/frontend/environments/graphql/resolvers/base_spec.js. It passes in the Vue 2 lane and with VUE_VERSION=3.
  2. In GDK, open a project and go to Operate > Environments.
  3. Open an environment folder and open the browser console.
  4. Stop an environment, then delete it from the Stopped tab.
  5. On master, the console shows Missing field 'errors' while writing result true after the delete. On this branch, the console stays clean and the list refreshes.

MR acceptance checklist

This MR was evaluated against the acceptance checklist.

References

Edited by Miguel Rincon

Merge request reports

Loading
Loading