All files / src/core networkStatus.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 2/2
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57  10x 10x 10x 10x 10x 10x 10x 10x     1161x                                                                                          
/**
 * The current status of a query’s execution in our system.
 */
export enum NetworkStatus {
  /**
   * The query has never been run before and the query is now currently running. A query will still
   * have this network status even if a partial data result was returned from the cache, but a
   * query was dispatched anyway.
   */
  loading = 1,
 
  /**
   * If `setVariables` was called and a query was fired because of that then the network status
   * will be `setVariables` until the result of that query comes back.
   */
  setVariables = 2,
 
  /**
   * Indicates that `fetchMore` was called on this query and that the query created is currently in
   * flight.
   */
  fetchMore = 3,
 
  /**
   * Similar to the `setVariables` network status. It means that `refetch` was called on a query
   * and the refetch request is currently in flight.
   */
  refetch = 4,
 
  /**
   * Indicates that a polling query is currently in flight. So for example if you are polling a
   * query every 10 seconds then the network status will switch to `poll` every 10 seconds whenever
   * a poll request has been sent but not resolved.
   */
  poll = 6,
 
  /**
   * No request is in flight for this query, and no errors happened. Everything is OK.
   */
  ready = 7,
 
  /**
   * No request is in flight for this query, but one or more errors were detected.
   */
  error = 8,
}
 
/**
 * Returns true if there is currently a network request in flight according to a given network
 * status.
 */
export function isNetworkRequestInFlight(
  networkStatus: NetworkStatus,
): boolean {
  return networkStatus < 7;
}