Skip to content

Update Apollo cache with latest assignment status on mutation success

Vamsi Vempati requested to merge 421967-update-cache-on-successful-mutation into master

What does this MR do and why?

Updates Apollo cache with latest assignment status on mutation success

  • Uses NETWORK_ONLY + CACHE_FIRST policy to fetch the user list from the server initially and operate on cache from there on
  • Captures mutation errors on Sentry

Note: The API changes to fetch the user list is being implemented in Create add on eligible users GraphQL API (!129203 - merged). In the meantime, we're using client resolvers to resolve the value of addOnEligibleUsers to display the user list on Code Suggestions tab. This will let us deploy frontend code while the API is being implemented. The plan is to remove the client resolvers once the API changes are live.

Screenshots or screen recordings

No visual changes - the status of the toggle is deduced from a computed value reading the cache instead of a local variable in the component.

Screen_Recording_2023-09-26_at_1.54.27_PM

How to set up and validate locally

Application setup

  1. Customers Dot needs to be setup in order to view the billing page for a group
  2. Start GDK in SaaS mode GITLAB_SIMULATE_SAAS=1 gdk start

Group setup

  1. Create a Group
  2. Buy a Subscription for your group from Settings > Billing

Feature flag

Run the following in your rails console

Feature.enable(:enable_hamilton_in_usage_quotas_ui, Namespace.find(your-group-id)
Feature.enable(:hamilton_seat_management, Namespace.find(your-group-id)

Add-on purchase

Run the following in your rails console

  1. Find the namespace
namespace = Namespace.find(your-group-id)
  1. Create an Addon
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
  1. Create an add-on purchase
GitlabSubscriptions::AddOnPurchase.create!(add_on: add_on, namespace: namespace, expires_on: 1.month.from_now, quantity: 20, purchase_xid: 'A-S0001')

Client resolvers for add-on user list

  1. Apply patch to resolve user list locally on Client side: Add_On_Users_For_Cache_Update.patch
  2. Update the user id for the first user in ee/app/assets/javascripts/usage_quotas/code_suggestions/mock_data.js to be that of one of the users in the group's members page - /groups/<your-namespace-name>/-/group_members.
    • This is so we can see the mutation to assign and unassign working with a real user id in the group
    • Note: We have an issue to handle unassigning a user who has already been unassigned in case you come across this situation while testing

Code Suggestions tab

  1. Visit /groups/<your-namespace-name>/-/usage_quotas#code-suggestions-usage-tab

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #421967

Edited by Vamsi Vempati

Merge request reports