diff --git a/package.json b/package.json index 68f0225..193750a 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "react-relay": "^1.4.1", "react-router-dom": "^4.2.2", "style-loader": "0.19.0", - "subscriptions-transport-ws": "0.8.3", + "subscriptions-transport-ws": "^0.9.7", "sw-precache-webpack-plugin": "0.11.4", "url-loader": "0.6.2", "webpack": "3.8.1", diff --git a/src/Environment.js b/src/Environment.js index 4a18246..af5f402 100644 --- a/src/Environment.js +++ b/src/Environment.js @@ -30,10 +30,28 @@ export const fetchQuery = (operation, variables) => { const setupSubscription = (config, variables, cacheConfig, observer) => { const query = config.text - const subscriptionClient = new SubscriptionClient('wss://subscriptions.graph.cool/v1/__SERVICE_ID__', {reconnect: true}) - subscriptionClient.subscribe({query, variables}, (error, result) => { - observer.onNext({data: result}) - }) + const subscriptionClient = new SubscriptionClient( + 'wss://subscriptions.__REGION__.graph.cool/v1/__PROJECT_ID__', + {reconnect: true} + ) + + const client = subscriptionClient + .request({query, variables}) + .subscribe({ + next: (result) => { + observer.onNext({data: result.data}) + }, + complete: () => { + observer.onCompleted() + }, + error: (error) => { + observer.onError(error) + } + }) + + return { + dispose: client.unsubscribe + } } const network = Network.create(fetchQuery, setupSubscription) @@ -43,4 +61,5 @@ const environment = new Environment({ store, }) -export default environment \ No newline at end of file +export default environment +