Closed rneswold closed 1 year ago
GraphQL resolvers are only called if the field is specified in the reply. Unfortunately, it's not easy to save the results of one field's resolver to share with others. If the user wants all three fields returned, I don't see how I can save the results of the XINFO command to be used when each resolver is called. So it seems I need to run XINFO 3 times.
Instead, I created another type DeviceHistory
that contains the three fields and made one field in DeviceInfo
. Now if the user asks for the history, we grab it once with XINFO and return the structure. The reply may not return all three fields, but they're there.
While playing with redis, I found the XINFO command which returns information about a redis stream. Since our device history is stored in streams, this could be a useful command to return history information. Among several interesting pieces of information, it returns the number of points of history and the first and last data points along with the timestamps.
This issue proposes to add several fields to the reply of a
deviceInfo
query.total_points
first_point
last_point
The reading fields are nullable, if there isn't any history. The
Reading
type is the same used when monitoring a device. In fact, reading thelast_point
field is a way to poll a device (monitoring a device is better, though, since you can't miss any intermediate values.)For the simple backend,
total_points
will be 0 or 1 and thefirst_point
andlast_point
fields will be null or have the same value since its history is only one point deep.