graphql.normalized.NormalizedQueryTree Maven / Gradle / Ivy
package graphql.normalized;
import graphql.Assert;
import graphql.Internal;
import graphql.execution.MergedField;
import graphql.execution.ResultPath;
import graphql.language.Field;
import graphql.schema.FieldCoordinates;
import graphql.schema.GraphQLFieldsContainer;
import java.util.List;
import java.util.Map;
@Internal
public class NormalizedQueryTree {
private final List topLevelFields;
private final Map> fieldToNormalizedField;
private final Map normalizedFieldToMergedField;
private final Map> coordinatesToNormalizedFields;
public NormalizedQueryTree(List topLevelFields,
Map> fieldToNormalizedField,
Map normalizedFieldToMergedField,
Map> coordinatesToNormalizedFields) {
this.topLevelFields = topLevelFields;
this.fieldToNormalizedField = fieldToNormalizedField;
this.normalizedFieldToMergedField = normalizedFieldToMergedField;
this.coordinatesToNormalizedFields = coordinatesToNormalizedFields;
}
public Map> getCoordinatesToNormalizedFields() {
return coordinatesToNormalizedFields;
}
public List getTopLevelFields() {
return topLevelFields;
}
public Map> getFieldToNormalizedField() {
return fieldToNormalizedField;
}
public List getNormalizedFields(Field field) {
return fieldToNormalizedField.get(field);
}
public Map getNormalizedFieldToMergedField() {
return normalizedFieldToMergedField;
}
public MergedField getMergedField(NormalizedField normalizedField) {
return normalizedFieldToMergedField.get(normalizedField);
}
public NormalizedField getNormalizedField(MergedField mergedField, GraphQLFieldsContainer fieldsContainer, ResultPath resultPath) {
List normalizedFields = fieldToNormalizedField.get(mergedField.getSingleField());
List keysOnlyPath = resultPath.getKeysOnly();
for (NormalizedField normalizedField : normalizedFields) {
if (normalizedField.getListOfResultKeys().equals(keysOnlyPath)) {
if (normalizedField.getObjectType() == fieldsContainer) {
return normalizedField;
}
}
}
return Assert.assertShouldNeverHappen("normalized field not found");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy