Skip to content

How to skip cache for some operations #3559

Discussion options

You must be logged in to vote

Here is a solution:

import { cacheExchange, CacheExchangeOpts } from '@urql/exchange-graphcache';
import {
  Exchange,
  ExchangeInput,
  ExchangeIO,
  Operation,
  OperationResult,
} from 'urql';
import { empty, filter, merge, pipe, Source } from 'wonka';
import { getDocumentFieldName } from './utils';

interface WrappedCacheExchangeOpts extends CacheExchangeOpts {
  cacheSkipOperations?: string[];
}

/** filter which operation will skip cache */
function filterOperationToSkipCache(
  operation: Operation,
  options?: WrappedCacheExchangeOpts
) {
  const operationName = getDocumentFieldName(operation.query);
  if (operationName && options?.cacheSkipOperations?.includes(operationName)) {

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@FreeRiderBysik
Comment options

@amannn
Comment options

Comment options

You must be logged in to vote
1 reply
@drc37
Comment options

Answer selected by FreeRiderBysik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants