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

graphql.normalized.ExecutableNormalizedOperation Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableListMultimap;
import graphql.Assert;
import graphql.Internal;
import graphql.execution.MergedField;
import graphql.execution.ResultPath;
import graphql.language.Field;
import graphql.language.OperationDefinition;
import graphql.schema.FieldCoordinates;
import graphql.schema.GraphQLFieldsContainer;

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

@Internal
public class ExecutableNormalizedOperation {
    private final OperationDefinition.Operation operation;
    private final String operationName;
    private final List topLevelFields;
    private final ImmutableListMultimap fieldToNormalizedField;
    private final Map normalizedFieldToMergedField;
    private final ImmutableListMultimap coordinatesToNormalizedFields;

    public ExecutableNormalizedOperation(
            OperationDefinition.Operation operation,
            String operationName,
            List topLevelFields,
            ImmutableListMultimap fieldToNormalizedField,
            Map normalizedFieldToMergedField,
            ImmutableListMultimap coordinatesToNormalizedFields
    ) {
        this.operation = operation;
        this.operationName = operationName;
        this.topLevelFields = topLevelFields;
        this.fieldToNormalizedField = fieldToNormalizedField;
        this.normalizedFieldToMergedField = normalizedFieldToMergedField;
        this.coordinatesToNormalizedFields = coordinatesToNormalizedFields;
    }

    public OperationDefinition.Operation getOperation() {
        return operation;
    }

    public String getOperationName() {
        return operationName;
    }

    public ImmutableListMultimap getCoordinatesToNormalizedFields() {
        return coordinatesToNormalizedFields;
    }

    public List getTopLevelFields() {
        return topLevelFields;
    }

    /**
     * This is a multimap: the size of it reflects the all the normalized fields
     *
     * @return an immutable list multi map of field to normalised field
     */
    public ImmutableListMultimap getFieldToNormalizedField() {
        return fieldToNormalizedField;
    }

    public List getNormalizedFields(Field field) {
        return fieldToNormalizedField.get(field);
    }

    public Map getNormalizedFieldToMergedField() {
        return normalizedFieldToMergedField;
    }

    public MergedField getMergedField(ExecutableNormalizedField executableNormalizedField) {
        return normalizedFieldToMergedField.get(executableNormalizedField);
    }

    public ExecutableNormalizedField getNormalizedField(MergedField mergedField, GraphQLFieldsContainer fieldsContainer, ResultPath resultPath) {
        List executableNormalizedFields = fieldToNormalizedField.get(mergedField.getSingleField());
        List keysOnlyPath = resultPath.getKeysOnly();
        for (ExecutableNormalizedField executableNormalizedField : executableNormalizedFields) {
            if (executableNormalizedField.getListOfResultKeys().equals(keysOnlyPath)) {
                if (executableNormalizedField.getObjectTypeNames().contains(fieldsContainer.getName())) {
                    return executableNormalizedField;
                }
            }
        }
        return Assert.assertShouldNeverHappen("normalized field not found");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy