Cache and parent fields

Goal: when arquiring some data (a big list = prefetch) and later quering a subset of that list (by extId), I want the data to be acquired from cache (iso http req).

Situation: supabase + pg_graphql (adds intermediate fields like adsCollection, edges, node to e.g. support pagination, which are not stored in normalized form in cache)+ (vue) apollo client
Query:

query getAdGroupingData($adExtIds: [UUID]) {
  **adsCollection**(
    filter: { extId: { in: $adExtIds } }
  ) {
    
    **edges** {
      **node** { -->typename = ads 
        extId
        name
        creatives{ -->typename is creatives
thumbnailUrl, extId}
      }
    }
  }

execution query first 1) with variables adExtIds = [1,2,3] and later with 2) [1,2] should result in only ONE network call. But currently getting 2 calls.

Tried:

  1. I’m able to get the normalized ads and creatives in cache [OK]
typePolicies: {
    ads: { keyFields: ['extId'] },
    creatives: { keyFields: ['extId'] },
  1. able to get a single entry from cache, but undesired as I need to write a second query/ fragment and post processer to get the correct fields later.
client.readFragment({
      id: 'ads:{"extId":"23853221171040758"}', // The value of the to-do item's cache ID
      fragment: gql`
        fragment AdGroupData on ads {
          extId
          name
          creatives {
            thumbnailUrl
            extId
          }
        }
      `,

3. problem, how to just execute the ‘getAdGroupingData’ query with a subset of the id’s without performing a network request

Hi @rob :wave: welcome to the forum!

I’m not 100% certain but the Cache Redirects portion of our documentation may be worth a read:

I don’t believe the cache will assume that an array of arbitrary values passed as variables to an arbitrary query will behave deterministically. So adding a read function to a field policy for getAdGropuingData should help you specify deduplication logic so the cache behaves in the manner you prescribe. I hope that helps!