Benefits
- Without install
@absinthe/socket
which contains some legacy package; also save 16kb gzip
import{subscriptionExchange}from'@urql/core'import{Channel,Socket}from'phoenix'import{make,pipe,toObservable}from'wonka'import{getWsEndpoint}from'~/env'constwsEndpoint=getWsEndpoint()constsocket=newSocket(`${wsEndpoint}/socket`,{})socket.connect()constabsintheChannel=socket.channel('__absinthe__:control')absintheChannel.join()exportconstabsintheExchange=subscriptionExchange({forwardSubscription({query,variables}){letsubscriptionChannel:Channelconstsource=make((observer)=>{const{next}=observerabsintheChannel.push('doc',{query,variables}).receive('ok',(v)=>{constsubscriptionId=v.subscriptionIdif(subscriptionId){subscriptionChannel=socket.channel(subscriptionId)subscriptionChannel.on('subscription:data',(value)=>{next(value.result)})}})return()=>{subscriptionChannel?.leave()}})returnpipe(source,toObservable)},})
Then
constendpoint=getEndpoint()exportconstclient=createClient({url:`${endpoint}/graphql`,exchanges:[dedupExchange,fetchExchange,absintheExchange,],})
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse