1import { pipe, tap } from 'wonka';
2import type { Exchange } from '../types';
3
4/** Simple log debugger exchange.
5 *
6 * @remarks
7 * An exchange that logs incoming {@link Operation | Operations} and
8 * {@link OperationResult | OperationResults} in development.
9 *
10 * This exchange is a no-op in production and often used in issue reporting
11 * to understand certain usage patterns of `urql` without having access to
12 * the original source code.
13 *
14 * Hint: When you report an issue you’re having with `urql`, adding
15 * this as your first exchange and posting its output can speed up
16 * issue triaging a lot!
17 */
18export const debugExchange: Exchange = ({ forward }) => {
19 if (process.env.NODE_ENV === 'production') {
20 return ops$ => forward(ops$);
21 } else {
22 return ops$ =>
23 pipe(
24 ops$,
25 // eslint-disable-next-line no-console
26 tap(op => console.debug('[Exchange debug]: Incoming operation: ', op)),
27 forward,
28 tap(result =>
29 // eslint-disable-next-line no-console
30 console.debug('[Exchange debug]: Completed operation: ', result)
31 )
32 );
33 }
34};