forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidator.java
More file actions
74 lines (56 loc) · 3.99 KB
/
Validator.java
File metadata and controls
74 lines (56 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package graphql.validation;
import graphql.language.Document;
import graphql.schema.GraphQLSchema;
import graphql.validation.rules.*;
import java.util.ArrayList;
import java.util.List;
public class Validator {
public List<ValidationError> validateDocument(GraphQLSchema schema, Document document) {
ValidationContext validationContext = new ValidationContext(schema, document);
ValidationErrorCollector validationErrorCollector = new ValidationErrorCollector();
List<AbstractRule> rules = createRules(validationContext, validationErrorCollector);
LanguageTraversal languageTraversal = new LanguageTraversal();
languageTraversal.traverse(document, new RulesVisitor(validationContext, rules));
return validationErrorCollector.getErrors();
}
private List<AbstractRule> createRules(ValidationContext validationContext, ValidationErrorCollector validationErrorCollector) {
List<AbstractRule> rules = new ArrayList<AbstractRule>();
ArgumentsOfCorrectType argumentsOfCorrectType = new ArgumentsOfCorrectType(validationContext, validationErrorCollector);
rules.add(argumentsOfCorrectType);
FieldsOnCorrectType fieldsOnCorrectType = new FieldsOnCorrectType(validationContext, validationErrorCollector);
rules.add(fieldsOnCorrectType);
FragmentsOnCompositeType fragmentsOnCompositeType = new FragmentsOnCompositeType(validationContext, validationErrorCollector);
rules.add(fragmentsOnCompositeType);
KnownArgumentNames knownArgumentNames = new KnownArgumentNames(validationContext, validationErrorCollector);
rules.add(knownArgumentNames);
KnownDirectives knownDirectives = new KnownDirectives(validationContext, validationErrorCollector);
rules.add(knownDirectives);
KnownFragmentNames knownFragmentNames = new KnownFragmentNames(validationContext, validationErrorCollector);
rules.add(knownFragmentNames);
KnownTypeNames knownTypeNames = new KnownTypeNames(validationContext, validationErrorCollector);
rules.add(knownTypeNames);
NoFragmentCycles noFragmentCycles = new NoFragmentCycles(validationContext, validationErrorCollector);
rules.add(noFragmentCycles);
NoUndefinedVariables noUndefinedVariables = new NoUndefinedVariables(validationContext, validationErrorCollector);
rules.add(noUndefinedVariables);
NoUnusedFragments noUnusedFragments = new NoUnusedFragments(validationContext, validationErrorCollector);
rules.add(noUnusedFragments);
NoUnusedVariables noUnusedVariables = new NoUnusedVariables(validationContext, validationErrorCollector);
rules.add(noUnusedVariables);
OverlappingFieldsCanBeMerged overlappingFieldsCanBeMerged = new OverlappingFieldsCanBeMerged(validationContext, validationErrorCollector);
rules.add(overlappingFieldsCanBeMerged);
PossibleFragmentSpreads possibleFragmentSpreads = new PossibleFragmentSpreads(validationContext, validationErrorCollector);
rules.add(possibleFragmentSpreads);
ProvidedNonNullArguments providedNonNullArguments = new ProvidedNonNullArguments(validationContext, validationErrorCollector);
rules.add(providedNonNullArguments);
ScalarLeafs scalarLeafs = new ScalarLeafs(validationContext, validationErrorCollector);
rules.add(scalarLeafs);
VariableDefaultValuesOfCorrectType variableDefaultValuesOfCorrectType = new VariableDefaultValuesOfCorrectType(validationContext, validationErrorCollector);
rules.add(variableDefaultValuesOfCorrectType);
VariablesAreInputTypes variablesAreInputTypes = new VariablesAreInputTypes(validationContext, validationErrorCollector);
rules.add(variablesAreInputTypes);
VariableTypesMatchRule variableTypesMatchRule = new VariableTypesMatchRule(validationContext, validationErrorCollector);
rules.add(variableTypesMatchRule);
return rules;
}
}