Skip to content

Commit

Permalink
Merge pull request #1956 from kiva/GROW-130_query_fixes
Browse files Browse the repository at this point in the history
Fixed some issues with queries in this component
  • Loading branch information
eddieferrer authored Jul 31, 2020
2 parents 9ad12a3 + a7c457c commit 01f7e49
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/components/Homepage/LendByCategory/FeaturedLoansCarousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
client.query({
query: loanChannelData,
variables: {
ids: [categoryIds[0]],
numberOfLoans: 1,
}
})
Expand Down Expand Up @@ -125,11 +126,10 @@ export default {
basketId: cookieStore.get('kvbskt'),
},
});
this.processData(pageData);
} catch (e) {
logReadQueryError(e, 'FeaturedLoansCarousel lendByCategoryHomepageCategories');
}
this.processData(pageData);
// Read the loanChannel info from the cache
let categoryInfo = {};
try {
Expand All @@ -144,21 +144,25 @@ export default {
}
this.prefetchedCategoryInfo = _get(categoryInfo, 'lend.loanChannelsById') || [];
// Read the first loan from the cache
let loanInfo = {};
try {
loanInfo = this.apollo.readQuery({
query: loanChannelData,
variables: {
ids: [this.prefetchedCategoryInfo[0].id],
numberOfLoans: 1,
},
});
} catch (e) {
logReadQueryError(e, 'FeaturedLoansCarousel loanChannelData');
const firstChannelId = _get(this.prefetchedCategoryInfo[0], 'id');
if (firstChannelId) {
// Read the first loan from the cache
let loanInfo = {};
try {
loanInfo = this.apollo.readQuery({
query: loanChannelData,
variables: {
ids: [firstChannelId],
numberOfLoans: 1,
basketId: cookieStore.get('kvbskt'),
},
});
const channelLoans = _get(loanInfo, 'lend.loanChannelsById')[0];
this.featuredLoans.push(channelLoans);
} catch (e) {
logReadQueryError(e, 'FeaturedLoansCarousel loanChannelData');
}
}
const channelLoans = _get(loanInfo, 'lend.loanChannelsById')[0];
this.featuredLoans.push(channelLoans);
},
mounted() {
this.activateWatchers();
Expand Down

0 comments on commit 01f7e49

Please sign in to comment.