graphQL: Add ability to filter by a range (Date/Numeric fields)

It would be useful if graphQL queries could filter for a Date field in a specific range.

This would also be useful for Numeric fields.

This is a special case of the missing ability to specify compound conditions –
field>lowerBound AND field<upperBound

Hello, @Matt_Blais

It is possible. Find example below

{
  findReleases(releaseDate:{
	greater: "2023-10-01"
    less: "2023-10-31"
  })
  { 
    name
    releaseDate
  }
}

1 Like

@Oleg is there a way to reference today’s date in graphQL filter?

Like if I wanted to update your previous example to query all releases with a release date that fell in the last 7 days?

{
  findReleases(releaseDate:{
        less: Today - 7 days
  })
  { 
    name
    releaseDate
  }
}

Hello, @interr0bangr

Unfortunately it is not possible for now.

1 Like

@interr0bangr I access the graphQL API from bash scripts, and accomplish this like so:

...

local before=${before:-'3 months ago'}
before="dateRange:      { end: {less: \"$(utcDate "$before")\" } }"
limit=${limit:+"limit: $limit"}
SPACE=REPORTS; QUERY='
    mutation {
        callStats(
            '$before'        # exclude newer
            calls:          { isEmpty: true }
            callsCount:     { is: 0 }
            callsDurationMinutes: { is: 0 }
            orderBy:        { dateRange: {start: ASC} }
            '$limit'
        )
        # Use executeAsBackgroundJob if receiving "The upstream server is timing out"
        # {executeAsBackgroundJob { jobId actions
            { delete {message} }
        # }}
    }'
total=0; CHECKDELAY=30
while :; do
    waitForFiberyBackend   # Wait for Fibery backend (Formulas, linking, etc) to get caught up
    doQuery    # call curl for $SPACE and $QUERY- sets $rc
    ((rc==7))       && continue       # "Canceling statement due to statement timeout."
    ((deleted==0))  && break
    ((total+=deleted))
done
echo -e "FINISHED $jobName, TOTAL=$total" >&2

If you’re interested I can post the other parts of this system.

Thanks @Matt_Blais but that’s way over my very-limited understanding of the api/scripts!

I just created a date helper formula on one of databases and then use that field in my script, which isn’t ideal but gets the job done. :slight_smile:

1 Like