graphql.normalized.ValueToVariableValueCompiler Maven / Gradle / Ivy
package graphql.normalized;
import graphql.AssertException;
import graphql.Internal;
import graphql.language.ArrayValue;
import graphql.language.BooleanValue;
import graphql.language.EnumValue;
import graphql.language.FloatValue;
import graphql.language.IntValue;
import graphql.language.NullValue;
import graphql.language.ObjectField;
import graphql.language.ObjectValue;
import graphql.language.StringValue;
import graphql.language.Value;
import graphql.language.VariableDefinition;
import graphql.language.VariableReference;
import graphql.parser.Parser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.toList;
@Internal
public class ValueToVariableValueCompiler {
static VariableValueWithDefinition normalizedInputValueToVariable(NormalizedInputValue normalizedInputValue, int queryVariableCount) {
Object variableValue = normalisedValueToVariableValue(normalizedInputValue);
String varName = getVarName(queryVariableCount);
return new VariableValueWithDefinition(
variableValue,
VariableDefinition.newVariableDefinition()
.name(varName)
.type(Parser.parseType(normalizedInputValue.getTypeName()))
.build(),
VariableReference.newVariableReference().name(varName).build());
}
@SuppressWarnings("unchecked")
@Nullable
static Object normalisedValueToVariableValue(Object maybeValue) {
Object variableValue;
if (maybeValue instanceof NormalizedInputValue) {
NormalizedInputValue normalizedInputValue = (NormalizedInputValue) maybeValue;
Object inputValue = normalizedInputValue.getValue();
if (inputValue instanceof Value) {
variableValue = toVariableValue((Value>) inputValue);
} else if (inputValue instanceof List) {
variableValue = normalisedValueToVariableValues((List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy