
graphql.validation.util.Util Maven / Gradle / Ivy
package graphql.validation.util;
import graphql.Assert;
import graphql.GraphQLError;
import graphql.Internal;
import graphql.execution.DataFetcherResult;
import graphql.execution.ResultPath;
import graphql.schema.GraphQLInputType;
import graphql.schema.GraphQLType;
import graphql.schema.GraphQLTypeUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
@Internal
public class Util {
/**
* This will unwrap one level of List ness and ALL levels of NonNull ness.
*
* @param inputType the type to unwrap
*
* @return an input type
*/
public static GraphQLInputType unwrapOneAndAllNonNull(GraphQLInputType inputType) {
GraphQLType type = GraphQLTypeUtil.unwrapNonNull(inputType);
type = GraphQLTypeUtil.unwrapOne(type); // one level
type = GraphQLTypeUtil.unwrapNonNull(type);
if (type instanceof GraphQLInputType) {
return (GraphQLInputType) type;
} else {
String argType = GraphQLTypeUtil.simplePrint(inputType);
return Assert.assertShouldNeverHappen("You have a wrapped type that is in fact not a input type : %s", argType);
}
}
public static GraphQLInputType unwrapNonNull(GraphQLInputType inputType) {
GraphQLType type = GraphQLTypeUtil.unwrapNonNull(inputType);
if (type instanceof GraphQLInputType) {
return (GraphQLInputType) type;
} else {
String argType = GraphQLTypeUtil.simplePrint(inputType);
return Assert.assertShouldNeverHappen("You have a wrapped type that is in fact not a input type : %s", argType);
}
}
public static Object mkDFRFromFetchedResult(List errors, Object value) {
if (value instanceof CompletionStage) {
return ((CompletionStage>) value).thenApply(v -> mkDFRFromFetchedResult(errors, v));
} else if (value instanceof DataFetcherResult) {
DataFetcherResult df = (DataFetcherResult) value;
return mkDFR(df.getData(), concat(errors, df.getErrors()), df.getLocalContext());
} else {
return mkDFR(value, errors, null);
}
}
public static DataFetcherResult
© 2015 - 2025 Weber Informatics LLC | Privacy Policy