You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is an Angular implementation with SSR for anyone that finds this. It is actually pretty simple...
urql.module.ts
import{NgModule}from'@angular/core';import{CommonModule}from'@angular/common';import{cacheExchange,Client,createClient,dedupExchange,fetchExchange,gql,ssrExchange,subscriptionExchange,}from'@urql/core';import{SubscriptionClient}from"subscriptions-transport-ws";import'isomorphic-unfetch';import*aswsfrom'ws';consturi="YOUR ENDPOINT";
@NgModule({declarations: [],imports: [CommonModule]})exportclassUrqlModule{client!: Client;// you could list your queries here...QUERY1=gql`some query here`;constructor(){// obviously all this changes depending on your implementation and exchanges...// you could also use isPlatformBrowser hereconstisServerSide=typeofwindow==='undefined';constssr=ssrExchange({isClient: !isServerSide,initialState: !isServerSide ? (windowasany).__URQL_DATA__ : undefined,});constsubscriptionClient=newSubscriptionClient(`wss://${uri}`,{reconnect: true,lazy: true,},ws);this.client=createClient({url: `https://${uri}`,exchanges: [dedupExchange,cacheExchange,ssr,fetchExchange,subscriptionExchange({forwardSubscription(operation){returnsubscriptionClient.request(operation);},}),]});}}
If you don't use angular universal, you won't need all the ssr stuff.
Simply import the module as usual to your app module and the components that use it. Call the client property form this module in your component depending on your usage, and voila!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Here is an Angular implementation with SSR for anyone that finds this. It is actually pretty simple...
urql.module.ts
If you don't use angular universal, you won't need all the ssr stuff.
Simply import the module as usual to your app module and the components that use it. Call the client property form this module in your component depending on your usage, and voila!
Beta Was this translation helpful? Give feedback.
All reactions