Loading
Draft: Read policy store detail and editor through Vue Apollo
What does this MR do and why?
Closes https://gitlab.com/gitlab-org/gitlab/-/work_items/624217.
Both pages fetched their policy by awaiting a function in policies.js that wrapped a GraphQL query around the Apollo client by hand. That shape was kept from the REST era, when write responses were assigned straight to component state. Every policy store write is a GraphQL mutation now, so it can go.
- Detail and editor resolve the policy with a smart query, sharing one config in the new
single_policy_query.js. One document supplies both the policy and the triggers catalog, so the second request is gone. - The status toggle refreshes from the mutation's normalized result.
governPolicyUpdatereturns the wholeGovernPolicyfragment, which Apollo writes onto the entity the page watches — noupdatecallback, no second read. Pinned by a spec asserting the query handler is still called exactly once while the badge flips. policies.jskeeps only mappers (toPolicy,toListPolicies,toMutationVariables). ThegqlClientexport is gone fromapollo.js, which is now just the provider factory.- Specs drive real documents through
createMockApolloinstead ofjest.mock-ing the module.policies_spec.jsis now a mapper spec, andtoListPolicies— previously untested — is covered.
Decisions worth a reviewer's attention
- The delete does not touch the cache. An earlier draft evicted the policy, which forced the watching query to be stopped first, which in turn caused a refused delete to refetch and flash a spinner.
list_pathis rendered unconditionally on both detail views, so a successful delete always leaves viavisitUrl— a full navigation that discards the cache anyway. The eviction was unreachable in production, so it and theskipjuggling are both gone. "Updates the cache without refetch" is satisfied by the toggle, which is the one mutation whose page survives it. policyErroris assigned on every result rather than latched. Latching meant one failed read permanently replaced a healthy page with "could not be loaded". This matches whatcomponents/list/app.vuealready did.fetchPolicy: 'network-only'withnextFetchPolicy: 'cache-first'. The first read must not trust a cache another session may have staled;nextFetchPolicyonly applies after that fetch, so later reads follow the cache and a mutation's result reaches the page for free. A spec pins the first read by mounting twice against one client.- The camelCase adapter stays. The issue said "consider" dropping it;
step_wizard.vue,serializer.js,config_info.vueand the list rows all read the snake_case shape, so that is its own change. - Conflicts with !256226 (merged), which touches the same
onSavecatch block. Both are offmaster; whichever lands second needs a small rebase.
References
- Issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/624217
- Parent epic: https://gitlab.com/groups/gitlab-org/-/work_items/22542
- Conflicts with: !256226 (merged)
Screenshots or screen recordings
N/A — no rendered output changes. This is a data-layer refactor; the acceptance criterion is "no user-visible behavior change", and the 537 specs in ee/spec/frontend/policy_store assert the rendered states (loading, error, not-found, populated, badge flips) are unchanged.
How to set up and validate locally
- Enable the Policy Store experiment: the instance-level
policy_store_experiment_enabledapplication setting plus the organization setting. - Visit an organization's Policy Store, open a policy's detail page. Confirm name, badges, trigger/rules/actions sections, scope and compiled Rego all render as before.
- Click Disable, then Enable. The status badge and button label must flip without a page reload, and the network tab must show only the mutation — no second policies query.
- Visit a policy id that does not exist. Confirm the "could not be loaded" alert.
- Edit a policy and save. Confirm it returns to the detail view with the success alert and the updated values.
- Delete a policy. Confirm the confirmation dialog, then the return to the list.
- Run
node_modules/.bin/jest ee/spec/frontend/policy_store --no-coverage.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.