![JAR search and dependency download from the Maven repository](/logo.png)
graphql.schema.validation.Validator Maven / Gradle / Ivy
The newest version!
package graphql.schema.validation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLFieldsContainer;
import graphql.schema.GraphQLOutputType;
import graphql.schema.GraphQLSchema;
public class Validator {
private final Set processed = new HashSet<>();
public Set validateSchema(GraphQLSchema schema) {
ValidationErrorCollector validationErrorCollector = new ValidationErrorCollector();
List rules = new ArrayList<>();
rules.add(new NoUnbrokenInputCycles());
traverse(schema.getQueryType(), rules, validationErrorCollector);
if (schema.isSupportingMutations()) {
traverse(schema.getMutationType(), rules, validationErrorCollector);
}
return validationErrorCollector.getErrors();
}
private void traverse(GraphQLOutputType root, List rules, ValidationErrorCollector validationErrorCollector) {
if (processed.contains(root)) {
return;
}
processed.add(root);
if (root instanceof GraphQLFieldsContainer) {
for (GraphQLFieldDefinition fieldDefinition : ((GraphQLFieldsContainer) root).getFieldDefinitions()) {
for (ValidationRule rule : rules) {
rule.check(fieldDefinition, validationErrorCollector);
}
traverse(fieldDefinition.getType(), rules, validationErrorCollector);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy