message: Fix dependencies being stored for non-queries
diff: @@ -23,7 +23,7 @@ const addTypeNames = (op: Operation): Operation => ({
  // Retrieves the requestPolicy from an operation
  const getRequestPolicy = (op: Operation) => op.context.requestPolicy;
  -// Returns whether an operation is handled by this exchange
  +// Returns whether an operation is a query
  const isQueryOperation = (op: Operation): boolean => {
  const policy = getRequestPolicy(op);
  return (
  @@ -34,13 +34,16 @@ const isQueryOperation = (op: Operation): boolean => {
  );
  };
  -export const cacheExchange = (opts: StoreOpts): Exchange => ({
  - forward,
  - client,
  -}) => {
  - const store = new Store(opts);
  - const ops: OperationMap = new Map();
  - const deps = Object.create(null) as DependentOperations;
  +// Returns whether an operation is handled by this exchange
  +const isCacheableQuery = (op: Operation): boolean => {
  + const policy = getRequestPolicy(op);
  + return (
  + isQueryOperation(op) &&
  + (policy === 'cache-and-network' ||
  + policy === 'cache-first' ||
  + policy === 'cache-only')
  + );
  +};
  // Copy an operation and change the requestPolicy to skip the cache
  const toNetworkOnly = (operation: Operation): Operation => ({
  @@ -51,6 +54,14 @@ export const cacheExchange = (opts: StoreOpts): Exchange => ({
  },
  });
  +export const cacheExchange = (opts: StoreOpts): Exchange => ({
  + forward,
  + client,
  +}) => {
  + const store = new Store(opts);
  + const ops: OperationMap = new Map();
  + const deps = Object.create(null) as DependentOperations;
  +
  // This accepts an array of dependencies and reexecutes all known operations
  // against the mapping of dependencies to operations
  // The passed triggerOp is ignored however
  @@ -125,9 +136,11 @@ export const cacheExchange = (opts: StoreOpts): Exchange => ({
  // Update operations that depend on the updated data (except the current one)
  processDependencies(operation, dependencies);
  - // Update this operation's dependencies
  + // Update this operation's dependencies if it's a query
  + if (isQueryOperation(operation)) {
  updateDependencies(operation, dependencies);
  }
  + }
  };
  return ops$ => {
  @@ -140,7 +153,7 @@ export const cacheExchange = (opts: StoreOpts): Exchange => ({
  // Filter by operations that are cacheable and attempt to query them from the cache
  const cache$ = pipe(
  sharedOps$,
  - filter(op => isQueryOperation(op)),
  + filter(op => isCacheableQuery(op)),
  map(operationResultFromCache),
  share
  );
  @@ -173,7 +186,7 @@ export const cacheExchange = (opts: StoreOpts): Exchange => ({
  merge([
  pipe(
  sharedOps$,
  - filter(op => !isQueryOperation(op))
  + filter(op => !isCacheableQuery(op))
  ),
  cacheOps$,
  ])
  