Skip to main content

inhibitOnEmpty

Returns a step that yields the same values as the passed in step, but downstream work is inhibited when the yielded value is considered empty.

Not a security boundary

inhibitOnEmpty enables Grafast to optimize away unnecessary downstream work; it does not guarantee that the work will not execute. Do not use it for authorization or to prevent security-sensitive operations. Enforce those requirements inside the protected operation or data source.

Grafast currently considers a value empty if it is:

  • undefined
  • null
  • ""
  • an empty array
  • an object with no own enumerable string keys

false, 0, and other non-empty primitive values are not treated as empty.

Example​

const $myList = fieldArgs.getRaw("myList");
const $guardedList = inhibitOnEmpty($myList);
const $result = doSomethingWith($guardedList);
return trap($result, TRAP_INHIBITED, {
valueForInhibited: "EMPTY_LIST",
});

inhibitOnEmpty is a convenience helper built on top of inhibitIf.