Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.configuration.graphql.ws;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import graphql.ExecutionResult;
import graphql.GraphQLError;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* A class for mapping graphql-ws messages.
*
* @author Jeremy Grelle
* @since 4.0
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@Type(value = ConnectionInitMessage.class, name = Message.Types.CONNECTION_INIT),
@Type(value = ConnectionAckMessage.class, name = Message.Types.CONNECTION_ACK),
@Type(value = PingMessage.class, name = Message.Types.PING),
@Type(value = PongMessage.class, name = Message.Types.PONG),
@Type(value = SubscribeMessage.class, name = Message.Types.SUBSCRIBE),
@Type(value = NextMessage.class, name = Message.Types.NEXT),
@Type(value = ErrorMessage.class, name = Message.Types.ERROR),
@Type(value = CompleteMessage.class, name = Message.Types.COMPLETE)
})
public abstract sealed class Message {
/**
* Get the required value of the message's type field.
*
* @return The message's type
*/
@JsonIgnore
@NonNull
abstract String getMessageType();
/**
* Validate a required message id.
*
* @param id The required message id
*/
protected void checkRequiredId(String id) {
if (StringUtils.isEmpty(id)) {
throw new IllegalArgumentException("'id' is required for messages with type '" + getMessageType() + "'.");
}
}
/**
* The allowable graphql-ws message types.
*/
static final class Types {
static final String CONNECTION_INIT = "connection_init";
static final String CONNECTION_ACK = "connection_ack";
static final String PING = "ping";
static final String PONG = "pong";
static final String SUBSCRIBE = "subscribe";
static final String NEXT = "next";
static final String ERROR = "error";
static final String COMPLETE = "complete";
private Types() { }
}
}
/**
* A graphql-ws message that contains an optional payload.
*
* @param The payload type
*/
abstract sealed class PayloadMessage extends Message {
@Nullable
private final T payload;
/**
* Default constructor for a graphql-ws message with an optional payload.
*/
protected PayloadMessage() {
this(null);
}
/**
* Constructor for a graphql-ws message with a payload.
*
* @param payload The message payload.
*/
protected PayloadMessage(@Nullable T payload) {
this.payload = payload;
}
/**
* Get the message payload.
*
* @return The message payload.
*/
@Nullable
public T getPayload() {
return payload;
}
}
/**
* A graphql-ws message that has a required non-null payload.
*
* @param The payload type.
*/
abstract sealed class RequiredPayloadMessage extends Message {
@NonNull
private final T payload;
/**
* Constructor for a graphql-ws message with a required payload.
*
* @param payload The message payload.
*/
protected RequiredPayloadMessage(@NonNull T payload) {
Objects.requireNonNull(payload, "A payload is required for message type '" + getMessageType() + ".");
this.payload = payload;
}
/**
* Get the message payload - will never be null.
*
* @return The message payload.
*/
@NonNull
public T getPayload() {
return payload;
}
}
/**
* A graphql-ws message for connection initialisation.
*/
final class ConnectionInitMessage extends PayloadMessage