+126
docs/advanced/debugging.md
···+We've tried to make debugging in `urql` as seamless as possible by creating tools for users of `urql` and those creating their own exchanges.+Debug events are a means for seeing what's going on inside of `urql` exchanges. Before getting started, here are a few things to be aware of.+This includes the creator of an `urql` client and any of it's exchanges (although the latter is not advised).+Debug events are a fire-and-forget mechanism and should not be used as a means for messaging in your app.+Debugging events can be inspected either graphically using our [devtools](https://github.com/FormidableLabs/urql-devtools) or manually by subscribing to events on the client.+The quickest way is going to be using our [devtools extension](https://github.com/FormidableLabs/urql-devtools/) which visualizes events on a timeline and provides tools to filter events, inspect the cache, and trigger custom queries via the running client.+Visit [the repo](https://github.com/FormidableLabs/urql-devtools/) for instructions on getting started.+> Note: Devtools is unfortunately not currently supported for React Native but we're looking into it!+For those not looking to use a GUI to view events, the client has a `subscribeToDebugTarget` function.+As demonstrated below, the `subscribeToDebugTarget` function takes a callback which is called with every debug event that is dispatched.+For example, a [_fetchExchange_](https://github.com/FormidableLabs/urql/blob/master/packages/core/src/exchanges/fetch.ts) which triggers fetch requests may have an event of type `fetchRequest`.+For type safe events, and to prevent conflicts with other exchanges, [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) can be used.+A `dispatchDebug` function is now passed to every exchange and is used to dispatch debug events.+> Note: for a real world example, see the [_fetchExchange_](https://github.com/FormidableLabs/urql/blob/master/packages/core/src/exchanges/fetch.ts).+Key events should be easy to identify and differentiate, so have a unique name and data format for each unique event and use that format consistently.+While it is possible, there isn't any value in doing this. Use the exchange pipeline to communicate with other exchanges.+Debug **events** are intended to document **events** inside an exchange, not as a way to send messages to the user. Use `console.warn` to send alerts to the user.
docs/assets/devtools-timeline.png
This is a binary file and will not be displayed.