Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 9.2.0-SNAPSHOT
version = 9.2.1.001-SNAPSHOT
group = com.graphql-java-kickstart

PROJECT_NAME = graphql-java-servlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void sendDataMessage(String id, Object payload) {
}

@Override
public void sendErrorMessage(String id) {

public void sendErrorMessage(String id, Object payload) {
send(mapper.serialize(payload));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package graphql.kickstart.execution.subscriptions;

import graphql.ExecutionResult;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import graphql.GraphQLError;
import graphql.kickstart.execution.error.GenericGraphQLError;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Subscriber;
Expand All @@ -29,15 +34,20 @@ public void onSubscribe(Subscription subscription) {
public void onNext(ExecutionResult executionResult) {
Map<String, Object> result = new HashMap<>();
result.put("data", executionResult.getData());

session.sendDataMessage(id, result);
subscriptionReference.get().request(1);
}

@Override
public void onError(Throwable throwable) {
log.error("Subscription error", throwable);

Map<String, Object> payload = new HashMap<>();
payload.put("errors", Collections.singletonList(new GenericGraphQLError(throwable.getMessage())));

session.unsubscribe(id);
session.sendErrorMessage(id);
session.sendErrorMessage(id, payload);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface SubscriptionSession {

void sendDataMessage(String id, Object payload);

void sendErrorMessage(String id);
void sendErrorMessage(String id, Object payload);

void sendCompleteMessage(String id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void accept(String request) {
SubscriptionCommand command = commandProvider.getByType(message.getType());
command.apply(session, message);
} catch (JsonProcessingException e) {
log.error("Cannot read subscription command '{}'", request, e);
log.error("Cannot read subscription command '{}': {}", request, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add the : {} part here? Since the way it was worked just fine letting it print the stack trace.

session.sendMessage(new OperationMessage(Type.GQL_CONNECTION_ERROR, null, e.getMessage()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public void sendDataMessage(String id, Object payload) {
}

@Override
public void sendErrorMessage(String id) {
sendMessage(new OperationMessage(Type.GQL_ERROR, id, null));
public void sendErrorMessage(String id, Object payload) {
sendMessage(new OperationMessage(Type.GQL_ERROR, id, payload));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void apply(SubscriptionSession session, OperationMessage message) {
connectionListeners.forEach(it -> it.onConnect(session, message));
session.sendMessage(new OperationMessage(Type.GQL_CONNECTION_ACK, message.getId(), null));
} catch (Throwable t) {
log.error("Cannot initialize subscription command '{}': {}", message, t);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add the : {} part here? Since the way it was worked just fine letting it print the stack trace.

session.sendMessage(new OperationMessage(Type.GQL_CONNECTION_ERROR, message.getId(), t.getMessage()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onNext(String message) {

@Override
public void onError(Throwable t) {

log.error("WebSocket error", t);
}

@Override
Expand Down