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

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

There is a newer version: 16.0.0
Show newest version
package graphql.kickstart.execution.subscriptions.apollo;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OperationMessage {

  private Type type;
  private String id;
  private Object payload;

  public static OperationMessage newKeepAliveMessage() {
    return new OperationMessage(Type.GQL_CONNECTION_KEEP_ALIVE, null, null);
  }

  public Type getType() {
    return type;
  }

  public String getId() {
    return id;
  }

  public Object getPayload() {
    return payload;
  }

  public enum Type {

    // Server Messages
    GQL_CONNECTION_ACK("connection_ack"),
    GQL_CONNECTION_ERROR("connection_error"),
    GQL_CONNECTION_KEEP_ALIVE("ka"),
    GQL_DATA("data"),
    GQL_ERROR("error"),
    GQL_COMPLETE("complete"),

    // Client Messages
    GQL_CONNECTION_INIT("connection_init"),
    GQL_CONNECTION_TERMINATE("connection_terminate"),
    GQL_START("start"),
    GQL_STOP("stop");

    private static final Map reverseLookup = new HashMap<>();

    static {
      for (Type type : Type.values()) {
        reverseLookup.put(type.getType(), type);
      }
    }

    private final String type;

    Type(String type) {
      this.type = type;
    }

    @JsonCreator
    public static Type findType(String type) {
      return reverseLookup.get(type);
    }

    @JsonValue
    public String getType() {
      return type;
    }

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy