Skip to content

Commit

Permalink
Merge pull request #35 from compolabs/feat/support-node
Browse files Browse the repository at this point in the history
[1442] Checking node support
  • Loading branch information
EchoDex authored Aug 22, 2024
2 parents e5a2adb + 974e772 commit b5273c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
40 changes: 23 additions & 17 deletions src/utils/GraphClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
}
Expand Down

0 comments on commit b5273c6

Please sign in to comment.