Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77aa6a9

Browse files
IvanGoncharovmjmahone
authored andcommitted
Inline intermediate 'visitUsingRules' function (graphql#1430)
1 parent 183c532 commit 77aa6a9

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

src/validation/validate.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import invariant from '../jsutils/invariant';
1111
import type { GraphQLError } from '../error';
1212
import { visit, visitInParallel, visitWithTypeInfo } from '../language/visitor';
1313
import type { DocumentNode } from '../language/ast';
14-
import type { ASTVisitor } from '../language/visitor';
1514
import type { GraphQLSchema } from '../type/schema';
1615
import { assertValidSchema } from '../type/validate';
1716
import { TypeInfo } from '../utilities/TypeInfo';
@@ -36,36 +35,19 @@ import ValidationContext from './ValidationContext';
3635
*/
3736
export function validate(
3837
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),
4241
): $ReadOnlyArray<GraphQLError> {
43-
invariant(ast, 'Must provide document');
42+
invariant(documentAST, 'Must provide document');
4443
// If the schema used for validation is invalid, throw an error.
4544
assertValidSchema(schema);
46-
return visitUsingRules(
47-
schema,
48-
typeInfo || new TypeInfo(schema),
49-
ast,
50-
rules || specifiedRules,
51-
);
52-
}
5345

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> {
6646
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)));
6850
// Visit the whole document with each instance of all provided rules.
69-
visit(documentAST, visitWithTypeInfo(typeInfo, visitInParallel(visitors)));
51+
visit(documentAST, visitWithTypeInfo(typeInfo, visitor));
7052
return context.getErrors();
7153
}

0 commit comments

Comments
 (0)