Query :
query sample {
accountBalance(issuanceRequired: true) {
uCardAccountBalance {
purses {
uCardPurseType
promotionId
availableAmount
startDate
endDate
nextDeposit {
id
status
amount
}
groceryDiscountsInfo {
numDiscounts
}
}
}
}
}
`;
With this query sometimes nextDeposit, startDate, endDate from purses
are not available in the graphql response like this
"purses": [
{
"uCardPurseType": "grocery",
"availableAmount": 13.88,
"startDate": "2017-02-17T00:00:00",
"endDate": "2099-12-31T00:00:00",
"groceryDiscountsInfo": {
"numDiscounts": 6,
"__typename": "UCardPurseGroceryDiscountInfo"
},
"__typename": "UCardPurse"
},
{
"uCardPurseType": "otc_food_utilities",
"availableAmount": 0.0,
"__typename": "UCardPurse"
},
{
"uCardPurseType": "renew_rewards",
"availableAmount": 0.0,
"__typename": "UCardPurse"
}
],
as you see some fields are missing in two objects of purses, I get errors corresponding to each missing field on the console.
I tried adding them to typePolicies like this but I was wondering how many fields I will end up adding to fix this issues.
Is there a better way to handle it on frontend or backend efficiently?
typePolicies: {
UCardPurse: {
fields: {
startDate: {
read(existing) {
return existing || 'N/A'; // Provide a default value if startDate is missing
},
},
endDate: {
read(existing) {
return existing || 'N/A'; // Provide a default value if endDate is missing
},
},
nextDeposit: {
read(existing) {
console.log('Reading nextDeposit from cache:', existing);
return existing || {}; // Provide a default value if nextDeposit is missing
},
},
},
},
},