query MagicFeed($limit: Int!, $offset: Int!) {
magicFeed(limit: $limit, offset: $offset) @connection(key: "magicFeed") {
... on Product {
id
__typename
name
price
defaultImage
formatedName @client
formatedPrice @client
shop {
id
name
avatar
formatedShopName @client
}
isBookmarked
}
... on Category {
id
__typename
name
image
}
}
mainCategories {
id
__typename
name
image
subCats {
id
name
image
}
isSubCat
}
}
That was my Query, Here i am querying for magic feed and main categories from the server.
and inside my inMemeryCache.
export const cache: InMemoryCache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
readMainCategories: {
read(mainCategories, { readField}){
return readField<MainCategoriesQuery[]>('mainCategories') ?? [];
}
},
magicFeed: {
keyArgs: false,
read(existing, { args: { offset = 0, limit = existing?.length } = {}, readField }: any) {
const mainCategories = readField('readMainCategories')) || [];
newFeed = existing ? existing.slice(0) : [];
// i would like to return a new array with first element of the array
// being main category results returned from the cache and return the list
return existing && existing.slice(offset, offset + limit);
},
merge(existing, incoming, { args: { offset = 0 } }: any) {
const merged = existing ? existing.slice(0) : [];
for (let i = 0; i < incoming.length; ++i) {
merged[offset + i] = incoming[i];
}
// console.log('magicFeedMerged', merged);
return merged;
},
},
}
}
}
})
inside the read function, i would like to return a new array with first element of the array being main category results returned from the cache and return the list. Is this doable, Also with read function pagination doesn’t work for me.