Given the following schema:
interface ITransactor {
objectiveID: ID!
incomingTransactions: [Transaction!] @hasInverse(field: to)
outgoingTransactions: [Transaction!] @hasInverse(field: from)
balance: Float @lambda
}
type Transaction implements IMetadata {
objectiveID: ID!
from: ITransactor
to: ITransactor!
amount: Float! @search
}
I would like to have a lambda that calculates the balance by summing the incoming and outgoing transactions, something like this:
const balance = ({parent: {incomingTransactions, outgoingTransactions}}) => {
const totalIncoming = incomingTransactions.reduce(((pv, cv) => { pv += cv.amount; return pv; }), 0.0);
const totalOutgoing = outgoingTransactions.reduce(((pv, cv) => { pv += cv.amount; return pv; }), 0.0);
return totalIncoming - totalOutgoing;
}
self.addGraphQLResolvers({
"ITransactor.balance": balance
})
However, it looks like I can’t access the incomingTransactions and outgoingTransaction fields in the lambda query from the parent object. Is this by design? Is it because they are array fields? If so, is there a way to accomplish what I need?
Also just some feedback - it’s pretty difficult to debug lambdas as they are setup - e.g. the logs are unresponsive and not very informative, there’s no typing, etc.