We are using GraphQL as a query language for a data aggregation engine.
I am looking for ideas to represent simple (or complex) arithmetic calculation functions in GraphQL referring to existing types/attributes defined in a schema, and can be used over existing attributes.
I am looking into Custom scalars and Directives
Example -
{
item{
units
price_per_unit
market_price: function:multiply(units, price_per_unit)
market_price_usd: function:usdPrice(units, price_per_unit, currency)
}
}
where function:multiply is already defined in the GraphQL
schema as a type
functions {
multiply(operand 1, operand2) {
result
}
usdPrice(operand1, operand2, currency) {
result: {
if(currency == GBP) {
operand1 * operand2 * .76
}
{
}
internally resolver will multiply operand 1 and operand 2 to create result.