Skip to content

batches: cache batch change query by swapping to Apollo `useQuery`

Warren Gifford requested to merge kr/batch-change-data-caching into main

Created by: courier-new

Part 1 of #24417 (closed). Swaps out query to fetch batch change by namespace to use Apollo useQuery instead of observable pattern so that response data can be cached. This isn't the most important query from this page to cache, but it's one of the easiest, and it's also a pre-requisite for caching other important data, so I decided to start with it as a foundation for the rest.

I didn't have a chance to record this yet, but you can see it in action by visiting any batch change's details page, leaving, and then returning to the same page. The basic batch change details at the top of the page populate instantly on the return visit, but you can still observe network request made in the background that will update the page data with any updates.

This PR also adds wildcard-mock-link in order to mock response data for Apollo's MockedProvider for GraphQL requests with arbitrary variables, which is not currently supported by MockedProvider out of the box. I needed this to efficiently update the mock responses for the storybook stories for this page, but I will be pushing a follow-up PR that updates our Apollo usage docs with more instructions for how to use this to mock response data in tests.

As you'll notice, most of the added lines are related to explicitly requesting the __typename field on a variety of queries and then setting it on the corresponding mock data responses, because the Apollo cache relies on the field being there to reliably set and retrieve data. You'll see a lot of this come up in the subsequent PRs as well.

Merge request reports

Loading