Class RequestStateService

public

The RequestStateService is used to track the state of requests for fetching or updating known resource identifies that are inflight.

Show:

identifier
StableRecordIdentifier
returns
RequestState | null
the state of the most recent request for the given identifier

Retrieve the last completed request for a given resource identity.

identifier
StableRecordIdentifier
returns
RequestState[]
an array of request states for any pending requests for the given identifier

Retrieve all active requests for a given resource identity.

identifier
StableRecordIdentifier
callback
(state: RequestState) => void

Subscribe to requests for a given resource identity.

The callback will receive the current state of the request.

1
2
3
4
5
6
interface RequestState {
  state: 'pending' | 'fulfilled' | 'rejected';
  type: 'query' | 'mutation';
  request: Request;
  response?: { data: unknown };
}

Note: It should be considered dangerous to use this API for more than simple state derivation or debugging. The request and response properties are poorly spec'd and may change unexpectedly when shifting what Handlers are in use or how requests are issued from the Store.

We expect to revisit this API in the near future as we continue to refine the RequestManager ergonomics, as a simpler but more powerful direct integration with the RequestManager for these purposes is likely to be a better long-term design.