How to use math in a function?

I have a type that stores an amount field and an interval field:

type Commitment {
  id: ID
  amount: Float!
  intervals: Float!

We use this to track commitments as commitments can be weekly, bi-monthly, monthly, quarterly, yearly. The intervals is a set ratio against a year. This allows for commitments to span over several years as well.

What I want to do is to filter commitments to all that average at least $100/mo.

Hoping I could do something like:

  node(func: (gt(math(Commitment.amount * Commitment.intervals / 12), 100))) {

But, it appears that I cannot do this kind of math in a function like gt.

I get the error:

Expected comma or language but got: 1

Math functions operate on query variables (docs). Here’s an example based on your post, using a var block as well:

  var(func: type(Commitment)) {
    a as Commitment.amount
    i as Commitment.intervals
    m as math(a * i / 12)

  node(func: gt(val(m), 100)) {
1 Like