@@ -11,7 +11,6 @@ import invariant from '../jsutils/invariant';
11
11
import type { GraphQLError } from '../error' ;
12
12
import { visit , visitInParallel , visitWithTypeInfo } from '../language/visitor' ;
13
13
import type { DocumentNode } from '../language/ast' ;
14
- import type { ASTVisitor } from '../language/visitor' ;
15
14
import type { GraphQLSchema } from '../type/schema' ;
16
15
import { assertValidSchema } from '../type/validate' ;
17
16
import { TypeInfo } from '../utilities/TypeInfo' ;
@@ -36,36 +35,19 @@ import ValidationContext from './ValidationContext';
36
35
*/
37
36
export function validate (
38
37
schema : GraphQLSchema ,
39
- ast : DocumentNode ,
40
- rules ?: $ReadOnlyArray < any > ,
41
- typeInfo ?: TypeInfo ,
38
+ documentAST : DocumentNode ,
39
+ rules ?: $ReadOnlyArray < any > = specifiedRules ,
40
+ typeInfo ?: TypeInfo = new TypeInfo ( schema ) ,
42
41
) : $ReadOnlyArray < GraphQLError > {
43
- invariant ( ast , 'Must provide document' ) ;
42
+ invariant ( documentAST , 'Must provide document' ) ;
44
43
// If the schema used for validation is invalid, throw an error.
45
44
assertValidSchema ( schema ) ;
46
- return visitUsingRules (
47
- schema ,
48
- typeInfo || new TypeInfo ( schema ) ,
49
- ast ,
50
- rules || specifiedRules ,
51
- ) ;
52
- }
53
45
54
- /**
55
- * This uses a specialized visitor which runs multiple visitors in parallel,
56
- * while maintaining the visitor skip and break API.
57
- *
58
- * @internal
59
- */
60
- function visitUsingRules (
61
- schema : GraphQLSchema ,
62
- typeInfo : TypeInfo ,
63
- documentAST : DocumentNode ,
64
- rules : $ReadOnlyArray < ( ValidationContext ) => ASTVisitor > ,
65
- ) : $ReadOnlyArray < GraphQLError > {
66
46
const context = new ValidationContext ( schema , documentAST , typeInfo ) ;
67
- const visitors = rules . map ( rule => rule ( context ) ) ;
47
+ // This uses a specialized visitor which runs multiple visitors in parallel,
48
+ // while maintaining the visitor skip and break API.
49
+ const visitor = visitInParallel ( rules . map ( rule => rule ( context ) ) ) ;
68
50
// Visit the whole document with each instance of all provided rules.
69
- visit ( documentAST , visitWithTypeInfo ( typeInfo , visitInParallel ( visitors ) ) ) ;
51
+ visit ( documentAST , visitWithTypeInfo ( typeInfo , visitor ) ) ;
70
52
return context . getErrors ( ) ;
71
53
}
0 commit comments