Skip to content

Commit

Permalink
fix(api) Fix tests broken by PR #599 (#647)
Browse files Browse the repository at this point in the history
* fix(api) Fix tests broken by PR #599

* Move buildSubscriptionUrl to its original place
  • Loading branch information
rjuliano authored Jul 16, 2020
1 parent 3fde34c commit 71aa76d
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ final class SubscriptionEndpoint {
private final GraphQLResponse.Factory responseFactory;
private final TimeoutWatchdog timeoutWatchdog;
private final Set<String> pendingSubscriptionIds;
private final String subscriptionUrl;
private final OkHttpClient okHttpClient;
private WebSocket webSocket;
private AmplifyWebSocketListener webSocketListener;
Expand All @@ -84,7 +83,6 @@ final class SubscriptionEndpoint {
this.authorizer = Objects.requireNonNull(authorizer);
this.timeoutWatchdog = new TimeoutWatchdog();
this.pendingSubscriptionIds = Collections.synchronizedSet(new HashSet<>());
this.subscriptionUrl = buildConnectionRequestUrl();
this.okHttpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(UserAgentInterceptor.using(UserAgent::string))
.retryOnConnectionFailure(true)
Expand All @@ -107,10 +105,16 @@ synchronized <T> void requestSubscription(
// force a new connection to be created.
if (webSocketListener == null || webSocketListener.isDisconnectedState()) {
webSocketListener = new AmplifyWebSocketListener();
webSocket = okHttpClient.newWebSocket(new Request.Builder()
.url(subscriptionUrl)
.addHeader("Sec-WebSocket-Protocol", "graphql-ws")
.build(), webSocketListener);
try {
webSocket = okHttpClient.newWebSocket(new Request.Builder()
.url(buildConnectionRequestUrl())
.addHeader("Sec-WebSocket-Protocol", "graphql-ws")
.build(), webSocketListener);
} catch (ApiException apiException) {
onSubscriptionError.accept(apiException);
return;
}

}
final String subscriptionId = UUID.randomUUID().toString();
pendingSubscriptionIds.add(subscriptionId);
Expand Down

0 comments on commit 71aa76d

Please sign in to comment.