From 974e7728f7a437cde05be47ce0190bdbf4d124d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B8b=C4=97rt=C3=B8?= <106074508+EchoDex@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:09:07 +0400 Subject: [PATCH] feat: checking node support --- package.json | 2 +- src/utils/GraphClient.ts | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 73df4ac..02a902d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@compolabs/spark-orderbook-ts-sdk", - "version": "1.5.3", + "version": "1.5.4", "type": "module", "main": "./dist/index.сjs", "module": "./dist/index.js", diff --git a/src/utils/GraphClient.ts b/src/utils/GraphClient.ts index 7372218..45eb9e5 100644 --- a/src/utils/GraphClient.ts +++ b/src/utils/GraphClient.ts @@ -18,26 +18,32 @@ export class GraphClient { uri: httpUrl, }); - const wsLink = new GraphQLWsLink( - createClient({ - url: wsUrl, - }), - ); + const wsLink = + typeof window !== "undefined" + ? new GraphQLWsLink( + createClient({ + url: wsUrl, + }), + ) + : null; - const splitLink = split( - ({ query }) => { - const definition = getMainDefinition(query); - return ( - definition.kind === "OperationDefinition" && - definition.operation === "subscription" - ); - }, - wsLink, - httpLink, - ); + const splitLink = + typeof window !== "undefined" && wsLink !== null + ? split( + ({ query }) => { + const def = getMainDefinition(query); + return ( + def.kind === "OperationDefinition" && + def.operation === "subscription" + ); + }, + wsLink, + httpLink, + ) + : httpLink; this.client = new ApolloClient({ - link: wsLink, + link: splitLink, cache: new InMemoryCache(), }); }