From 10dafaf9e20ef5ea7de7afcb4290d652fb4b6afb Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 20 Apr 2017 23:50:35 +0100 Subject: [PATCH] feat(NA): enclose wsclient creation inside addGraphQLWS function. --- src/helpers.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 2a85941eb..e7d82d4e9 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,4 +1,4 @@ -import { SubscriptionClient } from './client'; +import { SubscriptionClient, ClientOptions } from './client'; import { ExecutionResult } from 'graphql'; /** @@ -22,7 +22,12 @@ export function addGraphQLSubscriptions(networkInterface: any, wsClient: Subscri }); } -export function addGraphQLWS(networkInterface: any, wsClient: SubscriptionClient): any { +export function addGraphQLWS(networkInterface: any, wsClientOptions: ClientOptions): any { + if (typeof networkInterface._uri !== 'string') { + throw new Error('Given networkInterface should have an uri defined to config the websocket.'); + } + + const wsClient = new SubscriptionClient(networkInterface._uri, wsClientOptions); return Object.assign(addGraphQLSubscriptions(networkInterface, wsClient), { query(request: any): Promise { return wsClient.query(request);