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

graphql.incremental.StreamPayload Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.incremental;

import graphql.ExperimentalApi;
import graphql.GraphQLError;
import org.jetbrains.annotations.Nullable;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Represents a stream payload
 */
@ExperimentalApi
public class StreamPayload extends IncrementalPayload {
    private final List items;

    private StreamPayload(List items, List path, String label, List errors, Map extensions) {
        super(path, label, errors, extensions);
        this.items = items;
    }

    /**
     * @param  the type to cast the result to
     * @return the resolved list of items
     */
    @Nullable
    public  List getItems() {
        // noinspection unchecked
        return (List) this.items;
    }

    /**
     * @return a map of this payload that strictly follows the spec
     */
    @Override
    public Map toSpecification() {
        Map map = new LinkedHashMap<>(super.toSpecification());
        map.put("items", items);
        return map;
    }

    /**
     * @return a {@link Builder} that can be used to create an instance of {@link StreamPayload}
     */
    public static StreamPayload.Builder newStreamedItem() {
        return new StreamPayload.Builder();
    }

    public static class Builder extends IncrementalPayload.Builder {
        private List items = null;

        public Builder items(List items) {
            this.items = items;
            return this;
        }

        public Builder from(StreamPayload streamedItem) {
            super.from(streamedItem);
            this.items = streamedItem.items;
            return this;
        }

        public StreamPayload build() {
            return new StreamPayload(items, this.path, this.label, this.errors, this.extensions);
        }
    }
}