All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.kickstart.execution.subscriptions.apollo.SubscriptionConnectionInitCommand Maven / Gradle / Ivy

package graphql.kickstart.execution.subscriptions.apollo;

import graphql.kickstart.execution.subscriptions.SubscriptionSession;
import graphql.kickstart.execution.subscriptions.apollo.OperationMessage.Type;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
class SubscriptionConnectionInitCommand implements SubscriptionCommand {

  private final Collection connectionListeners;

  @Override
  public void apply(SubscriptionSession session, OperationMessage message) {
    log.debug("Apollo subscription connection init: {}", session);
    try {
      connectionListeners.forEach(it -> it.onConnect(session, message));
      session.sendMessage(new OperationMessage(Type.GQL_CONNECTION_ACK, message.getId(), null));
    } catch (Exception t) {
      log.error("Cannot initialize subscription command '{}'", message, t);
      session.sendMessage(
          new OperationMessage(Type.GQL_CONNECTION_ERROR, message.getId(), t.getMessage()));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy