Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next-urql: how do I add devtoolsExchange? #888

Closed
TimonVS opened this issue Jul 3, 2020 · 2 comments · Fixed by #891
Closed

next-urql: how do I add devtoolsExchange? #888

TimonVS opened this issue Jul 3, 2020 · 2 comments · Fixed by #891

Comments

@TimonVS
Copy link

TimonVS commented Jul 3, 2020

urql version & exchanges:

  • urql: 1.9.8
  • next-urql: 1.0.2
  • @urql/devtools: 2.0.2

I'm wondering how you can add the devtools exchange without overriding the default exchanges with next-urql. The next-urql docs mention something about mergeExchanges in the second argument of withUrqlClient, but I can only pass ssr as an option in the second argument. If I provide exchanges in the first argument, it'll not apply the default exchanges (https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.tsx#L48 and https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.tsx#L84).

@JoviDeCroock
Copy link
Collaborator

Hey,

The defaultExchanges are dedupExchange, cacheExchange, ssr, fetchExchange in that order as you linked. So if you want to apply this to your next-urql client you should do:

import { fetchExchange, dedupExchange, cacheExchange } from 'urql';
import { devtoolsExchange } from '@urql/devtools';

export default withUrqlClient(ssr => {
  ...yourConfig
  exchanges: process.browser ? 
     [dedupExchange, devtoolsExchange, cacheExchange, ssr, fetchExchange] :
     [dedupExchange, cacheExchange, ssr, fetchExchange]
})(YourComponent)

@TimonVS
Copy link
Author

TimonVS commented Jul 3, 2020

Fair enough! The documentation about mergeExchanges had me confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants