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

graphql.execution.batched.GraphQLExecutionResultContainer Maven / Gradle / Ivy

package graphql.execution.batched;

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

public abstract class GraphQLExecutionResultContainer {

    /**
     * Creates a child datum which is linked through the results container to this parent.
     * @param fieldName fieldName
     * @param value value
     * @return datum
     */
    public GraphQLExecutionNodeDatum createAndPutChildDatum(String fieldName, Object value) {
        Map map = new LinkedHashMap<>();
        putResult(fieldName, map);
        return new GraphQLExecutionNodeDatum(map, value);
    }

    public GraphQLExecutionResultList createAndPutEmptyChildList(String fieldName) {
        List resultList = new ArrayList<>();
        putResult(fieldName, resultList);
        return new GraphQLExecutionResultList(resultList);
    }

    /**
     * Inserts this result into the parent for the specified field.
     * @param fieldName fieldName
     * @param value value
     */
    abstract void putResult(String fieldName, Object value);

}