Fluent Commerce Logo
Docs
Sign In

General Principles for Rules

Essential knowledge

Author:

Randy Chan

Changed on:

3 Nov 2023

Overview

Understand what are some general principles.

Key points

  • Fluent uses jsonPath, which is a period-separated string that describes a "path" between the entity being processed and a field on it or a related entity.
  • In essence, this category of rules understands how to generate dynamic queries. 
  • There are some helpers for traversing connection types, edges, and node fields, which will be automatically skipped, for example, `items.0.currency`  is equivalent to `items.edges.0.node.currency` 

JsonPath Props

Many of the rules in the core module accept a prop typed as a jsonPath, which is a period-separated string that describes a "path" between the being processed and a field on it or a related .

In essence, this category of rules understands how to generate dynamic queries to maximize flexibility across domains and use cases. In most cases, the value/s loaded via this dynamic query will be compared against another prop as described by the name and description.

For example, fields on or related to the could be accessed with the following paths:

Path

Description

`status`

Use the state field of the .

`fulfilmentChoice.deliveryType`

Use the delivery type field of the Choice related to the .

`items.0.currency`

Use the currency value of the first item of the .

`attributes.byName.promoCode`

Use the value of a custom of the .

Additionally, properties of the can be referenced with the `event.` prefix:

Path

Description

`event.entitySubType`

Use the subtype from the .

`event.attributes.myCustomAttribute`

Use the value of a custom .

`event.myCustomAttribute`

As above, as long as the name doesn't clash with a standard field.

Finally, there are some helpers to simplify specific use cases: - when traversing connection types, edges, and node fields will be automatically skipped over even if they're not added to the path, e.g., the `items.0.currency` sample above is equivalent to `items.edges.0.node.currency` - all array types, including connection edges, support first and last values in place of the index, e.g. `items.first.currency` or `items.last.currency` - since attributes are an array, the `byName` shorthand is available to access them by name, e.g. `attributes.byName.promoCode`.