graphql.schema.validation.SchemaValidator Maven / Gradle / Ivy
package graphql.schema.validation;
import graphql.Internal;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLTypeVisitor;
import graphql.schema.SchemaTraverser;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Internal
public class SchemaValidator {
private final List rules = new ArrayList<>();
public SchemaValidator() {
rules.add(new NoUnbrokenInputCycles());
rules.add(new TypesImplementInterfaces());
rules.add(new TypeAndFieldRule());
rules.add(new DefaultValuesAreValid());
rules.add(new AppliedDirectivesAreValid());
rules.add(new AppliedDirectiveArgumentsAreValid());
rules.add(new InputAndOutputTypesUsedAppropriately());
rules.add(new OneOfInputObjectRules());
rules.add(new DeprecatedInputObjectAndArgumentsAreValid());
}
public List getRules() {
return rules;
}
public Set validateSchema(GraphQLSchema schema) {
SchemaValidationErrorCollector validationErrorCollector = new SchemaValidationErrorCollector();
Map, Object> rootVars = new LinkedHashMap<>();
rootVars.put(GraphQLSchema.class, schema);
rootVars.put(SchemaValidationErrorCollector.class, validationErrorCollector);
new SchemaTraverser().depthFirstFullSchema(rules, schema, rootVars);
return validationErrorCollector.getErrors();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy