Skip to content

Commit

Permalink
feat: introspection queries passed to a new query file (#5022)
Browse files Browse the repository at this point in the history
* feat: introspection queries passed to a new query file

* fix: promise all added for loan facets
  • Loading branch information
roger-in-kiva authored Oct 10, 2023
1 parent ad75546 commit ed0cd56
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export default {
resetFilters() {
this.$emit('reset-filters');
this.selectedCategory = 0;
this.selectedGender = '';
this.selectedGender = 'all';
this.selectedGenders = ['all'];
this.sortBy = this.defaultSort;
this.updateLocation([]);
Expand Down
22 changes: 22 additions & 0 deletions src/graphql/query/loanEnumsQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
query loanEnums {
genderOptions: __type(name: "GenderEnum") {
enumValues {
name
}
}
standardSorts: __type(name: "LoanSearchSortByEnum") {
enumValues {
name
}
}
flssSorts: __type(name: "SortEnum") {
enumValues {
name
}
}
distributionModelOptions: __type(name: "LoanDistributionModelEnum") {
enumValues {
name
}
}
}
20 changes: 0 additions & 20 deletions src/graphql/query/loanFacetsQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,4 @@ query loanFacets {
}
}
}
genderOptions: __type(name: "GenderEnum") {
enumValues {
name
}
}
standardSorts: __type(name: "LoanSearchSortByEnum") {
enumValues {
name
}
}
flssSorts: __type(name: "SortEnum") {
enumValues {
name
}
}
distributionModelOptions: __type(name: "LoanDistributionModelEnum") {
enumValues {
name
}
}
}
24 changes: 14 additions & 10 deletions src/util/loanSearch/dataUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import loanFacetsQuery from '@/graphql/query/loanFacetsQuery.graphql';
import loanEnumsQuery from '@/graphql/query/loanEnumsQuery.graphql';
import {
fetchFacets,
fetchLoans,
Expand Down Expand Up @@ -60,15 +61,18 @@ export async function runLoansQuery(apollo, loanSearchState, origin) {
*/
export async function fetchLoanFacets(apollo) {
try {
const result = await apollo.query({ query: loanFacetsQuery, fetchPolicy: 'network-only' });
const [resultFacets, resultEnums] = await Promise.all([
apollo.query({ query: loanFacetsQuery, fetchPolicy: 'network-only' }),
apollo.query({ query: loanEnumsQuery, fetchPolicy: 'network-only' })
]);

const countryFacets = result.data?.lend?.countryFacets ?? [];
const sectorFacets = result.data?.lend?.sector ?? [];
const themeFacets = result.data?.lend?.loanThemeFilter ?? [];
const tagFacets = result.data?.lend?.tag ?? [];
const genderFacets = result.data?.genderOptions?.enumValues ?? [];
const distributionModelFacets = result.data?.distributionModelOptions?.enumValues ?? [];
const partnerFacets = result.data?.general?.partners?.values ?? [];
const countryFacets = resultFacets.data?.lend?.countryFacets ?? [];
const sectorFacets = resultFacets.data?.lend?.sector ?? [];
const themeFacets = resultFacets.data?.lend?.loanThemeFilter ?? [];
const tagFacets = resultFacets.data?.lend?.tag ?? [];
const genderFacets = resultEnums.data?.genderOptions?.enumValues ?? [];
const distributionModelFacets = resultEnums.data?.distributionModelOptions?.enumValues ?? [];
const partnerFacets = resultFacets.data?.general?.partners?.values ?? [];

return {
countryFacets,
Expand All @@ -85,8 +89,8 @@ export async function fetchLoanFacets(apollo) {
tagNames: tagFacets.map(t => t.name.toUpperCase()),
genderFacets,
genders: genderFacets.map(g => g.name.toUpperCase()),
flssSorts: result.data?.flssSorts?.enumValues ?? [],
standardSorts: result.data?.standardSorts?.enumValues ?? [],
flssSorts: resultEnums.data?.flssSorts?.enumValues ?? [],
standardSorts: resultEnums.data?.standardSorts?.enumValues ?? [],
distributionModelFacets,
distributionModels: distributionModelFacets.map(d => d.name.toUpperCase()),
partnerFacets,
Expand Down
3 changes: 3 additions & 0 deletions test/unit/specs/util/loanSearch/dataUtils.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { runFacetsQueries, runLoansQuery, fetchLoanFacets } from '@/util/loanSearch/dataUtils';
import * as flssUtils from '@/util/flssUtils';
import loanFacetsQuery from '@/graphql/query/loanFacetsQuery.graphql';
import loanEnumsQuery from '@/graphql/query/loanEnumsQuery.graphql';
import { getFlssFilters, FLSS_ORIGIN_NOT_SPECIFIED } from '@/util/flssUtils';
import { mockState } from '../../../fixtures/mockLoanSearchData';

Expand Down Expand Up @@ -144,6 +145,8 @@ describe('dataUtils.js', () => {
await fetchLoanFacets(apollo);
const apolloVariables = { query: loanFacetsQuery, fetchPolicy: 'network-only' };
expect(apollo.query).toHaveBeenCalledWith(apolloVariables);
const apolloEnumsVariables = { query: loanEnumsQuery, fetchPolicy: 'network-only' };
expect(apollo.query).toHaveBeenCalledWith(apolloEnumsVariables);
});

it('should handle undefined', async () => {
Expand Down

0 comments on commit ed0cd56

Please sign in to comment.