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

graphql.normalized.FieldCollectorNormalizedQueryParams Maven / Gradle / Ivy

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

import graphql.Assert;
import graphql.Internal;
import graphql.language.FragmentDefinition;
import graphql.schema.GraphQLSchema;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

@Internal
public class FieldCollectorNormalizedQueryParams {
    private final GraphQLSchema graphQLSchema;
    private final Map fragmentsByName;
    private final Map coercedVariableValues;
    private final Map normalizedVariableValues;

    public List possibleMergerList = new ArrayList<>();

    public static class PossibleMerger {
        ExecutableNormalizedField parent;
        String resultKey;

        public PossibleMerger(ExecutableNormalizedField parent, String resultKey) {
            this.parent = parent;
            this.resultKey = resultKey;
        }
    }

    public void addPossibleMergers(ExecutableNormalizedField parent, String resultKey) {
        possibleMergerList.add(new PossibleMerger(parent, resultKey));
    }

    public GraphQLSchema getGraphQLSchema() {
        return graphQLSchema;
    }

    public Map getFragmentsByName() {
        return fragmentsByName;
    }

    @NotNull
    public Map getCoercedVariableValues() {
        return coercedVariableValues;
    }

    @Nullable
    public Map getNormalizedVariableValues() {
        return normalizedVariableValues;
    }

    private FieldCollectorNormalizedQueryParams(GraphQLSchema graphQLSchema,
                                                Map coercedVariableValues,
                                                Map normalizedVariableValues,
                                                Map fragmentsByName) {
        this.fragmentsByName = fragmentsByName;
        this.graphQLSchema = graphQLSchema;
        this.coercedVariableValues = coercedVariableValues;
        this.normalizedVariableValues = normalizedVariableValues;
    }

    public static Builder newParameters() {
        return new Builder();
    }

    public static class Builder {
        private GraphQLSchema graphQLSchema;
        private final Map fragmentsByName = new LinkedHashMap<>();
        private final Map coercedVariableValues = new LinkedHashMap<>();
        private Map normalizedVariableValues;

        /**
         * @see FieldCollectorNormalizedQueryParams#newParameters()
         */
        private Builder() {

        }

        public Builder schema(GraphQLSchema graphQLSchema) {
            this.graphQLSchema = graphQLSchema;
            return this;
        }

        public Builder fragments(Map fragmentsByName) {
            this.fragmentsByName.putAll(fragmentsByName);
            return this;
        }

        public Builder coercedVariables(Map coercedVariableValues) {
            this.coercedVariableValues.putAll(coercedVariableValues);
            return this;
        }

        public Builder normalizedVariables(Map normalizedVariableValues) {
            this.normalizedVariableValues = normalizedVariableValues;
            return this;
        }

        public FieldCollectorNormalizedQueryParams build() {
            Assert.assertNotNull(graphQLSchema, () -> "You must provide a schema");
            return new FieldCollectorNormalizedQueryParams(graphQLSchema, coercedVariableValues, normalizedVariableValues, fragmentsByName);
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy