import { createClient , dedupExchange , cacheExchange , fetchExchange , ssrExchange , Client , Exchange , } from 'urql' ; import { SSRData , SSRExchange } from 'urql/dist/types/exchanges/ssr' ; import 'isomorphic-unfetch' ; import { NextUrqlClientOptions } from './types' ; let urqlClient = null ; let ssrCache = null ; export function initUrqlClient ( clientOptions , mergeExchanges = ssrEx => [ dedupExchange , cacheExchange , ssrEx , fetchExchange , ] , initialState ? ) { const isServer = typeof window === 'undefined' ; if ( isServer || ! urqlClient ) { ssrCache = ssrExchange ( { initialState } ) ; urqlClient = createClient ( { ... clientOptions , suspense : isServer , exchanges : mergeExchanges ( ssrCache ) , } ) ; } return [ urqlClient , ssrCache ] ; }