Managing an array at two different levels in a Schema

Does anyone have a recommendation for managing an array at two different levels in your schema?

For a longer explanation, we have a data model that looks something like this:

organization {
  alerts
  locations {
    ...
    machines
    ...
  }
}

machine(machineID: "") {
  alerts
}

alerts is a list of instances of the Alert type, which may contain a few fields (e.g. an id, name, enough details to identify the machine that the alert corresponds to, etc.). The organization type contains all of the alerts in the system for that organization. Machines are part of an organization. Thus, the Machine’s alerts will be a subset of the Organization’s alerts.

In our UI, we query for all of the organization’s alerts (i.e. organization { alerts }) and display some of that information in a small section. We set a pollInterval to periodically check if any new alerts started occurring or any existing alerts stopped occurring across the organization. Additionally, a user may also view information about a specific machine. In this case, we’ll query for that machine’s specific information (including its alerts, which will be a subset of the Organization’s alerts).

Ideally, if the Organization-level polling:

  • removes an existing alert and the user is viewing the machine-specific information, we would update the machine-specific UI to stop showing the alert.
  • adds a new alert and the user is viewing the machine-specific information, we would update the machine-specific UI to start showing the new alert.

Does anyone have any suggestions for the best way to manage this?

Is it possible to perform cache evictions and cache insertions as part of customizing the merge behavior for the Organization’s alert field?

My rough idea was to add a merge function for the Organization’s alert:

  • If an alert is removed, then evict it from the cache. I wasn’t sure if it was possible to evict from the cache at this point though. Does this need to happen outside of the merge function?
  • If an alert is added, calculate the machine’s cache ID and add a reference to the new alert.

Does the above make sense? Or is there a better way to accomplish this?

Thank you in advance,
Ryan